mirror of
https://github.com/opnsense/src.git
synced 2026-06-09 00:32:25 -04:00
Correct the r242545 sync with head@242525.
This commit is contained in:
commit
3cbf5f97aa
175 changed files with 4 additions and 82743 deletions
|
|
@ -1,716 +0,0 @@
|
|||
Notes on the Free Translation Project
|
||||
*************************************
|
||||
|
||||
Free software is going international! The Free Translation Project is
|
||||
a way to get maintainers of free software, translators, and users all
|
||||
together, so that will gradually become able to speak many languages.
|
||||
A few packages already provide translations for their messages.
|
||||
|
||||
If you found this `ABOUT-NLS' file inside a distribution, you may
|
||||
assume that the distributed package does use GNU `gettext' internally,
|
||||
itself available at your nearest GNU archive site. But you do _not_
|
||||
need to install GNU `gettext' prior to configuring, installing or using
|
||||
this package with messages translated.
|
||||
|
||||
Installers will find here some useful hints. These notes also
|
||||
explain how users should proceed for getting the programs to use the
|
||||
available translations. They tell how people wanting to contribute and
|
||||
work at translations should contact the appropriate team.
|
||||
|
||||
When reporting bugs in the `intl/' directory or bugs which may be
|
||||
related to internationalization, you should tell about the version of
|
||||
`gettext' which is used. The information can be found in the
|
||||
`intl/VERSION' file, in internationalized packages.
|
||||
|
||||
Quick configuration advice
|
||||
==========================
|
||||
|
||||
If you want to exploit the full power of internationalization, you
|
||||
should configure it using
|
||||
|
||||
./configure --with-included-gettext
|
||||
|
||||
to force usage of internationalizing routines provided within this
|
||||
package, despite the existence of internationalizing capabilities in the
|
||||
operating system where this package is being installed. So far, only
|
||||
the `gettext' implementation in the GNU C library version 2 provides as
|
||||
many features (such as locale alias, message inheritance, automatic
|
||||
charset conversion or plural form handling) as the implementation here.
|
||||
It is also not possible to offer this additional functionality on top
|
||||
of a `catgets' implementation. Future versions of GNU `gettext' will
|
||||
very likely convey even more functionality. So it might be a good idea
|
||||
to change to GNU `gettext' as soon as possible.
|
||||
|
||||
So you need _not_ provide this option if you are using GNU libc 2 or
|
||||
you have installed a recent copy of the GNU gettext package with the
|
||||
included `libintl'.
|
||||
|
||||
INSTALL Matters
|
||||
===============
|
||||
|
||||
Some packages are "localizable" when properly installed; the programs
|
||||
they contain can be made to speak your own native language. Most such
|
||||
packages use GNU `gettext'. Other packages have their own ways to
|
||||
internationalization, predating GNU `gettext'.
|
||||
|
||||
By default, this package will be installed to allow translation of
|
||||
messages. It will automatically detect whether the system already
|
||||
provides the GNU `gettext' functions. If not, the GNU `gettext' own
|
||||
library will be used. This library is wholly contained within this
|
||||
package, usually in the `intl/' subdirectory, so prior installation of
|
||||
the GNU `gettext' package is _not_ required. Installers may use
|
||||
special options at configuration time for changing the default
|
||||
behaviour. The commands:
|
||||
|
||||
./configure --with-included-gettext
|
||||
./configure --disable-nls
|
||||
|
||||
will respectively bypass any pre-existing `gettext' to use the
|
||||
internationalizing routines provided within this package, or else,
|
||||
_totally_ disable translation of messages.
|
||||
|
||||
When you already have GNU `gettext' installed on your system and run
|
||||
configure without an option for your new package, `configure' will
|
||||
probably detect the previously built and installed `libintl.a' file and
|
||||
will decide to use this. This might be not what is desirable. You
|
||||
should use the more recent version of the GNU `gettext' library. I.e.
|
||||
if the file `intl/VERSION' shows that the library which comes with this
|
||||
package is more recent, you should use
|
||||
|
||||
./configure --with-included-gettext
|
||||
|
||||
to prevent auto-detection.
|
||||
|
||||
The configuration process will not test for the `catgets' function
|
||||
and therefore it will not be used. The reason is that even an
|
||||
emulation of `gettext' on top of `catgets' could not provide all the
|
||||
extensions of the GNU `gettext' library.
|
||||
|
||||
Internationalized packages have usually many `po/LL.po' files, where
|
||||
LL gives an ISO 639 two-letter code identifying the language. Unless
|
||||
translations have been forbidden at `configure' time by using the
|
||||
`--disable-nls' switch, all available translations are installed
|
||||
together with the package. However, the environment variable `LINGUAS'
|
||||
may be set, prior to configuration, to limit the installed set.
|
||||
`LINGUAS' should then contain a space separated list of two-letter
|
||||
codes, stating which languages are allowed.
|
||||
|
||||
Using This Package
|
||||
==================
|
||||
|
||||
As a user, if your language has been installed for this package, you
|
||||
only have to set the `LANG' environment variable to the appropriate
|
||||
`LL_CC' combination. Here `LL' is an ISO 639 two-letter language code,
|
||||
and `CC' is an ISO 3166 two-letter country code. For example, let's
|
||||
suppose that you speak German and live in Germany. At the shell
|
||||
prompt, merely execute `setenv LANG de_DE' (in `csh'),
|
||||
`export LANG; LANG=de_DE' (in `sh') or `export LANG=de_DE' (in `bash').
|
||||
This can be done from your `.login' or `.profile' file, once and for
|
||||
all.
|
||||
|
||||
You might think that the country code specification is redundant.
|
||||
But in fact, some languages have dialects in different countries. For
|
||||
example, `de_AT' is used for Austria, and `pt_BR' for Brazil. The
|
||||
country code serves to distinguish the dialects.
|
||||
|
||||
The locale naming convention of `LL_CC', with `LL' denoting the
|
||||
language and `CC' denoting the country, is the one use on systems based
|
||||
on GNU libc. On other systems, some variations of this scheme are
|
||||
used, such as `LL' or `LL_CC.ENCODING'. You can get the list of
|
||||
locales supported by your system for your country by running the command
|
||||
`locale -a | grep '^LL''.
|
||||
|
||||
Not all programs have translations for all languages. By default, an
|
||||
English message is shown in place of a nonexistent translation. If you
|
||||
understand other languages, you can set up a priority list of languages.
|
||||
This is done through a different environment variable, called
|
||||
`LANGUAGE'. GNU `gettext' gives preference to `LANGUAGE' over `LANG'
|
||||
for the purpose of message handling, but you still need to have `LANG'
|
||||
set to the primary language; this is required by other parts of the
|
||||
system libraries. For example, some Swedish users who would rather
|
||||
read translations in German than English for when Swedish is not
|
||||
available, set `LANGUAGE' to `sv:de' while leaving `LANG' to `sv_SE'.
|
||||
|
||||
In the `LANGUAGE' environment variable, but not in the `LANG'
|
||||
environment variable, `LL_CC' combinations can be abbreviated as `LL'
|
||||
to denote the language's main dialect. For example, `de' is equivalent
|
||||
to `de_DE' (German as spoken in Germany), and `pt' to `pt_PT'
|
||||
(Portuguese as spoken in Portugal) in this context.
|
||||
|
||||
Translating Teams
|
||||
=================
|
||||
|
||||
For the Free Translation Project to be a success, we need interested
|
||||
people who like their own language and write it well, and who are also
|
||||
able to synergize with other translators speaking the same language.
|
||||
Each translation team has its own mailing list. The up-to-date list of
|
||||
teams can be found at the Free Translation Project's homepage,
|
||||
`http://www.iro.umontreal.ca/contrib/po/HTML/', in the "National teams"
|
||||
area.
|
||||
|
||||
If you'd like to volunteer to _work_ at translating messages, you
|
||||
should become a member of the translating team for your own language.
|
||||
The subscribing address is _not_ the same as the list itself, it has
|
||||
`-request' appended. For example, speakers of Swedish can send a
|
||||
message to `sv-request@li.org', having this message body:
|
||||
|
||||
subscribe
|
||||
|
||||
Keep in mind that team members are expected to participate
|
||||
_actively_ in translations, or at solving translational difficulties,
|
||||
rather than merely lurking around. If your team does not exist yet and
|
||||
you want to start one, or if you are unsure about what to do or how to
|
||||
get started, please write to `translation@iro.umontreal.ca' to reach the
|
||||
coordinator for all translator teams.
|
||||
|
||||
The English team is special. It works at improving and uniformizing
|
||||
the terminology in use. Proven linguistic skill are praised more than
|
||||
programming skill, here.
|
||||
|
||||
Available Packages
|
||||
==================
|
||||
|
||||
Languages are not equally supported in all packages. The following
|
||||
matrix shows the current state of internationalization, as of December
|
||||
2003. The matrix shows, in regard of each package, for which languages
|
||||
PO files have been submitted to translation coordination, with a
|
||||
translation percentage of at least 50%.
|
||||
|
||||
Ready PO files am az be bg ca cs da de el en en_GB eo es
|
||||
+-------------------------------------------+
|
||||
a2ps | [] [] [] [] |
|
||||
aegis | () |
|
||||
ant-phone | () |
|
||||
anubis | |
|
||||
ap-utils | |
|
||||
bash | [] [] [] [] |
|
||||
batchelor | |
|
||||
bfd | [] [] |
|
||||
binutils | [] [] |
|
||||
bison | [] [] [] |
|
||||
bluez-pin | [] [] |
|
||||
clisp | |
|
||||
clisp | [] [] [] |
|
||||
coreutils | [] [] [] [] |
|
||||
cpio | [] [] [] |
|
||||
darkstat | [] () [] |
|
||||
diffutils | [] [] [] [] [] [] [] |
|
||||
e2fsprogs | [] [] |
|
||||
enscript | [] [] [] [] |
|
||||
error | [] [] [] [] [] |
|
||||
fetchmail | [] () [] [] [] [] |
|
||||
fileutils | [] [] [] |
|
||||
findutils | [] [] [] [] [] [] [] |
|
||||
flex | [] [] [] [] |
|
||||
fslint | |
|
||||
gas | [] |
|
||||
gawk | [] [] [] [] |
|
||||
gbiff | [] |
|
||||
gcal | [] |
|
||||
gcc | [] [] |
|
||||
gettext | [] [] [] [] [] |
|
||||
gettext-examples | [] [] [] |
|
||||
gettext-runtime | [] [] [] [] [] |
|
||||
gettext-tools | [] [] [] |
|
||||
gimp-print | [] [] [] [] [] |
|
||||
gliv | |
|
||||
glunarclock | [] [] |
|
||||
gnubiff | [] |
|
||||
gnucash | [] () [] [] |
|
||||
gnucash-glossary | [] () [] |
|
||||
gnupg | [] () [] [] [] [] |
|
||||
gpe-aerial | [] |
|
||||
gpe-beam | [] [] |
|
||||
gpe-calendar | [] [] |
|
||||
gpe-clock | [] [] |
|
||||
gpe-conf | [] [] |
|
||||
gpe-contacts | [] [] |
|
||||
gpe-edit | [] |
|
||||
gpe-go | [] |
|
||||
gpe-login | [] [] |
|
||||
gpe-ownerinfo | [] [] |
|
||||
gpe-sketchbook | [] [] |
|
||||
gpe-su | [] [] |
|
||||
gpe-taskmanager | [] [] |
|
||||
gpe-timesheet | [] |
|
||||
gpe-today | [] [] |
|
||||
gpe-todo | [] [] |
|
||||
gphoto2 | [] [] [] [] |
|
||||
gprof | [] [] [] |
|
||||
gpsdrive | () () () |
|
||||
gramadoir | [] |
|
||||
grep | [] [] [] [] [] [] |
|
||||
gretl | [] |
|
||||
gtick | () |
|
||||
hello | [] [] [] [] [] [] |
|
||||
id-utils | [] [] |
|
||||
indent | [] [] [] [] |
|
||||
jpilot | [] [] [] |
|
||||
jtag | |
|
||||
jwhois | [] |
|
||||
kbd | [] [] [] [] [] |
|
||||
latrine | () |
|
||||
ld | [] [] |
|
||||
libc | [] [] [] [] [] [] |
|
||||
libgpewidget | [] [] |
|
||||
libiconv | [] [] [] [] [] |
|
||||
lifelines | [] () |
|
||||
lilypond | [] |
|
||||
lingoteach | |
|
||||
lingoteach_lessons | () () |
|
||||
lynx | [] [] [] [] |
|
||||
m4 | [] [] [] [] |
|
||||
mailutils | [] [] |
|
||||
make | [] [] [] |
|
||||
man-db | [] () [] [] () |
|
||||
minicom | [] [] [] |
|
||||
mysecretdiary | [] [] [] |
|
||||
nano | [] () [] [] [] |
|
||||
nano_1_0 | [] () [] [] [] |
|
||||
opcodes | [] |
|
||||
parted | [] [] [] [] [] |
|
||||
ptx | [] [] [] [] [] |
|
||||
python | |
|
||||
radius | [] |
|
||||
recode | [] [] [] [] [] [] [] |
|
||||
rpm | [] [] |
|
||||
screem | |
|
||||
scrollkeeper | [] [] [] [] [] [] |
|
||||
sed | [] [] [] [] [] |
|
||||
sh-utils | [] [] [] |
|
||||
shared-mime-info | |
|
||||
sharutils | [] [] [] [] [] [] |
|
||||
silky | () |
|
||||
skencil | [] () [] |
|
||||
sketch | [] () [] |
|
||||
soundtracker | [] [] [] |
|
||||
sp | [] |
|
||||
tar | [] [] [] [] |
|
||||
texinfo | [] [] [] |
|
||||
textutils | [] [] [] [] |
|
||||
tin | () () |
|
||||
tuxpaint | [] [] [] [] [] [] [] |
|
||||
util-linux | [] [] [] [] [] |
|
||||
vorbis-tools | [] [] [] [] |
|
||||
wastesedge | () |
|
||||
wdiff | [] [] [] [] |
|
||||
wget | [] [] [] [] [] [] |
|
||||
xchat | [] [] [] [] |
|
||||
xfree86_xkb_xml | [] |
|
||||
xpad | [] |
|
||||
+-------------------------------------------+
|
||||
am az be bg ca cs da de el en en_GB eo es
|
||||
0 0 8 3 37 38 56 73 15 1 5 12 64
|
||||
|
||||
et fa fi fr ga gl he hr hu id is it ja
|
||||
+----------------------------------------+
|
||||
a2ps | [] [] [] () |
|
||||
aegis | |
|
||||
ant-phone | |
|
||||
anubis | [] |
|
||||
ap-utils | [] |
|
||||
bash | [] [] |
|
||||
batchelor | [] |
|
||||
bfd | [] |
|
||||
binutils | [] [] |
|
||||
bison | [] [] [] [] |
|
||||
bluez-pin | [] [] [] [] [] |
|
||||
clisp | |
|
||||
clisp | [] |
|
||||
coreutils | [] [] [] [] [] [] |
|
||||
cpio | [] [] [] |
|
||||
darkstat | () [] [] [] |
|
||||
diffutils | [] [] [] [] [] [] [] |
|
||||
e2fsprogs | |
|
||||
enscript | [] [] |
|
||||
error | [] [] [] [] |
|
||||
fetchmail | [] |
|
||||
fileutils | [] [] [] [] [] [] |
|
||||
findutils | [] [] [] [] [] [] [] [] [] [] |
|
||||
flex | [] [] |
|
||||
fslint | |
|
||||
gas | [] |
|
||||
gawk | [] [] [] |
|
||||
gbiff | |
|
||||
gcal | [] |
|
||||
gcc | [] |
|
||||
gettext | [] [] |
|
||||
gettext-examples | [] [] |
|
||||
gettext-runtime | [] [] [] [] |
|
||||
gettext-tools | [] [] |
|
||||
gimp-print | [] [] |
|
||||
gliv | () |
|
||||
glunarclock | [] [] [] [] |
|
||||
gnubiff | |
|
||||
gnucash | () [] |
|
||||
gnucash-glossary | [] |
|
||||
gnupg | [] [] [] [] [] [] [] |
|
||||
gpe-aerial | [] |
|
||||
gpe-beam | [] |
|
||||
gpe-calendar | [] [] [] |
|
||||
gpe-clock | [] |
|
||||
gpe-conf | [] |
|
||||
gpe-contacts | [] [] |
|
||||
gpe-edit | [] [] |
|
||||
gpe-go | [] |
|
||||
gpe-login | [] [] |
|
||||
gpe-ownerinfo | [] [] [] |
|
||||
gpe-sketchbook | [] |
|
||||
gpe-su | [] |
|
||||
gpe-taskmanager | [] |
|
||||
gpe-timesheet | [] [] [] |
|
||||
gpe-today | [] [] |
|
||||
gpe-todo | [] [] |
|
||||
gphoto2 | [] [] [] |
|
||||
gprof | [] [] |
|
||||
gpsdrive | () [] () () |
|
||||
gramadoir | [] |
|
||||
grep | [] [] [] [] [] [] [] [] [] [] [] |
|
||||
gretl | [] |
|
||||
gtick | [] [] |
|
||||
hello | [] [] [] [] [] [] [] [] [] [] [] [] |
|
||||
id-utils | [] [] [] [] |
|
||||
indent | [] [] [] [] [] [] [] [] [] |
|
||||
jpilot | [] () |
|
||||
jtag | |
|
||||
jwhois | [] [] [] [] |
|
||||
kbd | [] |
|
||||
latrine | |
|
||||
ld | [] |
|
||||
libc | [] [] [] [] [] |
|
||||
libgpewidget | [] [] [] [] |
|
||||
libiconv | [] [] [] [] [] [] [] [] [] |
|
||||
lifelines | () |
|
||||
lilypond | [] |
|
||||
lingoteach | [] [] |
|
||||
lingoteach_lessons | |
|
||||
lynx | [] [] [] [] |
|
||||
m4 | [] [] [] [] |
|
||||
mailutils | |
|
||||
make | [] [] [] [] [] |
|
||||
man-db | () () |
|
||||
minicom | [] [] [] [] |
|
||||
mysecretdiary | [] [] |
|
||||
nano | [] [] [] [] |
|
||||
nano_1_0 | [] [] [] [] |
|
||||
opcodes | [] |
|
||||
parted | [] [] [] |
|
||||
ptx | [] [] [] [] [] [] [] |
|
||||
python | |
|
||||
radius | [] |
|
||||
recode | [] [] [] [] [] [] |
|
||||
rpm | |
|
||||
screem | |
|
||||
scrollkeeper | [] |
|
||||
sed | [] [] [] [] [] [] [] [] [] |
|
||||
sh-utils | [] [] [] [] [] [] [] |
|
||||
shared-mime-info | [] |
|
||||
sharutils | [] [] [] [] [] |
|
||||
silky | [] () |
|
||||
skencil | [] |
|
||||
sketch | [] |
|
||||
soundtracker | [] [] [] [] |
|
||||
sp | [] () |
|
||||
tar | [] [] [] [] [] [] [] [] [] |
|
||||
texinfo | [] [] [] [] |
|
||||
textutils | [] [] [] [] [] |
|
||||
tin | [] () |
|
||||
tuxpaint | [] [] [] [] [] [] [] [] |
|
||||
util-linux | [] [] [] [] () [] |
|
||||
vorbis-tools | [] |
|
||||
wastesedge | () |
|
||||
wdiff | [] [] [] [] [] [] |
|
||||
wget | [] [] [] [] [] [] [] |
|
||||
xchat | [] [] [] |
|
||||
xfree86_xkb_xml | |
|
||||
xpad | [] |
|
||||
+----------------------------------------+
|
||||
et fa fi fr ga gl he hr hu id is it ja
|
||||
21 1 25 86 24 24 8 10 38 31 1 23 32
|
||||
|
||||
ko lg lt lv ms nb nl nn no pl pt pt_BR ro
|
||||
+-------------------------------------------+
|
||||
a2ps | () [] [] () () [] [] |
|
||||
aegis | () () |
|
||||
ant-phone | [] [] |
|
||||
anubis | [] [] [] [] [] |
|
||||
ap-utils | [] () [] |
|
||||
bash | [] [] |
|
||||
batchelor | [] |
|
||||
bfd | [] |
|
||||
binutils | |
|
||||
bison | [] [] [] [] |
|
||||
bluez-pin | [] [] [] |
|
||||
clisp | |
|
||||
clisp | [] |
|
||||
coreutils | [] |
|
||||
cpio | [] [] [] [] [] |
|
||||
darkstat | [] [] [] [] |
|
||||
diffutils | [] [] [] [] |
|
||||
e2fsprogs | [] |
|
||||
enscript | [] [] [] |
|
||||
error | [] [] [] |
|
||||
fetchmail | [] [] () |
|
||||
fileutils | [] [] |
|
||||
findutils | [] [] [] [] [] |
|
||||
flex | [] [] [] [] |
|
||||
fslint | [] [] |
|
||||
gas | |
|
||||
gawk | [] [] [] |
|
||||
gbiff | [] [] |
|
||||
gcal | |
|
||||
gcc | |
|
||||
gettext | [] [] [] |
|
||||
gettext-examples | [] [] |
|
||||
gettext-runtime | [] [] [] |
|
||||
gettext-tools | [] [] [] |
|
||||
gimp-print | [] |
|
||||
gliv | [] [] [] |
|
||||
glunarclock | [] [] [] |
|
||||
gnubiff | |
|
||||
gnucash | [] [] () |
|
||||
gnucash-glossary | [] [] |
|
||||
gnupg | [] |
|
||||
gpe-aerial | [] [] [] |
|
||||
gpe-beam | [] [] [] |
|
||||
gpe-calendar | [] [] [] |
|
||||
gpe-clock | [] [] [] |
|
||||
gpe-conf | [] [] [] |
|
||||
gpe-contacts | [] [] [] |
|
||||
gpe-edit | [] [] [] |
|
||||
gpe-go | [] [] |
|
||||
gpe-login | [] [] [] |
|
||||
gpe-ownerinfo | [] [] [] |
|
||||
gpe-sketchbook | [] [] [] |
|
||||
gpe-su | [] [] [] |
|
||||
gpe-taskmanager | [] [] [] |
|
||||
gpe-timesheet | [] [] [] |
|
||||
gpe-today | [] [] [] |
|
||||
gpe-todo | [] [] [] |
|
||||
gphoto2 | [] |
|
||||
gprof | [] [] |
|
||||
gpsdrive | () () () [] |
|
||||
gramadoir | [] |
|
||||
grep | [] [] [] [] |
|
||||
gretl | |
|
||||
gtick | [] [] |
|
||||
hello | [] [] [] [] [] [] [] [] [] [] |
|
||||
id-utils | [] [] [] |
|
||||
indent | [] [] [] |
|
||||
jpilot | () () |
|
||||
jtag | |
|
||||
jwhois | [] [] [] [] |
|
||||
kbd | [] [] [] |
|
||||
latrine | [] |
|
||||
ld | |
|
||||
libc | [] [] [] [] [] |
|
||||
libgpewidget | [] [] [] |
|
||||
libiconv | [] [] [] [] |
|
||||
lifelines | |
|
||||
lilypond | |
|
||||
lingoteach | |
|
||||
lingoteach_lessons | |
|
||||
lynx | [] [] |
|
||||
m4 | [] [] [] [] |
|
||||
mailutils | [] [] |
|
||||
make | [] [] [] [] |
|
||||
man-db | [] |
|
||||
minicom | [] [] [] |
|
||||
mysecretdiary | [] [] [] |
|
||||
nano | [] [] [] [] |
|
||||
nano_1_0 | [] [] [] [] [] |
|
||||
opcodes | [] [] |
|
||||
parted | [] [] [] [] |
|
||||
ptx | [] [] [] [] [] [] [] |
|
||||
python | |
|
||||
radius | [] |
|
||||
recode | [] [] [] |
|
||||
rpm | [] [] |
|
||||
screem | |
|
||||
scrollkeeper | [] [] [] [] |
|
||||
sed | [] [] [] |
|
||||
sh-utils | [] |
|
||||
shared-mime-info | [] |
|
||||
sharutils | [] |
|
||||
silky | |
|
||||
skencil | [] [] |
|
||||
sketch | [] [] |
|
||||
soundtracker | |
|
||||
sp | |
|
||||
tar | [] [] [] [] [] [] |
|
||||
texinfo | [] [] [] |
|
||||
textutils | [] [] |
|
||||
tin | |
|
||||
tuxpaint | [] [] [] [] [] [] [] [] [] |
|
||||
util-linux | [] [] |
|
||||
vorbis-tools | [] [] |
|
||||
wastesedge | |
|
||||
wdiff | [] [] [] [] |
|
||||
wget | [] [] |
|
||||
xchat | [] [] |
|
||||
xfree86_xkb_xml | [] |
|
||||
xpad | [] [] |
|
||||
+-------------------------------------------+
|
||||
ko lg lt lv ms nb nl nn no pl pt pt_BR ro
|
||||
12 0 1 2 12 10 60 4 4 38 25 35 76
|
||||
|
||||
ru sk sl sr sv ta tr uk vi wa zh_CN zh_TW
|
||||
+-------------------------------------------+
|
||||
a2ps | [] [] [] [] [] | 16
|
||||
aegis | () | 0
|
||||
ant-phone | | 2
|
||||
anubis | [] [] [] | 9
|
||||
ap-utils | () | 3
|
||||
bash | [] | 9
|
||||
batchelor | | 2
|
||||
bfd | [] [] | 6
|
||||
binutils | [] [] [] | 7
|
||||
bison | [] [] [] | 14
|
||||
bluez-pin | [] [] [] | 13
|
||||
clisp | | 0
|
||||
clisp | | 5
|
||||
coreutils | [] [] [] [] [] | 16
|
||||
cpio | [] [] [] | 14
|
||||
darkstat | [] [] [] () () | 12
|
||||
diffutils | [] [] [] [] | 22
|
||||
e2fsprogs | [] [] | 5
|
||||
enscript | [] [] [] | 12
|
||||
error | [] [] [] | 15
|
||||
fetchmail | [] [] [] | 11
|
||||
fileutils | [] [] [] [] [] [] | 17
|
||||
findutils | [] [] [] [] [] [] [] | 29
|
||||
flex | [] [] [] | 13
|
||||
fslint | | 2
|
||||
gas | [] | 3
|
||||
gawk | [] [] | 12
|
||||
gbiff | | 3
|
||||
gcal | [] [] | 4
|
||||
gcc | [] | 4
|
||||
gettext | [] [] [] [] [] [] | 16
|
||||
gettext-examples | [] [] [] [] | 11
|
||||
gettext-runtime | [] [] [] [] [] [] [] [] [] | 21
|
||||
gettext-tools | [] [] [] [] [] [] | 14
|
||||
gimp-print | [] [] | 10
|
||||
gliv | | 3
|
||||
glunarclock | [] [] [] [] | 13
|
||||
gnubiff | | 1
|
||||
gnucash | [] [] [] | 9
|
||||
gnucash-glossary | [] [] [] | 8
|
||||
gnupg | [] [] [] [] | 17
|
||||
gpe-aerial | [] [] | 7
|
||||
gpe-beam | [] [] | 8
|
||||
gpe-calendar | [] [] [] [] [] | 13
|
||||
gpe-clock | [] [] [] [] | 10
|
||||
gpe-conf | [] [] [] | 9
|
||||
gpe-contacts | [] [] [] [] | 11
|
||||
gpe-edit | [] [] [] [] [] [] | 12
|
||||
gpe-go | [] | 5
|
||||
gpe-login | [] [] [] [] [] [] | 13
|
||||
gpe-ownerinfo | [] [] [] [] [] | 13
|
||||
gpe-sketchbook | [] [] [] | 9
|
||||
gpe-su | [] [] [] [] | 10
|
||||
gpe-taskmanager | [] [] [] [] | 10
|
||||
gpe-timesheet | [] [] [] [] [] | 12
|
||||
gpe-today | [] [] [] [] [] [] | 13
|
||||
gpe-todo | [] [] [] [] [] | 12
|
||||
gphoto2 | [] [] [] | 11
|
||||
gprof | [] [] | 9
|
||||
gpsdrive | [] [] | 4
|
||||
gramadoir | | 3
|
||||
grep | [] [] [] [] [] | 26
|
||||
gretl | | 2
|
||||
gtick | [] | 5
|
||||
hello | [] [] [] [] [] | 33
|
||||
id-utils | [] [] [] | 12
|
||||
indent | [] [] [] [] [] | 21
|
||||
jpilot | [] [] [] [] [] | 9
|
||||
jtag | [] | 1
|
||||
jwhois | () () [] [] | 11
|
||||
kbd | [] [] | 11
|
||||
latrine | | 1
|
||||
ld | [] [] | 5
|
||||
libc | [] [] [] [] | 20
|
||||
libgpewidget | [] [] [] [] | 13
|
||||
libiconv | [] [] [] [] [] [] [] [] [] | 27
|
||||
lifelines | [] | 2
|
||||
lilypond | [] | 3
|
||||
lingoteach | | 2
|
||||
lingoteach_lessons | () | 0
|
||||
lynx | [] [] [] [] | 14
|
||||
m4 | [] [] [] | 15
|
||||
mailutils | [] | 5
|
||||
make | [] [] [] [] | 16
|
||||
man-db | [] | 5
|
||||
minicom | [] | 11
|
||||
mysecretdiary | [] [] | 10
|
||||
nano | [] [] [] [] [] | 17
|
||||
nano_1_0 | [] [] [] [] | 17
|
||||
opcodes | [] [] | 6
|
||||
parted | [] [] [] | 15
|
||||
ptx | [] [] [] | 22
|
||||
python | | 0
|
||||
radius | [] | 4
|
||||
recode | [] [] [] [] | 20
|
||||
rpm | [] [] [] | 7
|
||||
screem | [] [] | 2
|
||||
scrollkeeper | [] [] [] [] | 15
|
||||
sed | [] [] [] [] [] [] | 23
|
||||
sh-utils | [] [] [] | 14
|
||||
shared-mime-info | [] [] | 4
|
||||
sharutils | [] [] [] [] [] | 17
|
||||
silky | () | 2
|
||||
skencil | [] | 6
|
||||
sketch | [] | 6
|
||||
soundtracker | [] [] | 9
|
||||
sp | [] | 3
|
||||
tar | [] [] [] [] [] | 24
|
||||
texinfo | [] [] [] [] | 14
|
||||
textutils | [] [] [] [] [] | 16
|
||||
tin | | 1
|
||||
tuxpaint | [] [] [] [] [] | 29
|
||||
util-linux | [] [] [] | 15
|
||||
vorbis-tools | [] | 8
|
||||
wastesedge | | 0
|
||||
wdiff | [] [] [] [] | 18
|
||||
wget | [] [] [] [] [] [] [] [] | 23
|
||||
xchat | [] [] [] [] [] | 14
|
||||
xfree86_xkb_xml | [] [] [] [] [] [] | 8
|
||||
xpad | | 4
|
||||
+-------------------------------------------+
|
||||
51 teams ru sk sl sr sv ta tr uk vi wa zh_CN zh_TW
|
||||
120 domains 59 42 16 25 81 0 56 12 1 10 21 22 1260
|
||||
|
||||
Some counters in the preceding matrix are higher than the number of
|
||||
visible blocks let us expect. This is because a few extra PO files are
|
||||
used for implementing regional variants of languages, or language
|
||||
dialects.
|
||||
|
||||
For a PO file in the matrix above to be effective, the package to
|
||||
which it applies should also have been internationalized and
|
||||
distributed as such by its maintainer. There might be an observable
|
||||
lag between the mere existence a PO file and its wide availability in a
|
||||
distribution.
|
||||
|
||||
If December 2003 seems to be old, you may fetch a more recent copy
|
||||
of this `ABOUT-NLS' file on most GNU archive sites. The most
|
||||
up-to-date matrix with full percentage details can be found at
|
||||
`http://www.iro.umontreal.ca/contrib/po/HTML/matrix.html'.
|
||||
|
||||
Using `gettext' in new packages
|
||||
===============================
|
||||
|
||||
If you are writing a freely available program and want to
|
||||
internationalize it you are welcome to use GNU `gettext' in your
|
||||
package. Of course you have to respect the GNU Library General Public
|
||||
License which covers the use of the GNU `gettext' library. This means
|
||||
in particular that even non-free programs can use `libintl' as a shared
|
||||
library, whereas only free software can use `libintl' as a static
|
||||
library or use modified versions of `libintl'.
|
||||
|
||||
Once the sources are changed appropriately and the setup can handle
|
||||
the use of `gettext' the only thing missing are the translations. The
|
||||
Free Translation Project is also available for packages which are not
|
||||
developed inside the GNU project. Therefore the information given above
|
||||
applies also for every other Free Software Project. Contact
|
||||
`translation@iro.umontreal.ca' to make the `.pot' files available to
|
||||
the translation teams.
|
||||
|
|
@ -1,86 +0,0 @@
|
|||
Here are the names of the programs in this package,
|
||||
each followed by the name(s) of its author(s).
|
||||
|
||||
basename: FIXME unknown
|
||||
cat: Torbjorn Granlund and Richard M. Stallman
|
||||
chgrp: David MacKenzie
|
||||
chmod: David MacKenzie
|
||||
chown: David MacKenzie
|
||||
chroot: Roland McGrath
|
||||
cksum: Q. Frank Xia
|
||||
comm: Richard Stallman and David MacKenzie
|
||||
cp: Torbjorn Granlund, David MacKenzie, and Jim Meyering
|
||||
csplit: Stuart Kemp and David MacKenzie
|
||||
cut: David Ihnat, David MacKenzie, and Jim Meyering
|
||||
date: David MacKenzie
|
||||
dd: Paul Rubin, David MacKenzie, and Stuart Kemp
|
||||
df: Torbjorn Granlund, David MacKenzie, Larry McVoy, and Paul Eggert
|
||||
dircolors: H. Peter Anvin
|
||||
dirname: David MacKenzie and Jim Meyering
|
||||
du: Torbjorn Granlund, David MacKenzie, Larry McVoy, and Paul Eggert
|
||||
echo: FIXME unknown
|
||||
env: Richard Mlynarik and David MacKenzie
|
||||
expand: David MacKenzie
|
||||
expr: Mike Parker
|
||||
factor: Paul Rubin
|
||||
false: no one
|
||||
fmt: Ross Paterson
|
||||
fold: David MacKenzie
|
||||
head: David MacKenzie
|
||||
hostid: Jim Meyering
|
||||
hostname: Jim Meyering
|
||||
id: Arnold Robbins and David MacKenzie
|
||||
install: David MacKenzie
|
||||
join: Mike Haertel
|
||||
kill: Paul Eggert
|
||||
link: Michael Stone
|
||||
ln: Mike Parker and David MacKenzie
|
||||
logname: FIXME: unknown
|
||||
ls: Richard Stallman and David MacKenzie
|
||||
md5sum: Ulrich Drepper and Scott Miller
|
||||
mkdir: David MacKenzie
|
||||
mkfifo: David MacKenzie
|
||||
mknod: David MacKenzie
|
||||
mv: Mike Parker, David MacKenzie, and Jim Meyering
|
||||
nice: David MacKenzie
|
||||
nl: Scott Bartram and David MacKenzie
|
||||
od: Jim Meyering
|
||||
paste: David M. Ihnat and David MacKenzie
|
||||
pathchk: David MacKenzie and Jim Meyering
|
||||
pinky: Joseph Arceneaux, David MacKenzie, and Kaveh Ghazi
|
||||
pr: Pete TerMaat and Roland Huebner
|
||||
printenv: David MacKenzie and Richard Mlynarik
|
||||
printf: David MacKenzie
|
||||
ptx: François Pinard
|
||||
pwd: Jim Meyering
|
||||
rm: Paul Rubin, David MacKenzie, Richard Stallman, and Jim Meyering
|
||||
rmdir: David MacKenzie
|
||||
seq: Ulrich Drepper
|
||||
shred: Colin Plumb
|
||||
sleep: Jim Meyering and Paul Eggert
|
||||
sort: Mike Haertel and Paul Eggert
|
||||
split: Torbjorn Granlund and Richard M. Stallman
|
||||
stat: Michael Meskes
|
||||
stty: David MacKenzie
|
||||
su: David MacKenzie
|
||||
sum: Kayvan Aghaiepour and David MacKenzie
|
||||
sync: Jim Meyering
|
||||
tac: Jay Lepreau and David MacKenzie
|
||||
tail: Paul Rubin, David MacKenzie, Ian Lance Taylor, and Jim Meyering
|
||||
tee: Mike Parker, Richard M. Stallman, and David MacKenzie
|
||||
test: FIXME: ksb and mjb
|
||||
touch: Paul Rubin, Arnold Robbins, Jim Kingdon, David MacKenzie, and Randy Smith
|
||||
tr: Jim Meyering
|
||||
true: no one
|
||||
tsort: Mark Kettenis
|
||||
tty: David MacKenzie
|
||||
uname: David MacKenzie
|
||||
unexpand: David MacKenzie
|
||||
uniq: Richard Stallman and David MacKenzie
|
||||
unlink: Michael Stone
|
||||
uptime: Joseph Arceneaux, David MacKenzie, and Kaveh Ghazi
|
||||
users: Joseph Arceneaux and David MacKenzie
|
||||
wc: Paul Rubin and David MacKenzie
|
||||
who: Joseph Arceneaux, David MacKenzie, and Michael Stone
|
||||
whoami: Richard Mlynarik
|
||||
yes: David MacKenzie
|
||||
|
|
@ -1,340 +0,0 @@
|
|||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 2, June 1991
|
||||
|
||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
|
||||
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
License is intended to guarantee your freedom to share and change free
|
||||
software--to make sure the software is free for all its users. This
|
||||
General Public License applies to most of the Free Software
|
||||
Foundation's software and to any other program whose authors commit to
|
||||
using it. (Some other Free Software Foundation software is covered by
|
||||
the GNU Library General Public License instead.) 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
|
||||
this service 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 make restrictions that forbid
|
||||
anyone to deny you these rights or to ask you to surrender the rights.
|
||||
These restrictions translate to certain responsibilities for you if you
|
||||
distribute copies of the software, or if you modify it.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must give the recipients all the rights that
|
||||
you have. 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.
|
||||
|
||||
We protect your rights with two steps: (1) copyright the software, and
|
||||
(2) offer you this license which gives you legal permission to copy,
|
||||
distribute and/or modify the software.
|
||||
|
||||
Also, for each author's protection and ours, we want to make certain
|
||||
that everyone understands that there is no warranty for this free
|
||||
software. If the software is modified by someone else and passed on, we
|
||||
want its recipients to know that what they have is not the original, so
|
||||
that any problems introduced by others will not reflect on the original
|
||||
authors' reputations.
|
||||
|
||||
Finally, any free program is threatened constantly by software
|
||||
patents. We wish to avoid the danger that redistributors of a free
|
||||
program will individually obtain patent licenses, in effect making the
|
||||
program proprietary. To prevent this, we have made it clear that any
|
||||
patent must be licensed for everyone's free use or not licensed at all.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License applies to any program or other work which contains
|
||||
a notice placed by the copyright holder saying it may be distributed
|
||||
under the terms of this General Public License. The "Program", below,
|
||||
refers to any such program or work, and a "work based on the Program"
|
||||
means either the Program or any derivative work under copyright law:
|
||||
that is to say, a work containing the Program or a portion of it,
|
||||
either verbatim or with modifications and/or translated into another
|
||||
language. (Hereinafter, translation is included without limitation in
|
||||
the term "modification".) Each licensee is addressed as "you".
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running the Program is not restricted, and the output from the Program
|
||||
is covered only if its contents constitute a work based on the
|
||||
Program (independent of having been made by running the Program).
|
||||
Whether that is true depends on what the Program does.
|
||||
|
||||
1. You may copy and distribute 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 and disclaimer of warranty; keep intact all the
|
||||
notices that refer to this License and to the absence of any warranty;
|
||||
and give any other recipients of the Program a copy of this License
|
||||
along with the Program.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy, and
|
||||
you may at your option offer warranty protection in exchange for a fee.
|
||||
|
||||
2. You may modify your copy or copies of the Program or any portion
|
||||
of it, thus forming a work based on the Program, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) You must cause the modified files to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
b) You must cause any work that you distribute or publish, that in
|
||||
whole or in part contains or is derived from the Program or any
|
||||
part thereof, to be licensed as a whole at no charge to all third
|
||||
parties under the terms of this License.
|
||||
|
||||
c) If the modified program normally reads commands interactively
|
||||
when run, you must cause it, when started running for such
|
||||
interactive use in the most ordinary way, to print or display an
|
||||
announcement including an appropriate copyright notice and a
|
||||
notice that there is no warranty (or else, saying that you provide
|
||||
a warranty) and that users may redistribute the program under
|
||||
these conditions, and telling the user how to view a copy of this
|
||||
License. (Exception: if the Program itself is interactive but
|
||||
does not normally print such an announcement, your work based on
|
||||
the Program is not required to print an announcement.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Program,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Program, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Program.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Program
|
||||
with the Program (or with a work based on the Program) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may copy and distribute the Program (or a work based on it,
|
||||
under Section 2) in object code or executable form under the terms of
|
||||
Sections 1 and 2 above provided that you also do one of the following:
|
||||
|
||||
a) Accompany it with the complete corresponding machine-readable
|
||||
source code, which must be distributed under the terms of Sections
|
||||
1 and 2 above on a medium customarily used for software interchange; or,
|
||||
|
||||
b) Accompany it with a written offer, valid for at least three
|
||||
years, to give any third party, for a charge no more than your
|
||||
cost of physically performing source distribution, a complete
|
||||
machine-readable copy of the corresponding source code, to be
|
||||
distributed under the terms of Sections 1 and 2 above on a medium
|
||||
customarily used for software interchange; or,
|
||||
|
||||
c) Accompany it with the information you received as to the offer
|
||||
to distribute corresponding source code. (This alternative is
|
||||
allowed only for noncommercial distribution and only if you
|
||||
received the program in object code or executable form with such
|
||||
an offer, in accord with Subsection b above.)
|
||||
|
||||
The source code for a work means the preferred form of the work for
|
||||
making modifications to it. For an executable work, complete source
|
||||
code means all the source code for all modules it contains, plus any
|
||||
associated interface definition files, plus the scripts used to
|
||||
control compilation and installation of the executable. However, as a
|
||||
special exception, the source code distributed need not include
|
||||
anything that is normally distributed (in either source or binary
|
||||
form) with the major components (compiler, kernel, and so on) of the
|
||||
operating system on which the executable runs, unless that component
|
||||
itself accompanies the executable.
|
||||
|
||||
If distribution of executable or object code is made by offering
|
||||
access to copy from a designated place, then offering equivalent
|
||||
access to copy the source code from the same place counts as
|
||||
distribution of the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
4. You may not copy, modify, sublicense, or distribute the Program
|
||||
except as expressly provided under this License. Any attempt
|
||||
otherwise to copy, modify, sublicense or distribute the Program is
|
||||
void, and will automatically terminate your rights under this License.
|
||||
However, parties who have received copies, or rights, from you under
|
||||
this License will not have their licenses terminated so long as such
|
||||
parties remain in full compliance.
|
||||
|
||||
5. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Program or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Program (or any work based on the
|
||||
Program), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Program or works based on it.
|
||||
|
||||
6. Each time you redistribute the Program (or any work based on the
|
||||
Program), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute or modify the Program subject to
|
||||
these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties to
|
||||
this License.
|
||||
|
||||
7. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
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
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Program at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Program by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Program.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under
|
||||
any particular circumstance, the balance of the section is intended to
|
||||
apply and the section as a whole is intended to apply in other
|
||||
circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system, which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
8. If the distribution and/or use of the Program is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Program under this License
|
||||
may add an explicit geographical distribution limitation excluding
|
||||
those countries, so that distribution is permitted only in or among
|
||||
countries not thus excluded. In such case, this License incorporates
|
||||
the limitation as if written in the body of this License.
|
||||
|
||||
9. The Free Software Foundation may publish revised and/or new versions
|
||||
of the 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 a version number of this License which applies to it and "any
|
||||
later version", you have the option of following the terms and conditions
|
||||
either of that version or of any later version published by the Free
|
||||
Software Foundation. If the Program does not specify a version number of
|
||||
this License, you may choose any version ever published by the Free Software
|
||||
Foundation.
|
||||
|
||||
10. If you wish to incorporate parts of the Program into other free
|
||||
programs whose distribution conditions are different, write to the author
|
||||
to ask for permission. For software which is copyrighted by the Free
|
||||
Software Foundation, write to the Free Software Foundation; we sometimes
|
||||
make exceptions for this. Our decision will be guided by the two goals
|
||||
of preserving the free status of all derivatives of our free software and
|
||||
of promoting the sharing and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, 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.
|
||||
|
||||
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
||||
REDISTRIBUTE 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.
|
||||
|
||||
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
|
||||
convey the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
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 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, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program is interactive, make it output a short notice like this
|
||||
when it starts in an interactive mode:
|
||||
|
||||
Gnomovision version 69, Copyright (C) year name of author
|
||||
Gnomovision 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, the commands you use may
|
||||
be called something other than `show w' and `show c'; they could even be
|
||||
mouse-clicks or menu items--whatever suits your program.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your
|
||||
school, if any, to sign a "copyright disclaimer" for the program, if
|
||||
necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
|
||||
`Gnomovision' (which makes passes at compilers) written by James Hacker.
|
||||
|
||||
<signature of Ty Coon>, 1 April 1989
|
||||
Ty Coon, President of Vice
|
||||
|
||||
This 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 Library General
|
||||
Public License instead of this License.
|
||||
File diff suppressed because it is too large
Load diff
|
|
@ -1,14 +0,0 @@
|
|||
$FreeBSD$
|
||||
|
||||
GNU Sort
|
||||
originals can be found at: ftp://ftp.gnu.org/gnu/coreutils/
|
||||
|
||||
Configure by:
|
||||
./configure --disable-nls --without-libiconv-prefix \
|
||||
--without-libintl-prefix
|
||||
|
||||
Imported by:
|
||||
|
||||
cvs import \
|
||||
-m "Virgin import (trimmed) of GNU Sort, coreutils 5.2.1" \
|
||||
src/contrib/gnu-sort FSF SORT_v5_2_1
|
||||
|
|
@ -1,229 +0,0 @@
|
|||
Copyright (C) 1994, 1995, 1996, 1999, 2000, 2001, 2002 Free Software
|
||||
Foundation, Inc.
|
||||
|
||||
This file is free documentation; the Free Software Foundation gives
|
||||
unlimited permission to copy, distribute and modify it.
|
||||
|
||||
Basic Installation
|
||||
==================
|
||||
|
||||
These are generic installation instructions.
|
||||
|
||||
The `configure' shell script attempts to guess correct values for
|
||||
various system-dependent variables used during compilation. It uses
|
||||
those values to create a `Makefile' in each directory of the package.
|
||||
It may also create one or more `.h' files containing system-dependent
|
||||
definitions. Finally, it creates a shell script `config.status' that
|
||||
you can run in the future to recreate the current configuration, and a
|
||||
file `config.log' containing compiler output (useful mainly for
|
||||
debugging `configure').
|
||||
|
||||
It can also use an optional file (typically called `config.cache'
|
||||
and enabled with `--cache-file=config.cache' or simply `-C') that saves
|
||||
the results of its tests to speed up reconfiguring. (Caching is
|
||||
disabled by default to prevent problems with accidental use of stale
|
||||
cache files.)
|
||||
|
||||
If you need to do unusual things to compile the package, please try
|
||||
to figure out how `configure' could check whether to do them, and mail
|
||||
diffs or instructions to the address given in the `README' so they can
|
||||
be considered for the next release. If you are using the cache, and at
|
||||
some point `config.cache' contains results you don't want to keep, you
|
||||
may remove or edit it.
|
||||
|
||||
The file `configure.ac' (or `configure.in') is used to create
|
||||
`configure' by a program called `autoconf'. You only need
|
||||
`configure.ac' if you want to change it or regenerate `configure' using
|
||||
a newer version of `autoconf'.
|
||||
|
||||
The simplest way to compile this package is:
|
||||
|
||||
1. `cd' to the directory containing the package's source code and type
|
||||
`./configure' to configure the package for your system. If you're
|
||||
using `csh' on an old version of System V, you might need to type
|
||||
`sh ./configure' instead to prevent `csh' from trying to execute
|
||||
`configure' itself.
|
||||
|
||||
Running `configure' takes awhile. While running, it prints some
|
||||
messages telling which features it is checking for.
|
||||
|
||||
2. Type `make' to compile the package.
|
||||
|
||||
3. Optionally, type `make check' to run any self-tests that come with
|
||||
the package.
|
||||
|
||||
4. Type `make install' to install the programs and any data files and
|
||||
documentation.
|
||||
|
||||
5. You can remove the program binaries and object files from the
|
||||
source code directory by typing `make clean'. To also remove the
|
||||
files that `configure' created (so you can compile the package for
|
||||
a different kind of computer), type `make distclean'. There is
|
||||
also a `make maintainer-clean' target, but that is intended mainly
|
||||
for the package's developers. If you use it, you may have to get
|
||||
all sorts of other programs in order to regenerate files that came
|
||||
with the distribution.
|
||||
|
||||
Compilers and Options
|
||||
=====================
|
||||
|
||||
Some systems require unusual options for compilation or linking that
|
||||
the `configure' script does not know about. Run `./configure --help'
|
||||
for details on some of the pertinent environment variables.
|
||||
|
||||
You can give `configure' initial values for configuration parameters
|
||||
by setting variables in the command line or in the environment. Here
|
||||
is an example:
|
||||
|
||||
./configure CC=c89 CFLAGS=-O2 LIBS=-lposix
|
||||
|
||||
*Note Defining Variables::, for more details.
|
||||
|
||||
Compiling For Multiple Architectures
|
||||
====================================
|
||||
|
||||
You can compile the package for more than one kind of computer at the
|
||||
same time, by placing the object files for each architecture in their
|
||||
own directory. To do this, you must use a version of `make' that
|
||||
supports the `VPATH' variable, such as GNU `make'. `cd' to the
|
||||
directory where you want the object files and executables to go and run
|
||||
the `configure' script. `configure' automatically checks for the
|
||||
source code in the directory that `configure' is in and in `..'.
|
||||
|
||||
If you have to use a `make' that does not support the `VPATH'
|
||||
variable, you have to compile the package for one architecture at a
|
||||
time in the source code directory. After you have installed the
|
||||
package for one architecture, use `make distclean' before reconfiguring
|
||||
for another architecture.
|
||||
|
||||
Installation Names
|
||||
==================
|
||||
|
||||
By default, `make install' will install the package's files in
|
||||
`/usr/local/bin', `/usr/local/man', etc. You can specify an
|
||||
installation prefix other than `/usr/local' by giving `configure' the
|
||||
option `--prefix=PATH'.
|
||||
|
||||
You can specify separate installation prefixes for
|
||||
architecture-specific files and architecture-independent files. If you
|
||||
give `configure' the option `--exec-prefix=PATH', the package will use
|
||||
PATH as the prefix for installing programs and libraries.
|
||||
Documentation and other data files will still use the regular prefix.
|
||||
|
||||
In addition, if you use an unusual directory layout you can give
|
||||
options like `--bindir=PATH' to specify different values for particular
|
||||
kinds of files. Run `configure --help' for a list of the directories
|
||||
you can set and what kinds of files go in them.
|
||||
|
||||
If the package supports it, you can cause programs to be installed
|
||||
with an extra prefix or suffix on their names by giving `configure' the
|
||||
option `--program-prefix=PREFIX' or `--program-suffix=SUFFIX'.
|
||||
|
||||
Optional Features
|
||||
=================
|
||||
|
||||
Some packages pay attention to `--enable-FEATURE' options to
|
||||
`configure', where FEATURE indicates an optional part of the package.
|
||||
They may also pay attention to `--with-PACKAGE' options, where PACKAGE
|
||||
is something like `gnu-as' or `x' (for the X Window System). The
|
||||
`README' should mention any `--enable-' and `--with-' options that the
|
||||
package recognizes.
|
||||
|
||||
For packages that use the X Window System, `configure' can usually
|
||||
find the X include and library files automatically, but if it doesn't,
|
||||
you can use the `configure' options `--x-includes=DIR' and
|
||||
`--x-libraries=DIR' to specify their locations.
|
||||
|
||||
Specifying the System Type
|
||||
==========================
|
||||
|
||||
There may be some features `configure' cannot figure out
|
||||
automatically, but needs to determine by the type of machine the package
|
||||
will run on. Usually, assuming the package is built to be run on the
|
||||
_same_ architectures, `configure' can figure that out, but if it prints
|
||||
a message saying it cannot guess the machine type, give it the
|
||||
`--build=TYPE' option. TYPE can either be a short name for the system
|
||||
type, such as `sun4', or a canonical name which has the form:
|
||||
|
||||
CPU-COMPANY-SYSTEM
|
||||
|
||||
where SYSTEM can have one of these forms:
|
||||
|
||||
OS KERNEL-OS
|
||||
|
||||
See the file `config.sub' for the possible values of each field. If
|
||||
`config.sub' isn't included in this package, then this package doesn't
|
||||
need to know the machine type.
|
||||
|
||||
If you are _building_ compiler tools for cross-compiling, you should
|
||||
use the `--target=TYPE' option to select the type of system they will
|
||||
produce code for.
|
||||
|
||||
If you want to _use_ a cross compiler, that generates code for a
|
||||
platform different from the build platform, you should specify the
|
||||
"host" platform (i.e., that on which the generated programs will
|
||||
eventually be run) with `--host=TYPE'.
|
||||
|
||||
Sharing Defaults
|
||||
================
|
||||
|
||||
If you want to set default values for `configure' scripts to share,
|
||||
you can create a site shell script called `config.site' that gives
|
||||
default values for variables like `CC', `cache_file', and `prefix'.
|
||||
`configure' looks for `PREFIX/share/config.site' if it exists, then
|
||||
`PREFIX/etc/config.site' if it exists. Or, you can set the
|
||||
`CONFIG_SITE' environment variable to the location of the site script.
|
||||
A warning: not all `configure' scripts look for a site script.
|
||||
|
||||
Defining Variables
|
||||
==================
|
||||
|
||||
Variables not defined in a site shell script can be set in the
|
||||
environment passed to `configure'. However, some packages may run
|
||||
configure again during the build, and the customized values of these
|
||||
variables may be lost. In order to avoid this problem, you should set
|
||||
them in the `configure' command line, using `VAR=value'. For example:
|
||||
|
||||
./configure CC=/usr/local2/bin/gcc
|
||||
|
||||
will cause the specified gcc to be used as the C compiler (unless it is
|
||||
overridden in the site shell script).
|
||||
|
||||
`configure' Invocation
|
||||
======================
|
||||
|
||||
`configure' recognizes the following options to control how it
|
||||
operates.
|
||||
|
||||
`--help'
|
||||
`-h'
|
||||
Print a summary of the options to `configure', and exit.
|
||||
|
||||
`--version'
|
||||
`-V'
|
||||
Print the version of Autoconf used to generate the `configure'
|
||||
script, and exit.
|
||||
|
||||
`--cache-file=FILE'
|
||||
Enable the cache: use and save the results of the tests in FILE,
|
||||
traditionally `config.cache'. FILE defaults to `/dev/null' to
|
||||
disable caching.
|
||||
|
||||
`--config-cache'
|
||||
`-C'
|
||||
Alias for `--cache-file=config.cache'.
|
||||
|
||||
`--quiet'
|
||||
`--silent'
|
||||
`-q'
|
||||
Do not print messages saying which checks are being made. To
|
||||
suppress all normal output, redirect it to `/dev/null' (any error
|
||||
messages will still be shown).
|
||||
|
||||
`--srcdir=DIR'
|
||||
Look for the package's source code in directory DIR. Usually
|
||||
`configure' can determine that directory automatically.
|
||||
|
||||
`configure' also accepts some other, not widely useful, options. Run
|
||||
`configure --help' for more details.
|
||||
|
||||
|
|
@ -1,904 +0,0 @@
|
|||
GNU coreutils NEWS -*- outline -*-
|
||||
|
||||
* Major changes in release 5.3.0 (2004-03-17) [unstable]
|
||||
|
||||
** Bug fixes
|
||||
|
||||
rm (without -f) no longer hangs when attempting to remove a symlink
|
||||
to a file on an off-line NFS-mounted partition.
|
||||
|
||||
cut's --output-delimiter=D option works with abutting byte ranges.
|
||||
|
||||
rm no longer gets a failed assertion under some unusual conditions.
|
||||
|
||||
Several fixes to chgrp and chown for compatibility with POSIX and BSD:
|
||||
|
||||
Do not affect symbolic links by default.
|
||||
Now, operate on whatever a symbolic points to, instead.
|
||||
To get the old behavior, use --no-dereference (-h).
|
||||
|
||||
--dereference now works, even when the specified owner
|
||||
and/or group match those of an affected symlink.
|
||||
|
||||
Check for incompatible options. When -R and --dereference are
|
||||
both used, then either -H or -L must also be used. When -R and -h
|
||||
are both used, then -P must be in effect.
|
||||
|
||||
-H, -L, and -P have no effect unless -R is also specified.
|
||||
If -P and -R are both specified, -h is assumed.
|
||||
|
||||
Do not optimize away the chown() system call when the file's owner
|
||||
and group already have the desired value. This optimization was
|
||||
incorrect, as it failed to update the last-changed time and reset
|
||||
special permission bits, as POSIX requires.
|
||||
|
||||
Do not report an error if the owner or group of a
|
||||
recursively-encountered symbolic link cannot be updated because
|
||||
the file system does not support it.
|
||||
|
||||
md5sum and sha1sum now report an error when given so many input
|
||||
lines that their line counter overflows, instead of silently
|
||||
reporting incorrect results.
|
||||
|
||||
rm no longer requires read access to the current directory.
|
||||
|
||||
"sort -o -" now writes to a file named "-" instead of to standard
|
||||
output; POSIX requires this.
|
||||
|
||||
tail -f no longer mishandles pipes and fifos. With no operands,
|
||||
tail now ignores -f if standard input is a pipe, as POSIX requires.
|
||||
|
||||
For some types of errors (e.g., read-only file system, I/O error)
|
||||
when first encountering a directory, `rm -r' would mistakenly fail
|
||||
to remove files under that directory.
|
||||
|
||||
If d/x is a directory and x a file, "ln x d/" now reports an error
|
||||
instead of incorrectly creating a link to d/x/x.
|
||||
|
||||
Fixes for "nice":
|
||||
|
||||
If it fails to lower the nice value due to lack of permissions,
|
||||
it goes ahead and runs the command anyway, as POSIX requires.
|
||||
|
||||
It no longer incorrectly reports an error if the current nice
|
||||
value happens to be -1.
|
||||
|
||||
It no longer assumes that nice values range from -20 through 19.
|
||||
|
||||
It now consistently adjusts out-of-range nice values to the
|
||||
closest values in range; formerly it sometimes reported an error.
|
||||
|
||||
ptx now diagnoses invalid values for its --width=N (-w)
|
||||
and --gap-size=N (-g) options.
|
||||
|
||||
tee now exits when it gets a SIGPIPE signal, as POSIX requires.
|
||||
To get tee's old behavior, use the shell command "(trap '' PIPE; tee)".
|
||||
Also, "tee -" now writes to standard output instead of to a file named "-".
|
||||
|
||||
ls no longer segfaults on systems for which SIZE_MAX != (size_t) -1
|
||||
|
||||
echo now conforms to POSIX better. It supports the \0ooo syntax for
|
||||
octal escapes, and \c now terminates printing immediately. If
|
||||
POSIXLY_CORRECT is set and the first argument is not "-n", echo now
|
||||
outputs all option-like arguments instead of treating them as options.
|
||||
|
||||
printf has several changes:
|
||||
|
||||
It now uses 'intmax_t' (not 'long int') to format integers, so it
|
||||
can now format 64-bit integers on most modern hosts.
|
||||
|
||||
On modern hosts it now supports the C99-inspired %a, %A, %F conversion
|
||||
specs, the "'" and "0" flags, and the ll, j, t, and z length modifiers
|
||||
(this is compatible with recent Bash versions).
|
||||
|
||||
The printf command now rejects invalid conversion specifications
|
||||
like %#d, instead of relying on undefined behavior in the underlying
|
||||
printf function.
|
||||
|
||||
who now prints user names in full instead of truncating them after 8 bytes.
|
||||
|
||||
** New features
|
||||
|
||||
For efficiency, `sort -m' no longer copies input to a temporary file
|
||||
merely because the input happens to come from a pipe. As a result,
|
||||
some relatively-contrived examples like `cat F | sort -m -o F - G'
|
||||
are no longer safe, as `sort' might start writing F before `cat' is
|
||||
done reading it. This problem cannot occur unless `-m' is used.
|
||||
|
||||
When outside the default POSIX locale, the 'who' and 'pinky'
|
||||
commands now output time stamps like "2004-06-21 13:09" instead of
|
||||
the traditional "Jun 21 13:09".
|
||||
|
||||
pwd now works even when run from a working directory whose name
|
||||
is longer than PATH_MAX.
|
||||
|
||||
cp, install, ln, and mv have a new --no-target-directory (-T) option,
|
||||
and -t is now a short name for their --target-directory option.
|
||||
|
||||
cp -pu and mv -u (when copying) now don't bother to update the
|
||||
destination if the resulting time stamp would be no newer than the
|
||||
preexisting time stamp. This saves work in the common case when
|
||||
copying or moving multiple times to the same destination in a file
|
||||
system with a coarse time stamp resolution.
|
||||
|
||||
dd has new conversions for the conv= option:
|
||||
|
||||
nocreat do not create the output file
|
||||
excl fail if the output file already exists
|
||||
fdatasync physically write output file data before finishing
|
||||
fsync likewise, but also write metadata
|
||||
|
||||
dd has new iflag= and oflag= options with the following flags:
|
||||
|
||||
append append mode (makes sense for output file only)
|
||||
direct use direct I/O for data
|
||||
dsync use synchronized I/O for data
|
||||
sync likewise, but also for metadata
|
||||
nonblock use non-blocking I/O
|
||||
nofollow do not follow symlinks
|
||||
|
||||
stty now provides support (iutf8) for setting UTF-8 input mode.
|
||||
|
||||
With stat, a specified format is no longer automatically newline terminated.
|
||||
If you want a newline at the end of your output, append `\n' to the format
|
||||
string.
|
||||
|
||||
'df', 'du', and 'ls' now take the default block size from the
|
||||
BLOCKSIZE environment variable if the BLOCK_SIZE, DF_BLOCK_SIZE,
|
||||
DU_BLOCK_SIZE, and LS_BLOCK_SIZE environment variables are not set.
|
||||
Unlike the other variables, though, BLOCKSIZE does not affect
|
||||
values like 'ls -l' sizes that are normally displayed as bytes.
|
||||
This new behavior is for compatibility with BSD.
|
||||
|
||||
du accepts a new option --files0-from=FILE, where FILE contains a
|
||||
list of NUL-terminated file names.
|
||||
|
||||
`date -d' and `touch -d' now accept integer counts of seconds since
|
||||
1970 when prefixed by `@'. For example, `@321' represents
|
||||
1970-01-01 00:05:21 UTC.
|
||||
|
||||
`date -d', `date -f' and `touch -d' now handle fractional time
|
||||
stamps like 2004-02-27 14:19:13.489392193.
|
||||
|
||||
`date' has a new option --iso-8601=ns that outputs
|
||||
nanosecond-resolution time stamps.
|
||||
|
||||
echo -e '\xHH' now outputs a byte whose hexadecimal value is HH,
|
||||
for compatibility with bash.
|
||||
|
||||
In the following cases POSIX allows the default GNU behavior,
|
||||
so when POSIXLY_CORRECT is set:
|
||||
|
||||
false, printf, true, unlink, and yes all support --help and --option.
|
||||
ls supports TABSIZE.
|
||||
pr no longer depends on LC_TIME for the date format in non-POSIX locales.
|
||||
printf supports \u, \U, \x.
|
||||
tail supports two or more files when using the obsolete option syntax.
|
||||
|
||||
The usual `--' operand is now supported by chroot, hostid, hostname,
|
||||
pwd, sync, and yes.
|
||||
|
||||
The stat option --filesystem has been renamed to --file-system, for
|
||||
consistency with POSIX "file system" and with cp and du --one-file-system.
|
||||
|
||||
** Removed features
|
||||
|
||||
tail's undocumented --max-consecutive-size-changes option has been removed.
|
||||
|
||||
* Major changes in release 5.2.1 (2004-03-12) [stable]
|
||||
|
||||
** Bug fixes
|
||||
|
||||
mv could mistakenly fail to preserve hard links when moving two
|
||||
or more arguments between partitions.
|
||||
|
||||
`cp --sparse=always F /dev/hdx' no longer tries to use lseek to create
|
||||
holes in the destination.
|
||||
|
||||
nohup now sets the close-on-exec flag for its copy of the stderr file
|
||||
descriptor. This avoids some nohup-induced hangs. For example, before
|
||||
this change, if you ran `ssh localhost', then `nohup sleep 600 </dev/null &',
|
||||
and then exited that remote shell, the ssh session would hang until the
|
||||
10-minute sleep terminated. With the fixed nohup, the ssh session
|
||||
terminates immediately.
|
||||
|
||||
`expr' now conforms to POSIX better:
|
||||
|
||||
Integers like -0 and 00 are now treated as zero.
|
||||
|
||||
The `|' operator now returns 0, not its first argument, if both
|
||||
arguments are null or zero. E.g., `expr "" \| ""' now returns 0,
|
||||
not the empty string.
|
||||
|
||||
The `|' and `&' operators now use short-circuit evaluation, e.g.,
|
||||
`expr 1 \| 1 / 0' no longer reports a division by zero.
|
||||
|
||||
** New features
|
||||
|
||||
`chown user.group file' now has its traditional meaning even when
|
||||
conforming to POSIX 1003.1-2001, so long as no user has a name
|
||||
containing `.' that happens to equal `user.group'.
|
||||
|
||||
|
||||
* Major changes in release 5.2.0 (2004-02-19) [stable]
|
||||
|
||||
** Bug fixes
|
||||
|
||||
none
|
||||
|
||||
|
||||
* Major changes in release 5.1.3 (2004-02-08): candidate to become stable 5.2.0
|
||||
|
||||
** Bug fixes
|
||||
|
||||
`cp -d' now works as required even on systems like OSF V5.1 that
|
||||
declare stat and lstat as `static inline' functions.
|
||||
|
||||
time stamps output by stat now include actual fractional seconds,
|
||||
when available -- or .0000000 for files without that information.
|
||||
|
||||
seq no longer infloops when printing 2^31 or more numbers.
|
||||
For reference, seq `echo 2^31|bc` > /dev/null takes about one hour
|
||||
on a 1.6 GHz Athlon 2000 XP. Now it can output 2^53-1 numbers before
|
||||
misbehaving.
|
||||
|
||||
* Major changes in release 5.1.2 (2004-01-25):
|
||||
|
||||
** Bug fixes
|
||||
|
||||
rmdir -p exits with status 1 on error; formerly it sometimes exited
|
||||
with status 0 when given more than one argument.
|
||||
|
||||
nohup now always exits with status 127 when it finds an error,
|
||||
as POSIX requires; formerly it sometimes exited with status 1.
|
||||
|
||||
Several programs (including cut, date, dd, env, hostname, nl, pr,
|
||||
stty, and tr) now always exit with status 1 when they find an error;
|
||||
formerly they sometimes exited with status 2.
|
||||
|
||||
factor no longer reports a usage error if stdin has the wrong format.
|
||||
|
||||
paste no longer infloops on ppc systems (bug introduced in 5.1.1)
|
||||
|
||||
|
||||
* Major changes in release 5.1.1 (2004-01-17):
|
||||
|
||||
** Configuration option
|
||||
|
||||
You can select the default level of POSIX conformance at configure-time,
|
||||
e.g., by ./configure DEFAULT_POSIX2_VERSION=199209
|
||||
|
||||
** Bug fixes
|
||||
|
||||
fold -s works once again on systems with differing sizes for int
|
||||
and size_t (bug introduced in 5.1.0)
|
||||
|
||||
** New features
|
||||
|
||||
touch -r now specifies the origin for any relative times in the -d
|
||||
operand, if both options are given. For example, "touch -r FOO -d
|
||||
'-5 seconds' BAR" sets BAR's modification time to be five seconds
|
||||
before FOO's.
|
||||
|
||||
join: The obsolete options "-j1 FIELD", "-j2 FIELD", and
|
||||
"-o LIST1 LIST2..." are no longer supported on POSIX 1003.1-2001 systems.
|
||||
Portable scripts should use "-1 FIELD", "-2 FIELD", and
|
||||
"-o LIST1,LIST2..." respectively. If join was compiled on a
|
||||
POSIX 1003.1-2001 system, you may enable the old behavior
|
||||
by setting _POSIX2_VERSION=199209 in your environment.
|
||||
|
||||
|
||||
* Major changes in release 5.1.0 (2003-12-21):
|
||||
|
||||
** New features
|
||||
|
||||
chgrp, chmod, and chown can now process (with -R) hierarchies of virtually
|
||||
unlimited depth. Before, they would fail to operate on any file they
|
||||
encountered with a relative name of length PATH_MAX (often 4096) or longer.
|
||||
|
||||
chgrp, chmod, chown, and rm accept the new options:
|
||||
--preserve-root, --no-preserve-root (default)
|
||||
|
||||
chgrp and chown now accept POSIX-mandated -L, -H, and -P options
|
||||
|
||||
du can now process hierarchies of virtually unlimited depth.
|
||||
Before, du was limited by the user's stack size and it would get a
|
||||
stack overflow error (often a segmentation fault) when applied to
|
||||
a hierarchy of depth around 30,000 or larger.
|
||||
|
||||
du works even when run from an inaccessible directory
|
||||
|
||||
du -D now dereferences all symlinks specified on the command line,
|
||||
not just the ones that reference directories
|
||||
|
||||
du now accepts -P (--no-dereference), for compatibility with du
|
||||
of NetBSD and for consistency with e.g., chown and chgrp
|
||||
|
||||
du's -H option will soon have the meaning required by POSIX
|
||||
(--dereference-args, aka -D) rather then the current meaning of --si.
|
||||
Now, using -H elicits a warning to that effect.
|
||||
|
||||
When given -l and similar options, ls now adjusts the output column
|
||||
widths to fit the data, so that output lines are shorter and have
|
||||
columns that line up better. This may adversely affect shell
|
||||
scripts that expect fixed-width columns, but such shell scripts were
|
||||
not portable anyway, even with old GNU ls where the columns became
|
||||
ragged when a datum was too wide.
|
||||
|
||||
du accepts a new option, -0/--null, to make it produce NUL-terminated
|
||||
output lines
|
||||
|
||||
** Bug fixes
|
||||
|
||||
printf, seq, tail, and sleep now parse floating-point operands
|
||||
and options in the C locale. POSIX requires this for printf.
|
||||
|
||||
od -c -w9999999 no longer segfaults
|
||||
|
||||
csplit no longer reads from freed memory (dumping core on some systems)
|
||||
|
||||
csplit would mistakenly exhaust virtual memory in some cases
|
||||
|
||||
ls --width=N (for very large N) is no longer subject to an address
|
||||
arithmetic bug that could result in bounds violations.
|
||||
|
||||
ls --width=N (with -x or -C) no longer allocates more space
|
||||
(potentially much more) than necessary for a given directory.
|
||||
|
||||
dd `unblock' and `sync' may now be combined (e.g., dd conv=unblock,sync)
|
||||
|
||||
* Major changes in release 5.0.91 (2003-09-08):
|
||||
|
||||
** New features
|
||||
|
||||
date accepts a new option --rfc-2822, an alias for --rfc-822.
|
||||
|
||||
split accepts a new option -d or --numeric-suffixes.
|
||||
|
||||
cp, install, mv, and touch now preserve microsecond resolution on
|
||||
file timestamps, on platforms that have the 'utimes' system call.
|
||||
Unfortunately there is no system call yet to preserve file
|
||||
timestamps to their full nanosecond resolution; microsecond
|
||||
resolution is the best we can do right now.
|
||||
|
||||
sort now supports the zero byte (NUL) as a field separator; use -t '\0'.
|
||||
The -t '' option, which formerly had no effect, is now an error.
|
||||
|
||||
sort option order no longer matters for the options -S, -d, -i, -o, and -t.
|
||||
Stronger options override weaker, and incompatible options are diagnosed.
|
||||
|
||||
`sha1sum --check' now accepts the BSD format for SHA1 message digests
|
||||
in addition to the BSD format for MD5 ones.
|
||||
|
||||
who -l now means `who --login', not `who --lookup', per POSIX.
|
||||
who's -l option has been eliciting an unconditional warning about
|
||||
this impending change since sh-utils-2.0.12 (April 2002).
|
||||
|
||||
** Bug fixes
|
||||
|
||||
Mistakenly renaming a file onto itself, e.g., via `mv B b' when `B' is
|
||||
the same directory entry as `b' no longer destroys the directory entry
|
||||
referenced by both `b' and `B'. Note that this would happen only on
|
||||
file systems like VFAT where two different names may refer to the same
|
||||
directory entry, usually due to lower->upper case mapping of file names.
|
||||
Now, the above can happen only on file systems that perform name mapping and
|
||||
that support hard links (stat.st_nlink > 1). This mitigates the problem
|
||||
in two ways: few file systems appear to be affected (hpfs and ntfs are),
|
||||
when the bug is triggered, mv no longer removes the last hard link to a file.
|
||||
*** ATTENTION ***: if you know how to distinguish the following two cases
|
||||
without writing to the file system in question, please let me know:
|
||||
1) B and b refer to the same directory entry on a file system like NTFS
|
||||
(B may well have a link count larger than 1)
|
||||
2) B and b are hard links to the same file
|
||||
|
||||
stat no longer overruns a buffer for format strings ending in `%'
|
||||
|
||||
fold -s -wN would infloop for N < 8 with TABs in the input.
|
||||
E.g., this would not terminate: printf 'a\t' | fold -w2 -s
|
||||
|
||||
`split -a0', although of questionable utility, is accepted once again.
|
||||
|
||||
`df DIR' used to hang under some conditions on OSF/1 5.1. Now it doesn't.
|
||||
|
||||
seq's --width (-w) option now works properly even when the endpoint
|
||||
requiring the larger width is negative and smaller than the other endpoint.
|
||||
|
||||
seq's default step is 1, even if LAST < FIRST.
|
||||
|
||||
paste no longer mistakenly outputs 0xFF bytes for a nonempty input file
|
||||
without a trailing newline.
|
||||
|
||||
`tail -n0 -f FILE' and `tail -c0 -f FILE' no longer perform what amounted
|
||||
to a busy wait, rather than sleeping between iterations.
|
||||
|
||||
tail's long-undocumented --allow-missing option now elicits a warning
|
||||
|
||||
|
||||
* Major changes in release 5.0.90 (2003-07-29):
|
||||
|
||||
** New features
|
||||
|
||||
sort is now up to 30% more CPU-efficient in some cases
|
||||
|
||||
`test' is now more compatible with Bash and POSIX:
|
||||
|
||||
`test -t', `test --help', and `test --version' now silently exit
|
||||
with status 0. To test whether standard output is a terminal, use
|
||||
`test -t 1'. To get help and version info for `test', use
|
||||
`[ --help' and `[ --version'.
|
||||
|
||||
`test' now exits with status 2 (not 1) if there is an error.
|
||||
|
||||
wc count field widths now are heuristically adjusted depending on the input
|
||||
size, if known. If only one count is printed, it is guaranteed to
|
||||
be printed without leading spaces.
|
||||
|
||||
Previously, wc did not align the count fields if POSIXLY_CORRECT was set,
|
||||
but POSIX did not actually require this undesirable behavior, so it
|
||||
has been removed.
|
||||
|
||||
** Bug fixes
|
||||
|
||||
kill no longer tries to operate on argv[0] (introduced in 5.0.1)
|
||||
Why wasn't this noticed? Although many tests use kill, none of
|
||||
them made an effort to avoid using the shell's built-in kill.
|
||||
|
||||
`[' invoked with no arguments no longer evokes a segfault
|
||||
|
||||
rm without --recursive (aka -r or -R) no longer prompts regarding
|
||||
unwritable directories, as required by POSIX.
|
||||
|
||||
uniq -c now uses a SPACE, not a TAB between the count and the
|
||||
corresponding line, as required by POSIX.
|
||||
|
||||
expr now exits with status 2 if the expression is syntactically valid,
|
||||
and with status 3 if an error occurred. POSIX requires this.
|
||||
|
||||
expr now reports trouble if string comparison fails due to a collation error.
|
||||
|
||||
split now generates suffixes properly on EBCDIC hosts.
|
||||
|
||||
split -a0 now works, as POSIX requires.
|
||||
|
||||
`sort --version' and `sort --help' fail, as they should
|
||||
when their output is redirected to /dev/full.
|
||||
|
||||
`su --version > /dev/full' now fails, as it should.
|
||||
|
||||
** Fewer arbitrary limitations
|
||||
|
||||
cut requires 97% less memory when very large field numbers or
|
||||
byte offsets are specified.
|
||||
|
||||
|
||||
* Major changes in release 5.0.1 (2003-07-15):
|
||||
|
||||
** New programs
|
||||
- new program: `[' (much like `test')
|
||||
|
||||
** New features
|
||||
- head now accepts --lines=-N (--bytes=-N) to print all but the
|
||||
N lines (bytes) at the end of the file
|
||||
- md5sum --check now accepts the output of the BSD md5sum program, e.g.,
|
||||
MD5 (f) = d41d8cd98f00b204e9800998ecf8427e
|
||||
- date -d DATE can now parse a DATE string like May-23-2003
|
||||
- chown: `.' is no longer recognized as a separator in the OWNER:GROUP
|
||||
specifier on POSIX 1003.1-2001 systems. If chown *was not* compiled
|
||||
on such a system, then it still accepts `.', by default. If chown
|
||||
was compiled on a POSIX 1003.1-2001 system, then you may enable the
|
||||
old behavior by setting _POSIX2_VERSION=199209 in your environment.
|
||||
- chown no longer tries to preserve set-user-ID and set-group-ID bits;
|
||||
on some systems, the chown syscall resets those bits, and previous
|
||||
versions of the chown command would call chmod to restore the original,
|
||||
pre-chown(2) settings, but that behavior is problematic.
|
||||
1) There was a window whereby a malicious user, M, could subvert a
|
||||
chown command run by some other user and operating on files in a
|
||||
directory where M has write access.
|
||||
2) Before (and even now, on systems with chown(2) that doesn't reset
|
||||
those bits), an unwary admin. could use chown unwittingly to create e.g.,
|
||||
a set-user-ID root copy of /bin/sh.
|
||||
|
||||
** Bug fixes
|
||||
- chown --dereference no longer leaks a file descriptor per symlink processed
|
||||
- `du /' once again prints the `/' on the last line
|
||||
- split's --verbose option works once again [broken in 4.5.10 and 5.0]
|
||||
- tail -f is no longer subject to a race condition that could make it
|
||||
delay displaying the last part of a file that had stopped growing. That
|
||||
bug could also make tail -f give an unwarranted `file truncated' warning.
|
||||
- du no longer runs out of file descriptors unnecessarily
|
||||
- df and `readlink --canonicalize' no longer corrupt the heap on
|
||||
non-glibc, non-solaris systems
|
||||
- `env -u UNSET_VARIABLE' no longer dumps core on non-glibc systems
|
||||
- readlink's --canonicalize option now works on systems like Solaris that
|
||||
lack the canonicalize_file_name function but do have resolvepath.
|
||||
- mv now removes `a' in this example on all systems: touch a; ln a b; mv a b
|
||||
This behavior is contrary to POSIX (which requires that the mv command do
|
||||
nothing and exit successfully), but I suspect POSIX will change.
|
||||
- date's %r format directive now honors locale settings
|
||||
- date's `-' (no-pad) format flag now affects the space-padded-by-default
|
||||
conversion specifiers, %e, %k, %l
|
||||
- fmt now diagnoses invalid obsolescent width specifications like `-72x'
|
||||
- fmt now exits nonzero when unable to open an input file
|
||||
- tsort now fails when given an odd number of input tokens,
|
||||
as required by POSIX. Before, it would act as if the final token
|
||||
appeared one additional time.
|
||||
|
||||
** Fewer arbitrary limitations
|
||||
- tail's byte and line counts are no longer limited to OFF_T_MAX.
|
||||
Now the limit is UINTMAX_MAX (usually 2^64).
|
||||
- split can now handle --bytes=N and --lines=N with N=2^31 or more.
|
||||
|
||||
** Portability
|
||||
- `kill -t' now prints signal descriptions (rather than `?') on systems
|
||||
like Tru64 with __sys_siglist but no strsignal function.
|
||||
- stat.c now compiles on Ultrix systems
|
||||
- sleep now works on AIX systems that lack support for clock_gettime
|
||||
- rm now works around Darwin6.5's broken readdir function
|
||||
Before `rm -rf DIR' would fail to remove all files in DIR
|
||||
if there were more than 338.
|
||||
|
||||
* Major changes in release 5.0 (2003-04-02):
|
||||
- false --help now exits nonzero
|
||||
|
||||
[4.5.12]
|
||||
* printf no longer treats \x specially when POSIXLY_CORRECT is set
|
||||
* printf avoids buffer overrun with format ending in a backslash and
|
||||
* printf avoids buffer overrun with incomplete conversion specifier
|
||||
* printf accepts multiple flags in a single conversion specifier
|
||||
|
||||
[4.5.11]
|
||||
* seq no longer requires that a field width be specified
|
||||
* seq no longer fails when given a field width of `0'
|
||||
* seq now accepts ` ' and `'' as valid format flag characters
|
||||
* df now shows a HOSTNAME: prefix for each remote-mounted file system on AIX 5.1
|
||||
* portability tweaks for HP-UX, AIX 5.1, DJGPP
|
||||
|
||||
[4.5.10]
|
||||
* printf no longer segfaults for a negative field width or precision
|
||||
* shred now always enables --exact for non-regular files
|
||||
* du no longer lists hard-linked files more than once
|
||||
* du no longer dumps core on some systems due to `infinite' recursion
|
||||
via nftw's use of the buggy replacement function in getcwd.c
|
||||
* portability patches for a few vendor compilers and 64-bit systems
|
||||
* du -S *really* now works like it did before the change in 4.5.5
|
||||
|
||||
[4.5.9]
|
||||
* du no longer truncates file sizes or sums to fit in 32-bit size_t
|
||||
* work around Linux kernel bug in getcwd (fixed in 2.4.21-pre4), so that pwd
|
||||
now fails if the name of the working directory is so long that getcwd
|
||||
truncates it. Before it would print the truncated name and exit successfully.
|
||||
* `df /some/mount-point' no longer hangs on a GNU libc system when another
|
||||
hard-mounted NFS file system (preceding /some/mount-point in /proc/mounts)
|
||||
is inaccessible.
|
||||
* rm -rf now gives an accurate diagnostic when failing to remove a file
|
||||
under certain unusual conditions
|
||||
* mv and `cp --preserve=links' now preserve multiple hard links even under
|
||||
certain unusual conditions where they used to fail
|
||||
|
||||
[4.5.8]
|
||||
* du -S once again works like it did before the change in 4.5.5
|
||||
* stat accepts a new file format, %B, for the size of each block reported by %b
|
||||
* du accepts new option: --apparent-size
|
||||
* du --bytes (-b) works the same way it did in fileutils-3.16 and before
|
||||
* du reports proper sizes for directories (not zero) (broken in 4.5.6 or 4.5.7)
|
||||
* df now always displays under `Filesystem', the device file name
|
||||
corresponding to the listed mount point. Before, for a block- or character-
|
||||
special file command line argument, df would display that argument. E.g.,
|
||||
`df /dev/hda' would list `/dev/hda' as the `Filesystem', rather than say
|
||||
/dev/hda3 (the device on which `/' is mounted), as it does now.
|
||||
* test now works properly when invoked from a set user ID or set group ID
|
||||
context and when testing access to files subject to alternate protection
|
||||
mechanisms. For example, without this change, a set-UID program that invoked
|
||||
`test -w F' (to see if F is writable) could mistakenly report that it *was*
|
||||
writable, even though F was on a read-only file system, or F had an ACL
|
||||
prohibiting write access, or F was marked as immutable.
|
||||
|
||||
[4.5.7]
|
||||
* du would fail with more than one DIR argument when any but the last did not
|
||||
contain a slash (due to a bug in ftw.c)
|
||||
|
||||
[4.5.6]
|
||||
* du no longer segfaults on Solaris systems (fixed heap-corrupting bug in ftw.c)
|
||||
* du --exclude=FILE works once again (this was broken by the rewrite for 4.5.5)
|
||||
* du no longer gets a failed assertion for certain hierarchy lay-outs
|
||||
involving hard-linked directories
|
||||
* `who -r' no longer segfaults when using non-C-locale messages
|
||||
* df now displays a mount point (usually `/') for non-mounted
|
||||
character-special and block files
|
||||
|
||||
[4.5.5]
|
||||
* ls --dired produces correct byte offset for file names containing
|
||||
nonprintable characters in a multibyte locale
|
||||
* du has been rewritten to use a variant of GNU libc's ftw.c
|
||||
* du now counts the space associated with a directory's directory entry,
|
||||
even if it cannot list or chdir into that subdirectory.
|
||||
* du -S now includes the st_size of each entry corresponding to a subdirectory
|
||||
* rm on FreeBSD can once again remove directories from NFS-mounted file systems
|
||||
* ls has a new option --dereference-command-line-symlink-to-dir, which
|
||||
corresponds to the new default behavior when none of -d, -l -F, -H, -L
|
||||
has been specified.
|
||||
* ls dangling-symlink now prints `dangling-symlink'.
|
||||
Before, it would fail with `no such file or directory'.
|
||||
* ls -s symlink-to-non-dir and ls -i symlink-to-non-dir now print
|
||||
attributes of `symlink', rather than attributes of their referents.
|
||||
* Fix a bug introduced in 4.5.4 that made it so that ls --color would no
|
||||
longer highlight the names of files with the execute bit set when not
|
||||
specified on the command line.
|
||||
* shred's --zero (-z) option no longer gobbles up any following argument.
|
||||
Before, `shred --zero file' would produce `shred: missing file argument',
|
||||
and worse, `shred --zero f1 f2 ...' would appear to work, but would leave
|
||||
the first file untouched.
|
||||
* readlink: new program
|
||||
* cut: new feature: when used to select ranges of byte offsets (as opposed
|
||||
to ranges of fields) and when --output-delimiter=STRING is specified,
|
||||
output STRING between ranges of selected bytes.
|
||||
* rm -r can no longer be tricked into mistakenly reporting a cycle.
|
||||
* when rm detects a directory cycle, it no longer aborts the entire command,
|
||||
but rather merely stops processing the affected command line argument.
|
||||
|
||||
[4.5.4]
|
||||
* cp no longer fails to parse options like this: --preserve=mode,ownership
|
||||
* `ls --color -F symlink-to-dir' works properly
|
||||
* ls is much more efficient on directories with valid dirent.d_type.
|
||||
* stty supports all baud rates defined in linux-2.4.19.
|
||||
* `du symlink-to-dir/' would improperly remove the trailing slash
|
||||
* `du ""' would evoke a bounds violation.
|
||||
* In the unlikely event that running `du /' resulted in `stat ("/", ...)'
|
||||
failing, du would give a diagnostic about `' (empty string) rather than `/'.
|
||||
* printf: a hexadecimal escape sequence has at most two hex. digits, not three.
|
||||
* The following features have been added to the --block-size option
|
||||
and similar environment variables of df, du, and ls.
|
||||
- A leading "'" generates numbers with thousands separators.
|
||||
For example:
|
||||
$ ls -l --block-size="'1" file
|
||||
-rw-rw-r-- 1 eggert src 47,483,707 Sep 24 23:40 file
|
||||
- A size suffix without a leading integer generates a suffix in the output.
|
||||
For example:
|
||||
$ ls -l --block-size="K"
|
||||
-rw-rw-r-- 1 eggert src 46371K Sep 24 23:40 file
|
||||
* ls's --block-size option now affects file sizes in all cases, not
|
||||
just for --block-size=human-readable and --block-size=si. Fractional
|
||||
sizes are now always rounded up, for consistency with df and du.
|
||||
* df now displays the block size using powers of 1000 if the requested
|
||||
block size seems to be a multiple of a power of 1000.
|
||||
* nl no longer gets a segfault when run like this `yes|nl -s%n'
|
||||
|
||||
[4.5.3]
|
||||
* du --dereference-args (-D) no longer fails in certain cases
|
||||
* `ln --target-dir=DIR' no longer fails when given a single argument
|
||||
|
||||
[4.5.2]
|
||||
* `rm -i dir' (without --recursive (-r)) no longer recurses into dir
|
||||
* `tail -c N FILE' now works with files of size >= 4GB
|
||||
* `mkdir -p' can now create very deep (e.g. 40,000-component) directories
|
||||
* rmdir -p dir-with-trailing-slash/ no longer fails
|
||||
* printf now honors the `--' command line delimiter
|
||||
* od's 8-byte formats x8, o8, and u8 now work
|
||||
* tail now accepts fractional seconds for its --sleep-interval=S (-s) option
|
||||
|
||||
[4.5.1]
|
||||
* du and ls now report sizes of symbolic links (before they'd always report 0)
|
||||
* uniq now obeys the LC_COLLATE locale, as per POSIX 1003.1-2001 TC1.
|
||||
|
||||
========================================================================
|
||||
Here are the NEWS entries made from fileutils-4.1 until the
|
||||
point at which the packages merged to form the coreutils:
|
||||
|
||||
[4.1.11]
|
||||
* `rm symlink-to-unwritable' doesn't prompt [introduced in 4.1.10]
|
||||
[4.1.10]
|
||||
* rm once again gives a reasonable diagnostic when failing to remove a file
|
||||
owned by someone else in a sticky directory [introduced in 4.1.9]
|
||||
* df now rounds all quantities up, as per POSIX.
|
||||
* New ls time style: long-iso, which generates YYYY-MM-DD HH:MM.
|
||||
* Any time style can be preceded by "posix-"; this causes "ls" to
|
||||
use traditional timestamp format when in the POSIX locale.
|
||||
* The default time style is now posix-long-iso instead of posix-iso.
|
||||
Set TIME_STYLE="posix-iso" to revert to the behavior of 4.1.1 thru 4.1.9.
|
||||
* `rm dangling-symlink' doesn't prompt [introduced in 4.1.9]
|
||||
* stat: remove support for --secure/-s option and related %S and %C format specs
|
||||
* stat: rename --link/-l to --dereference/-L.
|
||||
The old options will continue to work for a while.
|
||||
[4.1.9]
|
||||
* rm can now remove very deep hierarchies, in spite of any limit on stack size
|
||||
* new programs: link, unlink, and stat
|
||||
* New ls option: --author (for the Hurd).
|
||||
* `touch -c no-such-file' no longer fails, per POSIX
|
||||
[4.1.8]
|
||||
* mv no longer mistakenly creates links to preexisting destination files
|
||||
that aren't moved
|
||||
[4.1.7]
|
||||
* rm: close a hole that would allow a running rm process to be subverted
|
||||
[4.1.6]
|
||||
* New cp option: --copy-contents.
|
||||
* cp -r is now equivalent to cp -R. Use cp -R -L --copy-contents to get the
|
||||
traditional (and rarely desirable) cp -r behavior.
|
||||
* ls now accepts --time-style=+FORMAT, where +FORMAT works like date's format
|
||||
* The obsolete usage `touch [-acm] MMDDhhmm[YY] FILE...' is no longer
|
||||
supported on systems conforming to POSIX 1003.1-2001. Use touch -t instead.
|
||||
* cp and inter-partition mv no longer give a misleading diagnostic in some
|
||||
unusual cases
|
||||
[4.1.5]
|
||||
* cp -r no longer preserves symlinks
|
||||
* The block size notation is now compatible with SI and with IEC 60027-2.
|
||||
For example, --block-size=1MB now means --block-size=1000000,
|
||||
whereas --block-size=1MiB now means --block-size=1048576.
|
||||
A missing `B' (e.g. `1M') has the same meaning as before.
|
||||
A trailing `B' now means decimal, not binary; this is a silent change.
|
||||
The nonstandard `D' suffix (e.g. `1MD') is now obsolescent.
|
||||
* -H or --si now outputs the trailing 'B', for consistency with the above.
|
||||
* Programs now output trailing 'K' (not 'k') to mean 1024, as per IEC 60027-2.
|
||||
* New df, du short option -B is short for --block-size.
|
||||
* You can omit an integer `1' before a block size suffix,
|
||||
e.g. `df -BG' is equivalent to `df -B 1G' and to `df --block-size=1G'.
|
||||
* The following options are now obsolescent, as their names are
|
||||
incompatible with IEC 60027-2:
|
||||
df, du: -m or --megabytes (use -BM or --block-size=1M)
|
||||
df, du, ls: --kilobytes (use --block-size=1K)
|
||||
[4.1.4]
|
||||
* df --local no longer lists smbfs file systems whose name starts with //
|
||||
* dd now detects the Linux/tape/lseek bug at run time and warns about it.
|
||||
[4.1.3]
|
||||
* ls -R once again outputs a blank line between per-directory groups of files.
|
||||
This was broken by the cycle-detection change in 4.1.1.
|
||||
* dd once again uses `lseek' on character devices like /dev/mem and /dev/kmem.
|
||||
On systems with the linux kernel (at least up to 2.4.16), dd must still
|
||||
resort to emulating `skip=N' behavior using reads on tape devices, because
|
||||
lseek has no effect, yet appears to succeed. This may be a kernel bug.
|
||||
[4.1.2]
|
||||
* cp no longer fails when two or more source files are the same;
|
||||
now it just gives a warning and doesn't copy the file the second time.
|
||||
E.g., cp a a d/ produces this:
|
||||
cp: warning: source file `a' specified more than once
|
||||
* chmod would set the wrong bit when given symbolic mode strings like
|
||||
these: g=o, o=g, o=u. E.g., `chmod a=,o=w,ug=o f' would give a mode
|
||||
of --w-r---w- rather than --w--w--w-.
|
||||
[4.1.1]
|
||||
* mv (likewise for cp), now fails rather than silently clobbering one of
|
||||
the source files in the following example:
|
||||
rm -rf a b c; mkdir a b c; touch a/f b/f; mv a/f b/f c
|
||||
* ls -R detects directory cycles, per POSIX. It warns and doesn't infloop.
|
||||
* cp's -P option now means the same as --no-dereference, per POSIX.
|
||||
Use --parents to get the old meaning.
|
||||
* When copying with the -H and -L options, cp can preserve logical
|
||||
links between source files with --preserve=links
|
||||
* cp accepts new options:
|
||||
--preserve[={mode,ownership,timestamps,links,all}]
|
||||
--no-preserve={mode,ownership,timestamps,links,all}
|
||||
* cp's -p and --preserve options remain unchanged and are equivalent
|
||||
to `--preserve=mode,ownership,timestamps'
|
||||
* mv and cp accept a new option: --reply={yes,no,query}; provides a consistent
|
||||
mechanism to control whether one is prompted about certain existing
|
||||
destination files. Note that cp's and mv's -f options don't have the
|
||||
same meaning: cp's -f option no longer merely turns off `-i'.
|
||||
* remove portability limitations (e.g., PATH_MAX on the Hurd, fixes for
|
||||
64-bit systems)
|
||||
* mv now prompts before overwriting an existing, unwritable destination file
|
||||
when stdin is a tty, unless --force (-f) is specified, as per POSIX.
|
||||
* mv: fix the bug whereby `mv -uf source dest' would delete source,
|
||||
even though it's older than dest.
|
||||
* chown's --from=CURRENT_OWNER:CURRENT_GROUP option now works
|
||||
* cp now ensures that the set-user-ID and set-group-ID bits are cleared for
|
||||
the destination file when when copying and not preserving permissions.
|
||||
* `ln -f --backup k k' gives a clearer diagnostic
|
||||
* ls no longer truncates user names or group names that are longer
|
||||
than 8 characters.
|
||||
* ls's new --dereference-command-line option causes it to dereference
|
||||
symbolic links on the command-line only. It is the default unless
|
||||
one of the -d, -F, or -l options are given.
|
||||
* ls -H now means the same as ls --dereference-command-line, as per POSIX.
|
||||
* ls -g now acts like ls -l, except it does not display owner, as per POSIX.
|
||||
* ls -n now implies -l, as per POSIX.
|
||||
* ls can now display dates and times in one of four time styles:
|
||||
|
||||
- The `full-iso' time style gives full ISO-style time stamps like
|
||||
`2001-05-14 23:45:56.477817180 -0700'.
|
||||
- The 'iso' time style gives ISO-style time stamps like '2001-05-14 '
|
||||
and '05-14 23:45'.
|
||||
- The 'locale' time style gives locale-dependent time stamps like
|
||||
'touko 14 2001' and 'touko 14 23:45' (in a Finnish locale).
|
||||
- The 'posix-iso' time style gives traditional POSIX-locale
|
||||
time stamps like 'May 14 2001' and 'May 14 23:45' unless the user
|
||||
specifies a non-POSIX locale, in which case it uses ISO-style dates.
|
||||
This is the default.
|
||||
|
||||
You can specify a time style with an option like --time-style='iso'
|
||||
or with an environment variable like TIME_STYLE='iso'. GNU Emacs 21
|
||||
and later can parse ISO dates, but older Emacs versions cannot, so
|
||||
if you are using an older version of Emacs outside the default POSIX
|
||||
locale, you may need to set TIME_STYLE="locale".
|
||||
|
||||
* --full-time is now an alias for "-l --time-style=full-iso".
|
||||
|
||||
|
||||
========================================================================
|
||||
Here are the NEWS entries made from sh-utils-2.0 until the
|
||||
point at which the packages merged to form the coreutils:
|
||||
|
||||
[2.0.15]
|
||||
* date no longer accepts e.g., September 31 in the MMDDhhmm syntax
|
||||
* fix a bug in this package's .m4 files and in configure.ac
|
||||
[2.0.14]
|
||||
* nohup's behavior is changed as follows, to conform to POSIX 1003.1-2001:
|
||||
- nohup no longer adjusts scheduling priority; use "nice" for that.
|
||||
- nohup now redirects stderr to stdout, if stderr is not a terminal.
|
||||
- nohup exit status is now 126 if command was found but not invoked,
|
||||
127 if nohup failed or if command was not found.
|
||||
[2.0.13]
|
||||
* uname and uptime work better on *BSD systems
|
||||
* pathchk now exits nonzero for a path with a directory component
|
||||
that specifies a non-directory
|
||||
[2.0.12]
|
||||
* kill: new program
|
||||
* who accepts new options: --all (-a), --boot (-b), --dead (-d), --login,
|
||||
--process (-p), --runlevel (-r), --short (-s), --time (-t), --users (-u).
|
||||
The -u option now produces POSIX-specified results and is the same as
|
||||
the long option `--users'. --idle is no longer the same as -u.
|
||||
* The following changes apply on systems conforming to POSIX 1003.1-2001,
|
||||
and are required by the new POSIX standard:
|
||||
- `date -I' is no longer supported. Instead, use `date --iso-8601'.
|
||||
- `nice -NUM' is no longer supported. Instead, use `nice -n NUM'.
|
||||
* New 'uname' options -i or --hardware-platform, and -o or --operating-system.
|
||||
'uname -a' now outputs -i and -o information at the end.
|
||||
New uname option --kernel-version is an alias for -v.
|
||||
Uname option --release has been renamed to --kernel-release,
|
||||
and --sysname has been renamed to --kernel-name;
|
||||
the old options will work for a while, but are no longer documented.
|
||||
* 'expr' now uses the LC_COLLATE locale for string comparison, as per POSIX.
|
||||
* 'expr' now requires '+' rather than 'quote' to quote tokens;
|
||||
this removes an incompatibility with POSIX.
|
||||
* date -d 'last friday' would print a date/time that was one hour off
|
||||
(e.g., 23:00 on *thursday* rather than 00:00 of the preceding friday)
|
||||
when run such that the current time and the target date/time fall on
|
||||
opposite sides of a daylight savings time transition.
|
||||
This problem arose only with relative date strings like `last monday'.
|
||||
It was not a problem with strings that include absolute dates.
|
||||
* factor is twice as fast, for large numbers
|
||||
[2.0.11]
|
||||
* setting the date now works properly, even when using -u
|
||||
* `date -f - < /dev/null' no longer dumps core
|
||||
* some DOS/Windows portability changes
|
||||
[2.0j]
|
||||
* `date -d DATE' now parses certain relative DATEs correctly
|
||||
[2.0i]
|
||||
* fixed a bug introduced in 2.0h that made many programs fail with a
|
||||
`write error' when invoked with the --version option
|
||||
[2.0h]
|
||||
* all programs fail when printing --help or --version output to a full device
|
||||
* printf exits nonzero upon write failure
|
||||
* yes now detects and terminates upon write failure
|
||||
* date --rfc-822 now always emits day and month names from the `C' locale
|
||||
* portability tweaks for Solaris8, Ultrix, and DOS
|
||||
[2.0g]
|
||||
* date now handles two-digit years with leading zeros correctly.
|
||||
* printf interprets unicode, \uNNNN \UNNNNNNNN, on systems with the
|
||||
required support; from Bruno Haible.
|
||||
* stty's rprnt attribute now works on HPUX 10.20
|
||||
* seq's --equal-width option works more portably
|
||||
[2.0f]
|
||||
* fix build problems with ut_name vs. ut_user
|
||||
[2.0e]
|
||||
* stty: fix long-standing bug that caused test failures on at least HPUX
|
||||
systems when COLUMNS was set to zero
|
||||
* still more portability fixes
|
||||
* unified lib/: now that directory and most of the configuration framework
|
||||
is common between fileutils, textutils, and sh-utils
|
||||
[2.0d]
|
||||
* fix portability problem with sleep vs lib/strtod.c's requirement for -lm
|
||||
[2.0c]
|
||||
* fix portability problems with nanosleep.c and with the new code in sleep.c
|
||||
[2.0b]
|
||||
* Regenerate lib/Makefile.in so that nanosleep.c is distributed.
|
||||
[2.0a]
|
||||
* sleep accepts floating point arguments on command line
|
||||
* sleep's clock continues counting down when sleep is suspended
|
||||
* when a suspended sleep process is resumed, it continues sleeping if
|
||||
there is any time remaining
|
||||
* who once again prints whatever host information it has, even without --lookup
|
||||
|
||||
========================================================================
|
||||
For older NEWS entries for the fileutils, textutils, and sh-utils
|
||||
packages, see ./old/*/NEWS.
|
||||
|
||||
This package began as the union of the following:
|
||||
textutils-2.1, fileutils-4.1.11, sh-utils-2.0.15.
|
||||
|
|
@ -1,147 +0,0 @@
|
|||
These are the GNU core utilities. This package is the union of
|
||||
the GNU fileutils, sh-utils, and textutils packages.
|
||||
|
||||
Most of these programs have significant advantages over their Unix
|
||||
counterparts, such as greater speed, additional options, and fewer
|
||||
arbitrary limits.
|
||||
|
||||
The programs that can be built with this package are:
|
||||
|
||||
[ basename cat chgrp chmod chown chroot cksum comm cp csplit cut date dd
|
||||
df dir dircolors dirname du echo env expand expr factor false fmt fold
|
||||
ginstall groups head hostid hostname id join kill link ln logname ls
|
||||
md5sum mkdir mkfifo mknod mv nice nl nohup od paste pathchk pinky pr
|
||||
printenv printf ptx pwd readlink rm rmdir seq sha1sum shred sleep sort
|
||||
split stat stty su sum sync tac tail tee test touch tr true tsort tty
|
||||
uname unexpand uniq unlink uptime users vdir wc who whoami yes
|
||||
|
||||
See the file NEWS for a list of major changes in the current release.
|
||||
|
||||
See the file INSTALL for compilation and installation instructions.
|
||||
|
||||
These programs are intended to conform to POSIX (with BSD and other
|
||||
extensions), like the rest of the GNU system. By default they conform
|
||||
to older POSIX (1003.2-1992), and therefore support obsolete usages
|
||||
like "head -10" and "chown owner.group file". This default is
|
||||
overridden at build-time by the value of <unistd.h>'s _POSIX2_VERSION
|
||||
macro, and this in turn can be overridden at runtime as described in
|
||||
the documentation under "Standards conformance".
|
||||
|
||||
The ls, dir, and vdir commands are all separate executables instead of
|
||||
one program that checks argv[0] because people often rename these
|
||||
programs to things like gls, gnuls, l, etc. Renaming a program
|
||||
file shouldn't affect how it operates, so that people can get the
|
||||
behavior they want with whatever name they want.
|
||||
|
||||
Special thanks to Paul Eggert, Brian Matthews, Bruce Evans, Karl Berry,
|
||||
Kaveh Ghazi, and François Pinard for help with debugging and porting
|
||||
these programs. Many thanks to all of the people who have taken the
|
||||
time to submit problem reports and fixes. All contributed changes are
|
||||
attributed in the ChangeLog file.
|
||||
|
||||
And thanks to the following people who have provided accounts for
|
||||
portability testing on many different types of systems: Bob Proulx,
|
||||
Christian Robert, François Pinard, Greg McGary, Harlan Stenn,
|
||||
Joel N. Weber, Mark D. Roth, Matt Schalit, Nelson H. F. Beebe,
|
||||
Réjean Payette, Sam Tardieu.
|
||||
|
||||
Thanks to Michael Stone for inflicting test releases of the fileutils
|
||||
on Debian's unstable distribution, and to all the kind folks who used
|
||||
that distribution and found and reported bugs.
|
||||
|
||||
Note that each man page is now automatically generated from a template
|
||||
and from the corresponding --help usage message. Patches to the template
|
||||
files (man/*.x) are welcome. However, the authoritative documentation
|
||||
is in texinfo form in the doc directory.
|
||||
|
||||
If you run the tests on a SunOS4.1.4 system, expect the ctime-part of
|
||||
the ls `time-1' test to fail. I believe that is due to a bug in the
|
||||
way Sun implemented link(2) and chmod(2).
|
||||
|
||||
***************************************
|
||||
Last-minute notes, before coreutils-5.0
|
||||
---------------------------------------
|
||||
|
||||
A known problem exists when compiling on HPUX on both hppa and ia64
|
||||
in 64-bit mode (i.e. +DD64) on all known HPUX 11.x versions. This
|
||||
is not due to a bug in the package but instead due to a bug in the
|
||||
system header file which breaks things in 64-bit mode. The default
|
||||
compilation mode is 32-bit and the software compiles fine using the
|
||||
default mode. To build this software in 64-bit mode you will need
|
||||
to fix the system /usr/include/inttypes.h header file. After
|
||||
correcting that file the software also compiles fine in 64-bit mode.
|
||||
Here is one possible patch to correct the problem.
|
||||
|
||||
--- /usr/include/inttypes.h.orig Thu May 30 01:00:00 1996
|
||||
+++ /usr/include/inttypes.h Sun Mar 23 00:20:36 2003
|
||||
@@ -489 +489 @@
|
||||
-#ifndef __STDC_32_MODE__
|
||||
+#ifndef __LP64__
|
||||
|
||||
If you run the tests as root, note that a few of them create files
|
||||
and/or run programs as a non-root user, `nobody' by default.
|
||||
If you want to use some other non-root username, specify it via
|
||||
the NON_ROOT_USERNAME environment variable. Depending on the
|
||||
permissions with which the working directories have been created,
|
||||
using `nobody' may fail, because that user won't have the required
|
||||
read and write access to the build and test directories.
|
||||
I find that it is best to unpack and build as a non-privileged
|
||||
user, and then to run the following command as that user in order
|
||||
to run the privilege-requiring tests:
|
||||
|
||||
sudo env NON_ROOT_USERNAME=$USER make check
|
||||
|
||||
If you can run the tests as root, please do so and report any
|
||||
problems. We get much less test coverage in that mode, and it's
|
||||
arguably more important that these tools work well when run by
|
||||
root than when run by less privileged users.
|
||||
|
||||
***************************************
|
||||
|
||||
There are pretty many tests, but nowhere near as many as we need.
|
||||
Additions and corrections are very welcome.
|
||||
|
||||
If you see a problem that you've already reported, feel free to re-report
|
||||
it -- it won't bother me to get a reminder. Besides, the more messages I
|
||||
get regarding a particular problem the sooner it'll be fixed -- usually.
|
||||
If you sent a complete patch and, after a couple weeks you haven't
|
||||
received any acknowledgement, please ping us. A complete patch includes
|
||||
a well-written ChangeLog entry, unified (diff -u format) diffs relative
|
||||
to the most recent test release (or, better, relative to the latest
|
||||
sources in the CVS repository), an explanation for why the patch is
|
||||
necessary or useful, and if at all possible, enough information to
|
||||
reproduce whatever problem prompted it. Plus, you'll earn lots of
|
||||
karma if you include a test case to exercise any bug(s) you fix.
|
||||
Instructions for checking out the latest source via CVS are here:
|
||||
|
||||
http://savannah.gnu.org/cvs/?group=coreutils
|
||||
|
||||
|
||||
If your patch adds a new feature, please try to get some sort of consensus
|
||||
that it is a worthwhile change. One way to do that is to send mail to
|
||||
bug-coreutils@gnu.org including as much description and justification
|
||||
as you can. Based on the feedback that generates, you may be able to
|
||||
convince us that it's worth adding.
|
||||
|
||||
|
||||
WARNING: If you modify files like configure.in, m4/*.m4, aclocal.m4,
|
||||
or any Makefile.am, then don't be surprised if what gets regenerated no
|
||||
longer works. To make things work, you'll have to be using appropriate
|
||||
versions of automake and autoconf. As for what versions are `appropriate',
|
||||
use the versions of
|
||||
|
||||
* autoconf specified via AC_PREREQ in m4/jm-macros.m4
|
||||
* automake specified via AM_INIT_AUTOMAKE in configure.ac
|
||||
|
||||
Usually it's fine to use versions that are newer than those specified.
|
||||
|
||||
These programs all recognize the `--version' option. When reporting
|
||||
bugs, please include in the subject line both the package name/version
|
||||
and the name of the program for which you found a problem.
|
||||
|
||||
For general documentation on the coding and usage standards
|
||||
this distribution follows, see the GNU Coding Standards,
|
||||
http://www.gnu.org/prep/standards_toc.html.
|
||||
|
||||
Mail suggestions and bug reports for these programs to
|
||||
the address on the last line of --help output.
|
||||
|
|
@ -1,463 +0,0 @@
|
|||
These people have contributed to the GNU coreutils (formerly, the fileutils,
|
||||
textutils, and/or sh-utils packages). Some have reported problems, others
|
||||
have contributed improvements to the documentation, actual code, and even
|
||||
complete programs. Those contributions are described in the ChangeLog
|
||||
files. If your name has been left out, if you'd rather not be listed,
|
||||
or if you'd prefer a different address be used, please send a note to
|
||||
the bug-report mailing list (as seen on last line of e.g., cp --help).
|
||||
|
||||
??? kytek@cybercomm.net
|
||||
A Costa agcosta@gis.net
|
||||
Achim Blumensath blume@corona.oche.de
|
||||
Adam Klein aklein@debian.org
|
||||
Akim Demaille demaille@inf.enst.fr
|
||||
Alain Magloire alain@qnx.com
|
||||
Alan Iwi iwi@atm.ox.ac.uk
|
||||
Albert Chin-A-Young china@thewrittenword.com
|
||||
Albert Hopkins ahopkins@dynacare.com
|
||||
Alberto Accomazzi alberto@cfa0.harvard.edu
|
||||
aldomel aldomel@ix.netcom.com
|
||||
Alen Muzinic zveki@fly.cc.fer.hr
|
||||
Alexandre Duret-Lutz duret_g@epita.fr
|
||||
Alexey Solovyov alekso@math.uu.se
|
||||
Alexey Vyskubov alexey@pippuri.mawhrin.net
|
||||
Alfred M. Szmidt ams@kemisten.nu
|
||||
Andi Kleen freitag@alancoxonachip.com
|
||||
Andre Novaes Cunha Andre.Cunha@br.global-one.net
|
||||
Andreas Gruenbacher ag@bestbits.at
|
||||
Andreas Jaeger jaeger@gnu.org
|
||||
Andreas Luik luik@isa.de
|
||||
Andreas Schwab schwab@suse.de
|
||||
Andreas Stolcke stolcke@ICSI.Berkeley.EDU
|
||||
Andrei Gaponenko andr@triumf.ca
|
||||
Andres Soolo andres@soolo.matti.ee
|
||||
Andrew Burgess aab@cichlid.com
|
||||
Andrew Dalke dalke@bioreason.com
|
||||
Andrew Fabbro andrew@fabbro.org
|
||||
Andrew Pham andpha@us.ibm.com
|
||||
Andrew Tridgell tridge@samba.org
|
||||
Andrey Borzenkov arvidjaar@mail.ru
|
||||
Andries Brouwer Andries.Brouwer@cwi.nl
|
||||
Andy Longton alongton@metamark.com
|
||||
Anthony Thyssen anthony@griffith.edu.au
|
||||
Antonio Rendas ajrendas@yahoo.com
|
||||
Ariel Faigon ariel@cthulhu.engr.sgi.com
|
||||
Arne H. Juul arnej@solan.unit.no
|
||||
Arne Henrik Juul arnej@imf.unit.no
|
||||
Arnold Robbins arnold@skeeve.com
|
||||
Arthur Pool pool@commerce.uq.edu.au
|
||||
Arun Sharma arun.sharma@intel.com
|
||||
Arvind Autar Autar022@planet.nl
|
||||
Augey Mikus mikus@dqc.org
|
||||
Austin Donnelly Austin.Donnelly@cl.cam.ac.uk
|
||||
Axel Kittenberger Anshil@gmx.net
|
||||
Bauke Jan Douma bjdouma@xs4all.nl
|
||||
Ben Elliston bje@air.net.au
|
||||
Ben Harris bjh21@netbsd.org
|
||||
Benjamin Cutler cutlerbc@simla.colostate.edu
|
||||
Bengt Martensson bengt@mathematik.uni-Bremen.de
|
||||
Bernard Giroud bernard.giroud@creditlyonnais.ch
|
||||
Bernd Leibing bernd.leibing@rz.uni-ulm.de
|
||||
Bernd Melchers melchers@cis.fu-berlin.de
|
||||
Bernhard Baehr bernhard.baehr@gmx.de
|
||||
Bernhard Gabler bernhard@uni-koblenz.de
|
||||
Bernhard Rosenkraenzer bero@redhat.de
|
||||
Bert Deknuydt Bert.Deknuydt@esat.kuleuven.ac.be
|
||||
Bill Peters peters@gaffel.as.arizona.edu
|
||||
Bjorn Helgaas helgaas@rsn.hp.com
|
||||
Bob McCracken kerouac@ravenet.com
|
||||
Bob Proulx rwp@fc.hp.com
|
||||
Branden Robinson branden@necrotic.deadbeast.net
|
||||
Brendan O'Dea bod@compusol.com.au
|
||||
Brian Kimball bfk@footbag.org
|
||||
Brian Youmans 3diff@gnu.org
|
||||
Bruce Korb bkorb@veritas.com
|
||||
Bruce Robertson brucer@theodolite.dyndns.org
|
||||
Bruno Haible haible@clisp.cons.org
|
||||
Carl Johnson carlj@cjlinux.home.org
|
||||
Carl Lowenstein cdl@mpl.UCSD.EDU
|
||||
Carlos Canau Carlos.Canau@relay.puug.pt
|
||||
Charles Karney karney@pppl.gov
|
||||
Charles Randall crandall@matchlogic.com
|
||||
Chip Salzenberg chip@valinux.com
|
||||
Chris Faylor cgf@cygnus.com
|
||||
Chris J. Bednar cjb@AdvancedDataSolutions.com
|
||||
Chris Lesniewski ctl@mit.edu
|
||||
Chris Sylvain csylvain@umm.edu
|
||||
Chris Yeo cyeo@biking.org
|
||||
Christi Alice Scarborough christi@chiark.greenend.org.uk
|
||||
Christian Harkort christian.harkort@web.de
|
||||
Christian Krackowizer ckrackowiz@std.schuler-ag.com
|
||||
Christian Rose menthos@menthos.com
|
||||
Christian von Roques roques@pond.sub.org
|
||||
Chuck Hedrick hedrick@klinzhai.rutgers.edu
|
||||
Clark Morgan cmorgan@aracnet.com
|
||||
Clement Wang clem.wang@overture.com
|
||||
Colin Plumb colin@nyx.net
|
||||
Colin Watson cjw44@riva.ucam.org
|
||||
Collin Rogowski collin@rogowski.de
|
||||
Cray-Cyber Project http://www.cray-cyber.org
|
||||
Dale Scheetz dwarf@polaris.net
|
||||
Dan Hagerty hag@gnu.ai.it.edu
|
||||
Dan Jacobson http://www.geocities.com/jidani
|
||||
Dan Pascu dan@services.iiruc.ro
|
||||
Daniel Bergstrom noa@melody.se
|
||||
Dániel Varga danielv@axelero.hu
|
||||
Danny Levinson danny.levinson@overture.com
|
||||
Darren Salt ds@youmustbejoking.demon.co.uk
|
||||
Dave Beckett dajobe@dajobe.org
|
||||
David Dyck dcd@tc.fluke.COM
|
||||
David Eisner cradle@umd.edu
|
||||
David Flynn dav@chess.plus.com
|
||||
David Godfrey dave@delta.demon.co.uk
|
||||
David Luyer david_luyer@pacific.net.au
|
||||
David Malone dwmalone@cnri.dit.ie
|
||||
Deepak Goel deego@gnufans.org
|
||||
Dennis Henriksen opus@flamingo.osrl.dk
|
||||
Dennis Smit ds@nerds-incorporated.org
|
||||
Derek Clegg dclegg@next.com
|
||||
Dick Streefland dick_streefland@tasking.com
|
||||
Dirk Lattermann dlatt@t-online.de
|
||||
Dirk-Jan Faber djfaber@snow.nl
|
||||
Dmitry Rutsky rutsky@school.ioffe.rssi.ru
|
||||
Dmitry V. Levin ldv@altlinux.org
|
||||
Don Parsons dparsons@synapse.kent.edu
|
||||
Donni Erpel donald@appc11.gsi.de
|
||||
Doug Coleman coleman@iarc1.ece.utexas.edu
|
||||
Doug McLaren dougmc@comco.com
|
||||
Dragos Harabor dharabor@us.oracle.com
|
||||
Duncan Roe duncanr@optimation.com.au
|
||||
Ed Avis ed@membled.com
|
||||
Edzer Pebesma Edzer.Pebesma@rivm.nl
|
||||
Eirik Fuller eirik@hackrat.com
|
||||
Eivind eivindt@multinet.no
|
||||
Eli Zaretskii eliz@is.elta.co.il
|
||||
Emile LeBlanc leblanc@math.toronto.edu
|
||||
Eric Backus ericb@lsid.hp.com
|
||||
Eric G. Miller egm2@jps.net
|
||||
Eric Pemente pemente@northpark.edu
|
||||
Eric S. Raymond esr@snark.thyrsus.com
|
||||
Erik Bennett bennett@cvo.oneworld.com
|
||||
Erik Corry erik@kroete2.freinet.de
|
||||
Felix Lee flee@teleport.com
|
||||
Ferdinand fw@scenic.mine.nu
|
||||
Fletcher Mattox fletcher@cs.utexas.edu
|
||||
Florin Iucha fiucha@hsys.mic.ro
|
||||
François Pinard pinard@iro.umontreal.ca
|
||||
Frank Adler fadler@allesklar.de
|
||||
Frank T Lofaro ftlofaro@snooks.Egr.UNLV.EDU
|
||||
Fred Fish fnf@ninemoons.com
|
||||
Frédéric L. W. Meunier 0@pervalidus.net
|
||||
Frederik Eaton frederik@caltech.edu
|
||||
Gabor Z. Papp gzp@gzp.org.hu
|
||||
Gaël Quéri gqueri@mail.dotcom.fr
|
||||
Galen Hazelwood galenh@micron.net
|
||||
Gary Anderson ganderson@clark.net
|
||||
Gary V. Vaughan gary@gnu.org
|
||||
Gaute Hvoslef Kvalnes gaute@verdsveven.com
|
||||
Geoff Collyer geoff at collyer.net
|
||||
Geoff Kuenning geoff@cs.hmc.edu
|
||||
Geoff Odhner geoff@franklin.com
|
||||
Geoff Whale geoffw@cse.unsw.EDU.AU
|
||||
Gerhard Poul gpoul@gnu.org
|
||||
Germano Leichsenring germano@jedi.cs.kobe-u.ac.jp
|
||||
Göran Uddeborg goeran@uddeborg.pp.se
|
||||
GOTO Masanori gotom@debian.or.jp
|
||||
Greg Louis glouis@dynamicro.on.ca
|
||||
Greg McGary gkm@gnu.org
|
||||
Greg Schafer gschafer@zip.com.au
|
||||
Greg Troxel gdt@bbn.com
|
||||
Greg Wooledge gawooledge@sherwin.com
|
||||
Gregory Leblanc gleblanc@cu-portland.edu
|
||||
Guido Leenders guido.leenders@invantive.com
|
||||
H. J. Lu hjl@valinux.com
|
||||
Hans Ginzel hans@matfyz.cz
|
||||
Hans Lermen lermen@fgan.de
|
||||
Hans Verkuil hans@wyst.hobby.nl
|
||||
Harry Liu rliu@lek.ugcs.caltech.edu
|
||||
Harti Brandt brandt@fokus.fraunhofer.de
|
||||
Herbert Xu herbert@gondor.apana.org.au
|
||||
Holger Berger hberger@ess.nec.de
|
||||
Hon-Yin Kok hkok@yoda.unl.edu
|
||||
Hugh Daniel hugh@xanadu.com
|
||||
Ian Bruce ian.bruce@myrealbox.com
|
||||
Ian Jackson ijackson@chiark.greenend.org.uk
|
||||
Ian Lance Taylor ian@cygnus.com
|
||||
Ian Turner vectro@pipeline.com
|
||||
Iida Yosiaki iida@gnu.org
|
||||
Ingo Saitz ingo@debian.org
|
||||
Ivo Timmermans ivo@debian.org
|
||||
James james@albion.glarp.com
|
||||
James Antill jmanti%essex.ac.uk@seralph21.essex.ac.uk
|
||||
James Sneeringer jvs@ocslink.com
|
||||
James Tanis jtt@soscorp.com
|
||||
James Youngman james+usenet@free-lunch.demon.co.uk
|
||||
Jamie Lokier jamie@imbolc.ucc.ie
|
||||
Jan Fedak J.Fedak@sh.cvut.cz
|
||||
Jan Nieuwenhuizen janneke@gnu.org
|
||||
Janos Farkas chexum@shadow.banki.hu
|
||||
Jarkko Hietaniemi jhi@epsilon.hut.fi
|
||||
Jean Charles Delepine delepine@u-picardie.fr
|
||||
Jeff Moore jbm@mordor.com
|
||||
Jeff Sheinberg jeff@bsrd.net
|
||||
Jens Elkner elkner@imsgroup.de
|
||||
Jens Schmidt jms@jsds.hamburg.com
|
||||
Jerome Abela abela@hsc.fr
|
||||
Jérôme Zago bug-coreutils-ml@agt-the-walker.net
|
||||
Jesse Kornblum kornblum@usna.edu
|
||||
Jesse Thilo jgt2@eecs.lehigh.edu
|
||||
Jie Xu xuj@iag.net
|
||||
Jim Blandy jimb@cyclic.com
|
||||
Jim Dennis jimd@starshine.org
|
||||
Joakim Rosqvist dvljrt@cs.umu.se
|
||||
Jochen Hein jochen@jochen.org
|
||||
Joe Orton joe@manyfish.co.uk
|
||||
Johan Danielsson joda@pdc.kth.se
|
||||
John Bley jbb6@acpub.duke.edu
|
||||
John David Anglin dave.anglin@nrc.ca
|
||||
John Gatewood Ham zappaman@alphabox.compsci.buu.ac.th
|
||||
John Gotts jgotts@umich.edu
|
||||
John Kendall kendall@capps.com
|
||||
John Kodis kodis@acm.org
|
||||
John Murphy jam@philabs.research.philips.com
|
||||
John Roll john@panic.harvard.edu
|
||||
John Salmon johns@mullet.anu.edu.au
|
||||
John Summerfield summer@OS2.ami.com.au
|
||||
Jon Peatfield J.S.Peatfield@damtp.cam.ac.uk
|
||||
Joost van Baal joostvb@xs4all.nl
|
||||
Jorge Stolfi stolfi@ic.unicamp.br
|
||||
Joseph S. Myers jsm28@cam.ac.uk
|
||||
Juan F. Codagnone juam@arnet.com.ar
|
||||
Jungshik Shin jshin@pantheon.yale.edu
|
||||
Jürgen Fluk louis@dachau.marco.de
|
||||
Jurriaan thunder7@xs4all.nl
|
||||
jvogel jvogel@linkny.com
|
||||
Kai Henningsen kai@debian.org
|
||||
Kai-Uwe Rommel rommel@informatik.tu-muenchen.de
|
||||
Kalle Olavi Niemitalo kon@iki.fi
|
||||
Kamal Paul Nigam Kamal_Paul_Nigam@gs35.sp.cs.cmu.edu
|
||||
Karl Eichwalder keichwa@gmx.net
|
||||
Karl Heuer kwzh@gnu.org
|
||||
Karl-Michael Schneider schneide@phil.uni-passau.de
|
||||
Karsten Thygesen karthy@kom.auc.dk
|
||||
Kaveh R. Ghazi ghazi@caip.rutgers.edu
|
||||
Keith M. Briggs keith.briggs@bt.com
|
||||
Keith Owens kaos@audio.apana.org.au
|
||||
Keith Thompson kst@cts.com
|
||||
Ken Pizzini kenp@halcyon.com
|
||||
Kristin E Thomas kristint@us.ibm.com
|
||||
Kjetil Torgrim Homme kjetilho@ifi.uio.no
|
||||
Kristoffer Rose kris@diku.dk
|
||||
Larry McVoy lm@sgi.com
|
||||
Lars Hecking lhecking@nmrc.ucc.ie
|
||||
Leah Q eequor@earthlink.net
|
||||
Lehti Rami rammer@cs.tut.fi
|
||||
Leonard N. Zubkoff lnz@dandelion.com
|
||||
Leonardo Milano lmilano@udel.edu
|
||||
Lorne Baker lbaker@nitro.avint.net
|
||||
Luke Hassell lukehassell@yahoo.com
|
||||
M. P. Suzuki mpsuzuki@hiroshima-u.ac.jp
|
||||
Maciej Kwapulinski pikpok@univ.gda.pl
|
||||
Manas Garg manas@cygsoft.com
|
||||
Manfred Hollstein manfred@s-direktnet.de
|
||||
Marc Boucher marc@mbsi.ca
|
||||
Marc Haber mh+debian-bugs@zugschlus.de
|
||||
Marc Olzheim marcolz@stack.nl
|
||||
Marco Franzen Marco.Franzen@Thyron.com
|
||||
Marcus Brinkmann http://www.marcus-brinkmann.de
|
||||
Marcus Daniels marcus@ee.pdx.edu
|
||||
Mark A. Thomas thommark@access.digex.net
|
||||
Mark Conty Mark_Conty@cargill.com
|
||||
Mark D. Roth roth@uiuc.edu
|
||||
Mark Funkenhauser mfunkenhauser@rogers.com
|
||||
Mark Harris mark@monitor.designacc.com
|
||||
Mark Hewitt mhewitt@armature.com
|
||||
Mark Hounschell markh@compro.net
|
||||
Mark Hubbart discord@mac.com
|
||||
Mark Kettenis kettenis@phys.uva.nl
|
||||
Mark Nudelman marknu@flash.net
|
||||
Mark W. Eichin eichin@cygnus.com
|
||||
Markus Demleitner msdemlei@auriga.ari.uni-heidelberg.de
|
||||
Martin martin@dresden.nacamar.de
|
||||
Martin Buck martin.buck@ascom.ch
|
||||
Martin Gallant martyg@goodbit.net
|
||||
Martin Hippe martin.hippe@schlund.de
|
||||
Martin Michlmayr tbm@cyrius.com
|
||||
Martin Mitchell martin@debian.org
|
||||
Martin P.J. Zinser zinser@decus.de
|
||||
Marty Leisner leisner@sdsp.mc.xerox.com
|
||||
Masami Takikawa takikawm@CS.ORST.EDU
|
||||
Mate Wierdl mw@moni.msci.memphis.edu
|
||||
Matej Vela mvela@public.srce.hr
|
||||
Matt Perry matt@primefactor.com
|
||||
Matt Schalit mschalit@pacbell.net
|
||||
Matt Swift swift@alum.mit.edu
|
||||
Matthew Arnison maffew@cat.org.au
|
||||
Matthew Braun matthew@ans.net
|
||||
Matthew Clarke Matthew_Clarke@mindlink.bc.ca
|
||||
Matthew S. Levine mslevine@theory.lcs.mit.edu
|
||||
Matthew Smith matts@bluesguitar.org
|
||||
Matthew Swift swift@alum.mit.edu
|
||||
Matthias Urlichs smurf@noris.de
|
||||
Matti Aarnio matti.aarnio@zmailer.org
|
||||
Mattias Wadenstein maswan@acc.umu.se
|
||||
Meelis Roos mroos@tartu.cyber.ee
|
||||
Michael michael@aplatform.com
|
||||
Michael ??? michael@roka.net
|
||||
Michael Bacarella mbac@netgraft.com>
|
||||
Michael Deutschmann michael@talamasca.ocis.net
|
||||
Michael Elizabeth Chastain mec.gnu@mindspring.com
|
||||
Michael Gaughen mgaughen@polyserve.com
|
||||
Michael Hasselberg mikelh@zonta.ping.de
|
||||
Michael Hohn hohn@math.utah.edu
|
||||
Michael J. Croghan mcroghan@usatoday.com
|
||||
Michael McFarland sidlon@yahoo.com
|
||||
Michael Piefel piefel@informatik.hu-berlin.de
|
||||
Michael Steffens michael.steffens@s.netic.de
|
||||
Michael Stone mstone@debian.org
|
||||
Michael Stutz stutz@dsl.org
|
||||
Michael van Elst mlelstv@dev.de.cw.net
|
||||
Michael Veksler mveksler@techunix.technion.ac.il
|
||||
Michail Litvak mci@owl.openwall.com
|
||||
Michal Politowski mpol@charybda.icm.edu.pl
|
||||
Michal Svec msvec@suse.cz
|
||||
Michel Robitaille robitail@IRO.UMontreal.CA
|
||||
Michiel Bacchiani bacchian@raven.bu.edu
|
||||
Mike Castle dalgoda@ix.netcom.com
|
||||
Mike Coleman mkc@mathdogs.com
|
||||
Mike Jetzer mjetzer@mke.catalystwms.com
|
||||
Mikko Tuumanen m@sorvankyla.yok.utu.fi
|
||||
Mikulas Patocka mikulas@artax.karlin.mff.cuni.cz
|
||||
Miles Bader miles@gnu.ai.mit.edu
|
||||
Minh Tran-Le tranle@intellicorp.com
|
||||
Morten Welinder terra@diku.dk
|
||||
Neal H Walfield neal@cs.uml.edu
|
||||
Neil Brown neilb@cse.unsw.edu.au
|
||||
Nelson H. F. Beebe beebe@math.utah.edu
|
||||
Nick Estes debian@nickstoys.com
|
||||
Nick Lawes nlawes@silverplatter.com
|
||||
Niklas Edmundsson nikke@acc.umu.se
|
||||
Nikola Milutinovic Nikola.Milutinovic@ev.co.yu
|
||||
Noah Friedman friedman@splode.com
|
||||
Noel Cragg noel@red-bean.com
|
||||
Olatunji Oluwabukunmi Ruwase tjruwase@stanford.edu
|
||||
Olav Morkrid olav@funcom.com
|
||||
Ole Laursen olau@hardworking.dk
|
||||
Oliver Kiddle okiddle@yahoo.co.uk
|
||||
Ørn E. Hansen oehansen@daimi.aau.dk
|
||||
Oskar Liljeblad osk@hem.passagen.se
|
||||
Patrick Mauritz oxygene@studentenbude.ath.cx
|
||||
Paul Eggert eggert@twinsun.com
|
||||
Paul Jarc prj@po.cwru.edu
|
||||
Paul Nevai nevai@ops.mps.ohio-state.edu
|
||||
Paul Sauer paul@alexa.com
|
||||
Paul Slootman paul@debian.org
|
||||
Paul Worrall paul@basilisk.uklinux.net
|
||||
Pawel Prokop pablo@wizard.ae.krakow.pl
|
||||
Per Cederqvist ceder@lysator.liu.se
|
||||
Per Kristian Hove perhov@math.ntnu.no
|
||||
Peter Eriksson peter@ifm.liu.se
|
||||
Peter Horst peter@ointment.org
|
||||
Peter Moulder reiter@netspace.net.au
|
||||
Peter Samuelson psamuels@sampo.creighton.edu
|
||||
Peter Seebach seebs@taniemarie.solon.com
|
||||
Petter Reinholdtsen pere@hungry.com
|
||||
Phelippe Neveu pneveu@pcigeomatics.com
|
||||
Phil Richards phil.richards@vf.vodafone.co.uk
|
||||
Philippe De Muyter phdm@macqel.be
|
||||
Philippe Schnoebelen Philippe.Schnoebelen@imag.fr
|
||||
Phillip Jones mouse@datastacks.com
|
||||
Piergiorgio Sartor sartor@sony.de
|
||||
Piotr Kwapulinski kwap@univ.gda.pl
|
||||
Prashant TR tr@eth.net
|
||||
Rainer Orth ro@TechFak.Uni-Bielefeld.DE
|
||||
Ralf W. Stephan stephan@tmt.de
|
||||
Ralph Loader loader@maths.ox.ac.uk
|
||||
Raul Miller moth@magenta.com
|
||||
Raúl Núñez de Arenas Coronado raul@pleyades.net
|
||||
Reuben Thomas rrt@sc3d.org
|
||||
Richard A Downing richard.downing@bcs.org.uk
|
||||
Richard Braakman dark@xs4all.nl
|
||||
Richard Dawe rich@phekda.freeserve.co.uk
|
||||
Richard J. Rauenzahn rrauenza@hairball.cup.hp.com
|
||||
Richard Neill rn214@hermes.cam.ac.uk
|
||||
Richard Sharman rsharman@magmacom.com
|
||||
Rick Sladkey jrs@world.std.com
|
||||
Rik Faith faith@cs.unc.edu
|
||||
Risto Kankkunen kankkune@lingsoft.fi
|
||||
Robert H. de Vries robert@and.nl
|
||||
Robert Millan zeratul2@wanadoo.es
|
||||
Rogier Wolff R.E.Wolff@BitWizard.nl
|
||||
Roland Huebner ro-huebner@gmx.de
|
||||
Roland Turner raz.tah.bet@raz.cx
|
||||
Ronald F. Guilmette rfg@netcom.com
|
||||
Ross Alexander r.alexander@auckland.ac.nz
|
||||
Ross Paterson rap@doc.ic.ac.uk
|
||||
Ross Ridge rridge@calum.csclub.uwaterloo.ca
|
||||
Sami Farin sfarin@ratol.fi
|
||||
Samuel Tardieu sam@rfc1149.net
|
||||
Samuli Karkkainen Samuli.Karkkainen@hut.fi
|
||||
Sander van Malssen svm@kozmix.ow.nl
|
||||
Santiago Vila Doncel sanvila@unex.es
|
||||
Savochkin Andrey Vladimirovich saw@msu.ru
|
||||
Scott Lurndal slurn@griffin.engr.sgi.com
|
||||
Shing-Shong Shei shei@cs.indiana.edu
|
||||
Soeren Sonnenburg sonnenburg@informatik.hu-berlin.de
|
||||
Solar Designer solar@owl.openwall.com
|
||||
Stanislav Ievlev inger@altlinux.ru
|
||||
Stéphane Chazelas Stephane_CHAZELAS@yahoo.fr
|
||||
Stephen Depooter sbdep@myrealbox.com
|
||||
Stephen Eglen eglen@pcg.wustl.edu
|
||||
Stephen Gildea gildea@stop.mail-abuse.org
|
||||
Stephen Smoogen smooge@mindspring.com
|
||||
Steve McConnel steve@acadcomp.sil.org
|
||||
Steven G. Johnson stevenj@alum.mit.edu
|
||||
Steven Mocking ufo@quicknet.nl
|
||||
Steven P Watson steven@magelico.net
|
||||
Stuart Kemp skemp@peter.bmc.com
|
||||
Szakacsits Szabolcs szaka@sienet.hu
|
||||
Tadayoshi Funaba tadf@kt.rim.or.jp
|
||||
TAKAI Kousuke takai@vlsi.kuee.kyoto-u.ac.jp
|
||||
Theodore Ts'o tytso@rsts-11.mit.edu
|
||||
Thomas Bushnell thomas@gnu.ai.mit.edu
|
||||
Thomas Goerlich thomas@schnappmatik.de
|
||||
Thomas Luzat thomas@luzat.com
|
||||
Thomas Quinot thomas@Cuivre.FR.EU.ORG
|
||||
Tim J. Robbins tjr@FreeBSD.org
|
||||
Tim Mooney mooney@dogbert.cc.ndsu.NoDak.edu
|
||||
Tim Smithers mouse@dmouse.com.au
|
||||
Tim Waugh twaugh@redhat
|
||||
Todd A. Jacobs tjacobs@codegnome.org
|
||||
Tom Haynes thomas@netapp.com
|
||||
Tom Quinn trq@dionysos.thphys.ox.ac.uk
|
||||
Tommi Kyntola tkyntola@cc.hut.fi
|
||||
Ton Hospel thospel@mail.dma.be
|
||||
Ton Nijkes ton@murphy.nl
|
||||
Tony Kocurko akocurko@mun.ca
|
||||
Tony Leneis tony@plaza.ds.adp.com
|
||||
Tony Robinson ajr@eng.cam.ac.uk
|
||||
Torbjorn Granlund tege@nada.kth.se
|
||||
Torbjorn Lindgren tl@funcom.no
|
||||
Torsten Landschoff torsten@pclab.ifg.uni-kiel.de
|
||||
Ulrich Drepper drepper@gnu.org
|
||||
Urs Thuermann urs@isnogud.escape.de
|
||||
Uwe H. Steinfeld usteinfeld@gmx.net
|
||||
Vesselin Atanasov vesselin@bgnet.bg
|
||||
Vin Shelton acs@alumni.princeton.edu
|
||||
Volker Borchert bt@teknon.de
|
||||
Volker Paul vpaul@dohle.com
|
||||
Wartan Hachaturow wart@tepkom.ru
|
||||
Wayne Stewart wstewa@atl.com
|
||||
Wenjun Zheng zwj@yahoo.com
|
||||
Werner Almesberger Werner.Almesberger@epfl.ch
|
||||
Wichert Akkerman wichert@cistron.nl
|
||||
Will Edgington wedgingt@acm.org
|
||||
William Bader william@nscs.fast.net
|
||||
William Dowling will@franklin.com
|
||||
William Lewis wiml@omnigroup.com
|
||||
wiregauze wiregauze@yahoo.com
|
||||
Wojciech Purczynski cliph@isec.pl
|
||||
Wolfram Kleff kleff@cs.uni-bonn.de
|
||||
Won-kyu Park wkpark@chem.skku.ac.kr
|
||||
Yann Dirson dirson@debian.org
|
||||
Zvi Har'El rl@math.technion.ac.il
|
||||
|
|
@ -1,36 +0,0 @@
|
|||
The following teams have translated the many diagnostics of this
|
||||
package into many different languages. Thank you!
|
||||
|
||||
---
|
||||
http://www.iro.umontreal.ca/contrib/po/HTML/team-af.html
|
||||
http://www.iro.umontreal.ca/contrib/po/HTML/team-be.html
|
||||
http://www.iro.umontreal.ca/contrib/po/HTML/team-ca.html
|
||||
http://www.iro.umontreal.ca/contrib/po/HTML/team-cs.html
|
||||
http://www.iro.umontreal.ca/contrib/po/HTML/team-da.html
|
||||
http://www.iro.umontreal.ca/contrib/po/HTML/team-de.html
|
||||
http://www.iro.umontreal.ca/contrib/po/HTML/team-el.html
|
||||
http://www.iro.umontreal.ca/contrib/po/HTML/team-es.html
|
||||
http://www.iro.umontreal.ca/contrib/po/HTML/team-et.html
|
||||
http://www.iro.umontreal.ca/contrib/po/HTML/team-fi.html
|
||||
http://www.iro.umontreal.ca/contrib/po/HTML/team-fr.html
|
||||
http://www.iro.umontreal.ca/contrib/po/HTML/team-ga.html
|
||||
http://www.iro.umontreal.ca/contrib/po/HTML/team-gl.html
|
||||
http://www.iro.umontreal.ca/contrib/po/HTML/team-hu.html
|
||||
http://www.iro.umontreal.ca/contrib/po/HTML/team-it.html
|
||||
http://www.iro.umontreal.ca/contrib/po/HTML/team-ja.html
|
||||
http://www.iro.umontreal.ca/contrib/po/HTML/team-ko.html
|
||||
http://www.iro.umontreal.ca/contrib/po/HTML/team-lg.html
|
||||
http://www.iro.umontreal.ca/contrib/po/HTML/team-ms.html
|
||||
http://www.iro.umontreal.ca/contrib/po/HTML/team-nb.html
|
||||
http://www.iro.umontreal.ca/contrib/po/HTML/team-nl.html
|
||||
http://www.iro.umontreal.ca/contrib/po/HTML/team-no.html
|
||||
http://www.iro.umontreal.ca/contrib/po/HTML/team-pl.html
|
||||
http://www.iro.umontreal.ca/contrib/po/HTML/team-pt.html
|
||||
http://www.iro.umontreal.ca/contrib/po/HTML/team-pt_BR.html
|
||||
http://www.iro.umontreal.ca/contrib/po/HTML/team-ru.html
|
||||
http://www.iro.umontreal.ca/contrib/po/HTML/team-sk.html
|
||||
http://www.iro.umontreal.ca/contrib/po/HTML/team-sl.html
|
||||
http://www.iro.umontreal.ca/contrib/po/HTML/team-sv.html
|
||||
http://www.iro.umontreal.ca/contrib/po/HTML/team-tr.html
|
||||
http://www.iro.umontreal.ca/contrib/po/HTML/team-zh_CN.html
|
||||
http://www.iro.umontreal.ca/contrib/po/HTML/team-zh_TW.html
|
||||
|
|
@ -1,171 +0,0 @@
|
|||
restore djgpp, eventually
|
||||
merge TODO lists
|
||||
add unit tests for lib/*.c
|
||||
|
||||
strip: add an option to specify the program used to strip binaries.
|
||||
suggestion from Karl Berry
|
||||
|
||||
doc/coreutils.texi:
|
||||
Address this comment: FIXME: mv's behavior in this case is system-dependent
|
||||
Better still: fix the code so it's *not* system-dependent.
|
||||
|
||||
implement --target-directory=DIR for install (per texinfo documentation)
|
||||
|
||||
ls: add --format=FORMAT option that controls how each line is printed.
|
||||
|
||||
cp --no-preserve=X should not attempt to preserve attribute X
|
||||
reported by Andreas Schwab
|
||||
|
||||
copy.c: Address the FIXME-maybe comment in copy_internal.
|
||||
And once that's done, add an exclusion so that `cp --link'
|
||||
no longer incurs the overhead of saving src. dev/ino and dest. filename
|
||||
in the hash table.
|
||||
|
||||
See if we can be consistent about where --verbose sends its output:
|
||||
These all send --verbose output to stdout:
|
||||
head, tail, rm, cp, mv, ln, chmod, chown, chgrp, install, ln
|
||||
These send it to stderr:
|
||||
shred mkdir split
|
||||
readlink is different
|
||||
|
||||
Write an autoconf test to work around build failure in HPUX's 64-bit mode.
|
||||
See notes in README -- and remove them once there's a work-around.
|
||||
|
||||
Integrate use of sendfile, suggested here:
|
||||
http://mail.gnu.org/archive/html/bug-fileutils/2003-03/msg00030.html
|
||||
I don't plan to do that, since a few tests demonstrate no significant benefit.
|
||||
|
||||
Should printf '\0123' print "\n3"?
|
||||
per report from TAKAI Kousuke on Mar 27
|
||||
http://mail.gnu.org/archive/html/bug-coreutils/2003-03/index.html
|
||||
|
||||
printf: consider adapting builtins/printf.def from bash
|
||||
|
||||
df: add `--total' option, suggested here http://bugs.debian.org/186007
|
||||
|
||||
seq: give better diagnostics for invalid formats:
|
||||
e.g. no or too many % directives
|
||||
seq: consider allowing format string to contain no %-directives
|
||||
|
||||
m4: rename all macros that start with AC_ to start with another prefix
|
||||
|
||||
resolve RH report on cp -a forwarded by Tim Waugh
|
||||
|
||||
Martin Michlmayr's patch to provide ls with `--sort directory' option
|
||||
|
||||
tail: don't use xlseek; it *exits*.
|
||||
Instead, maybe use a macro and return nonzero.
|
||||
|
||||
add mktemp? Suggested by Nelson Beebe
|
||||
|
||||
df: alignment problem of `Used' heading with e.g., -mP
|
||||
reported by Karl Berry
|
||||
|
||||
tr: support nontrivial equivalence classes, e.g. [=e=] with LC_COLLATE=fr_FR
|
||||
|
||||
fix tail -f to work with named pipes; reported by Ian D. Allen
|
||||
$ mkfifo j; tail -f j & sleep 1; echo x > j
|
||||
./tail: j: file truncated
|
||||
./tail: j: cannot seek to offset 0: Illegal seek
|
||||
|
||||
lib/strftime.c: Since %N is the only format that we need but that
|
||||
glibc's strftime doesn't support, consider using a wrapper that
|
||||
would expand /%(-_)?\d*N/ to the desired string and then pass the
|
||||
resulting string to glibc's strftime.
|
||||
|
||||
sort: Compress temporary files when doing large external sort/merges.
|
||||
This improves performance when you can compress/uncompress faster than
|
||||
you can read/write, which is common in these days of fast CPUs.
|
||||
suggestion from Charles Randall on 2001-08-10
|
||||
|
||||
sort: Add an ordering option -R that causes 'sort' to sort according
|
||||
to a random permutation of the correct sort order. Also, add an
|
||||
option --random-seed=SEED that causes 'sort' to use an arbitrary
|
||||
string SEED to select which permutations to use, in a deterministic
|
||||
manner: that is, if you sort a permutation of the same input file
|
||||
with the same --random-seed=SEED option twice, you'll get the same
|
||||
output. The default SEED is chosen at random, and contains enough
|
||||
information to ensure that the output permutation is random.
|
||||
suggestion from Feth AREZKI, Stephan Kasal, and Paul Eggert on 2003-07-17
|
||||
|
||||
unexpand: [http://www.opengroup.org/onlinepubs/007908799/xcu/unexpand.html]
|
||||
printf 'x\t \t y\n'|unexpand -t 8,9 should print its input, unmodified.
|
||||
printf 'x\t \t y\n'|unexpand -t 5,8 should print "x\ty\n"
|
||||
|
||||
Let GNU su use the `wheel' group if appropriate.
|
||||
(there are a couple patches, already)
|
||||
|
||||
sort: Investigate better sorting algorithms; see Knuth vol. 3.
|
||||
|
||||
We tried list merge sort, but it was about 50% slower than the
|
||||
recursive algorithm currently used by sortlines, and it used more
|
||||
comparisons. We're not sure why this was, as the theory suggests it
|
||||
should do fewer comparisons, so perhaps this should be revisited.
|
||||
List merge sort was implemented in the style of Knuth algorithm
|
||||
5.2.4L, with the optimization suggested by exercise 5.2.4-22. The
|
||||
test case was 140,213,394 bytes, 426,4424 lines, text taken from the
|
||||
GCC 3.3 distribution, sort.c compiled with GCC 2.95.4 and running on
|
||||
Debian 3.0r1 GNU/Linux, 2.4GHz Pentium 4, single pass with no
|
||||
temporary files and plenty of RAM.
|
||||
|
||||
Since comparisons seem to be the bottleneck, perhaps the best
|
||||
algorithm to try next should be merge insertion. See Knuth section
|
||||
5.3.1, who credits Lester Ford, Jr. and Selmer Johnson, American
|
||||
Mathematical Monthly 66 (1959), 387-389.
|
||||
|
||||
cp --recursive: perform dir traversals in source and dest hierarchy rather
|
||||
than forming full file names. The latter (current) approach fails
|
||||
unnecessarily when the names become very long.
|
||||
|
||||
tail --p is now ambiguous
|
||||
|
||||
Remove suspicious uses of alloca (ones that may allocate more than
|
||||
about 4k)
|
||||
|
||||
Adapt these contribution guidelines for coreutils:
|
||||
http://sources.redhat.com/automake/contribute.html
|
||||
|
||||
|
||||
Changes expected to go in, post-5.2.1:
|
||||
======================================
|
||||
|
||||
wc: add an option, --files0-from [as for du] to make it read NUL-delimited
|
||||
file name arguments from a file.
|
||||
|
||||
dd patch from Olivier Delhomme
|
||||
|
||||
Apply Andreas Gruenbacher's ACL and xattr changes
|
||||
|
||||
Apply Bruno Haible's hostname changes
|
||||
|
||||
test/mv/*: clean up $other_partition_tmpdir in all cases
|
||||
|
||||
ls: when both -l and --dereference-command-line-symlink-to-dir are
|
||||
specified, consider whether to let the latter select whether to
|
||||
dereference command line symlinks to directories. Since -l has
|
||||
an implicit --NO-dereference-command-line-symlink-to-dir meaning.
|
||||
Pointed out by Karl Berry.
|
||||
|
||||
A more efficient version of factor, and possibly one that
|
||||
accepts inputs of size 2^64 and larger.
|
||||
|
||||
Re-add a separate test for du's stack space usage (like the one removed
|
||||
from tests/rm/deep-1).
|
||||
|
||||
dd: consider adding an option to suppress `bytes/block read/written'
|
||||
output to stderr. Suggested here:
|
||||
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=165045
|
||||
|
||||
Pending copyright papers:
|
||||
------------------------
|
||||
ls --color: Ed Avis' patch to suppress escape sequences for
|
||||
non-highlighted files
|
||||
|
||||
getpwnam from Bruce Korb
|
||||
|
||||
pb (progress bar) from Miika Pekkarinen
|
||||
|
||||
Look into improving the performance of md5sum.
|
||||
`openssl md5' is consistently about 30% faster than md5sum on an idle
|
||||
AMD 2000-XP system with plenty of RAM and a 261 MB input file.
|
||||
openssl's md5 implementation is in assembly, generated by a perl script.
|
||||
|
|
@ -1,30 +0,0 @@
|
|||
/* __fpending.c -- return the number of pending output bytes on a stream
|
||||
Copyright (C) 2000 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, write to the Free Software Foundation,
|
||||
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
||||
|
||||
/* Written by Jim Meyering. */
|
||||
|
||||
#if HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#include "__fpending.h"
|
||||
|
||||
size_t
|
||||
__fpending (FILE *fp)
|
||||
{
|
||||
return PENDING_OUTPUT_N_BYTES;
|
||||
}
|
||||
|
|
@ -1,17 +0,0 @@
|
|||
#if HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#if HAVE_STDIO_EXT_H
|
||||
# include <stdio_ext.h>
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_DECL___FPENDING
|
||||
"this configure-time declaration test was not run"
|
||||
#endif
|
||||
#if !HAVE_DECL___FPENDING
|
||||
size_t __fpending (FILE *);
|
||||
#endif
|
||||
|
|
@ -1,278 +0,0 @@
|
|||
/* argmatch.c -- find a match for a string in an array
|
||||
|
||||
Copyright (C) 1990, 1998, 1999, 2001, 2002, 2003, 2004 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, write to the Free Software Foundation,
|
||||
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
||||
|
||||
/* Written by David MacKenzie <djm@ai.mit.edu>
|
||||
Modified by Akim Demaille <demaille@inf.enst.fr> */
|
||||
|
||||
#if HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
/* Specification. */
|
||||
#include "argmatch.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "gettext.h"
|
||||
#define _(msgid) gettext (msgid)
|
||||
|
||||
#include "error.h"
|
||||
#include "exit.h"
|
||||
#include "quotearg.h"
|
||||
#include "quote.h"
|
||||
#include "unlocked-io.h"
|
||||
|
||||
/* When reporting an invalid argument, show nonprinting characters
|
||||
by using the quoting style ARGMATCH_QUOTING_STYLE. Do not use
|
||||
literal_quoting_style. */
|
||||
#ifndef ARGMATCH_QUOTING_STYLE
|
||||
# define ARGMATCH_QUOTING_STYLE locale_quoting_style
|
||||
#endif
|
||||
|
||||
/* Non failing version of argmatch call this function after failing. */
|
||||
#ifndef ARGMATCH_DIE
|
||||
# include "exitfail.h"
|
||||
# define ARGMATCH_DIE exit (exit_failure)
|
||||
#endif
|
||||
|
||||
#ifdef ARGMATCH_DIE_DECL
|
||||
ARGMATCH_DIE_DECL;
|
||||
#endif
|
||||
|
||||
static void
|
||||
__argmatch_die (void)
|
||||
{
|
||||
ARGMATCH_DIE;
|
||||
}
|
||||
|
||||
/* Used by XARGMATCH and XARGCASEMATCH. See description in argmatch.h.
|
||||
Default to __argmatch_die, but allow caller to change this at run-time. */
|
||||
argmatch_exit_fn argmatch_die = __argmatch_die;
|
||||
|
||||
|
||||
/* If ARG is an unambiguous match for an element of the
|
||||
null-terminated array ARGLIST, return the index in ARGLIST
|
||||
of the matched element, else -1 if it does not match any element
|
||||
or -2 if it is ambiguous (is a prefix of more than one element).
|
||||
|
||||
If VALLIST is none null, use it to resolve ambiguities limited to
|
||||
synonyms, i.e., for
|
||||
"yes", "yop" -> 0
|
||||
"no", "nope" -> 1
|
||||
"y" is a valid argument, for `0', and "n" for `1'. */
|
||||
|
||||
ptrdiff_t
|
||||
argmatch (const char *arg, const char *const *arglist,
|
||||
const char *vallist, size_t valsize)
|
||||
{
|
||||
size_t i; /* Temporary index in ARGLIST. */
|
||||
size_t arglen; /* Length of ARG. */
|
||||
ptrdiff_t matchind = -1; /* Index of first nonexact match. */
|
||||
bool ambiguous = false; /* If true, multiple nonexact match(es). */
|
||||
|
||||
arglen = strlen (arg);
|
||||
|
||||
/* Test all elements for either exact match or abbreviated matches. */
|
||||
for (i = 0; arglist[i]; i++)
|
||||
{
|
||||
if (!strncmp (arglist[i], arg, arglen))
|
||||
{
|
||||
if (strlen (arglist[i]) == arglen)
|
||||
/* Exact match found. */
|
||||
return i;
|
||||
else if (matchind == -1)
|
||||
/* First nonexact match found. */
|
||||
matchind = i;
|
||||
else
|
||||
{
|
||||
/* Second nonexact match found. */
|
||||
if (vallist == NULL
|
||||
|| memcmp (vallist + valsize * matchind,
|
||||
vallist + valsize * i, valsize))
|
||||
{
|
||||
/* There is a real ambiguity, or we could not
|
||||
disambiguate. */
|
||||
ambiguous = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (ambiguous)
|
||||
return -2;
|
||||
else
|
||||
return matchind;
|
||||
}
|
||||
|
||||
/* Error reporting for argmatch.
|
||||
CONTEXT is a description of the type of entity that was being matched.
|
||||
VALUE is the invalid value that was given.
|
||||
PROBLEM is the return value from argmatch. */
|
||||
|
||||
void
|
||||
argmatch_invalid (const char *context, const char *value, ptrdiff_t problem)
|
||||
{
|
||||
char const *format = (problem == -1
|
||||
? _("invalid argument %s for %s")
|
||||
: _("ambiguous argument %s for %s"));
|
||||
|
||||
error (0, 0, format, quotearg_n_style (0, ARGMATCH_QUOTING_STYLE, value),
|
||||
quote_n (1, context));
|
||||
}
|
||||
|
||||
/* List the valid arguments for argmatch.
|
||||
ARGLIST is the same as in argmatch.
|
||||
VALLIST is a pointer to an array of values.
|
||||
VALSIZE is the size of the elements of VALLIST */
|
||||
void
|
||||
argmatch_valid (const char *const *arglist,
|
||||
const char *vallist, size_t valsize)
|
||||
{
|
||||
size_t i;
|
||||
const char *last_val = NULL;
|
||||
|
||||
/* We try to put synonyms on the same line. The assumption is that
|
||||
synonyms follow each other */
|
||||
fprintf (stderr, _("Valid arguments are:"));
|
||||
for (i = 0; arglist[i]; i++)
|
||||
if ((i == 0)
|
||||
|| memcmp (last_val, vallist + valsize * i, valsize))
|
||||
{
|
||||
fprintf (stderr, "\n - `%s'", arglist[i]);
|
||||
last_val = vallist + valsize * i;
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf (stderr, ", `%s'", arglist[i]);
|
||||
}
|
||||
putc ('\n', stderr);
|
||||
}
|
||||
|
||||
/* Never failing versions of the previous functions.
|
||||
|
||||
CONTEXT is the context for which argmatch is called (e.g.,
|
||||
"--version-control", or "$VERSION_CONTROL" etc.). Upon failure,
|
||||
calls the (supposed never to return) function EXIT_FN. */
|
||||
|
||||
ptrdiff_t
|
||||
__xargmatch_internal (const char *context,
|
||||
const char *arg, const char *const *arglist,
|
||||
const char *vallist, size_t valsize,
|
||||
argmatch_exit_fn exit_fn)
|
||||
{
|
||||
ptrdiff_t res = argmatch (arg, arglist, vallist, valsize);
|
||||
if (res >= 0)
|
||||
/* Success. */
|
||||
return res;
|
||||
|
||||
/* We failed. Explain why. */
|
||||
argmatch_invalid (context, arg, res);
|
||||
argmatch_valid (arglist, vallist, valsize);
|
||||
(*exit_fn) ();
|
||||
|
||||
return -1; /* To please the compilers. */
|
||||
}
|
||||
|
||||
/* Look for VALUE in VALLIST, an array of objects of size VALSIZE and
|
||||
return the first corresponding argument in ARGLIST */
|
||||
const char *
|
||||
argmatch_to_argument (const char *value,
|
||||
const char *const *arglist,
|
||||
const char *vallist, size_t valsize)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
for (i = 0; arglist[i]; i++)
|
||||
if (!memcmp (value, vallist + valsize * i, valsize))
|
||||
return arglist[i];
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#ifdef TEST
|
||||
/*
|
||||
* Based on "getversion.c" by David MacKenzie <djm@gnu.ai.mit.edu>
|
||||
*/
|
||||
char *program_name;
|
||||
|
||||
/* When to make backup files. */
|
||||
enum backup_type
|
||||
{
|
||||
/* Never make backups. */
|
||||
none,
|
||||
|
||||
/* Make simple backups of every file. */
|
||||
simple,
|
||||
|
||||
/* Make numbered backups of files that already have numbered backups,
|
||||
and simple backups of the others. */
|
||||
numbered_existing,
|
||||
|
||||
/* Make numbered backups of every file. */
|
||||
numbered
|
||||
};
|
||||
|
||||
/* Two tables describing arguments (keys) and their corresponding
|
||||
values */
|
||||
static const char *const backup_args[] =
|
||||
{
|
||||
"no", "none", "off",
|
||||
"simple", "never",
|
||||
"existing", "nil",
|
||||
"numbered", "t",
|
||||
0
|
||||
};
|
||||
|
||||
static const enum backup_type backup_vals[] =
|
||||
{
|
||||
none, none, none,
|
||||
simple, simple,
|
||||
numbered_existing, numbered_existing,
|
||||
numbered, numbered
|
||||
};
|
||||
|
||||
int
|
||||
main (int argc, const char *const *argv)
|
||||
{
|
||||
const char *cp;
|
||||
enum backup_type backup_type = none;
|
||||
|
||||
program_name = (char *) argv[0];
|
||||
|
||||
if (argc > 2)
|
||||
{
|
||||
fprintf (stderr, "Usage: %s [VERSION_CONTROL]\n", program_name);
|
||||
exit (1);
|
||||
}
|
||||
|
||||
if ((cp = getenv ("VERSION_CONTROL")))
|
||||
backup_type = XARGMATCH ("$VERSION_CONTROL", cp,
|
||||
backup_args, backup_vals);
|
||||
|
||||
if (argc == 2)
|
||||
backup_type = XARGMATCH (program_name, argv[1],
|
||||
backup_args, backup_vals);
|
||||
|
||||
printf ("The version control is `%s'\n",
|
||||
ARGMATCH_TO_ARGUMENT (backup_type, backup_args, backup_vals));
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
|
@ -1,112 +0,0 @@
|
|||
/* argmatch.h -- definitions and prototypes for argmatch.c
|
||||
|
||||
Copyright (C) 1990, 1998, 1999, 2001, 2002, 2004 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, write to the Free Software Foundation,
|
||||
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
||||
|
||||
/* Written by David MacKenzie <djm@ai.mit.edu>
|
||||
Modified by Akim Demaille <demaille@inf.enst.fr> */
|
||||
|
||||
#ifndef ARGMATCH_H_
|
||||
# define ARGMATCH_H_ 1
|
||||
|
||||
# include <stddef.h>
|
||||
|
||||
# define ARRAY_CARDINALITY(Array) (sizeof (Array) / sizeof *(Array))
|
||||
|
||||
# define ARGMATCH_CONSTRAINT(Arglist, Vallist) \
|
||||
(ARRAY_CARDINALITY (Arglist) == ARRAY_CARDINALITY (Vallist) + 1)
|
||||
|
||||
/* Assert there are as many real arguments as there are values
|
||||
(argument list ends with a NULL guard). ARGMATCH_VERIFY is
|
||||
preferred, since it is guaranteed to be checked at compile-time.
|
||||
ARGMATCH_ASSERT is for backward compatibility only. */
|
||||
|
||||
# define ARGMATCH_VERIFY(Arglist, Vallist) \
|
||||
struct argmatch_verify \
|
||||
{ \
|
||||
char argmatch_verify[ARGMATCH_CONSTRAINT(Arglist, Vallist) ? 1 : -1]; \
|
||||
}
|
||||
|
||||
# define ARGMATCH_ASSERT(Arglist, Vallist) \
|
||||
assert (ARGMATCH_CONSTRAINT (Arglist, Vallist))
|
||||
|
||||
/* Return the index of the element of ARGLIST (NULL terminated) that
|
||||
matches with ARG. If VALLIST is not NULL, then use it to resolve
|
||||
false ambiguities (i.e., different matches of ARG but corresponding
|
||||
to the same values in VALLIST). */
|
||||
|
||||
ptrdiff_t argmatch (char const *arg, char const *const *arglist,
|
||||
char const *vallist, size_t valsize);
|
||||
|
||||
# define ARGMATCH(Arg, Arglist, Vallist) \
|
||||
argmatch (Arg, Arglist, (char const *) (Vallist), sizeof *(Vallist))
|
||||
|
||||
/* xargmatch calls this function when it fails. This function should not
|
||||
return. By default, this is a function that calls ARGMATCH_DIE which
|
||||
in turn defaults to `exit (exit_failure)'. */
|
||||
typedef void (*argmatch_exit_fn) (void);
|
||||
extern argmatch_exit_fn argmatch_die;
|
||||
|
||||
/* Report on stderr why argmatch failed. Report correct values. */
|
||||
|
||||
void argmatch_invalid (char const *context, char const *value,
|
||||
ptrdiff_t problem);
|
||||
|
||||
/* Left for compatibility with the old name invalid_arg */
|
||||
|
||||
# define invalid_arg(Context, Value, Problem) \
|
||||
argmatch_invalid (Context, Value, Problem)
|
||||
|
||||
|
||||
|
||||
/* Report on stderr the list of possible arguments. */
|
||||
|
||||
void argmatch_valid (char const *const *arglist,
|
||||
char const *vallist, size_t valsize);
|
||||
|
||||
# define ARGMATCH_VALID(Arglist, Vallist) \
|
||||
argmatch_valid (Arglist, (char const *) (Vallist), sizeof *(Vallist))
|
||||
|
||||
|
||||
|
||||
/* Same as argmatch, but upon failure, reports a explanation on the
|
||||
failure, and exits using the function EXIT_FN. */
|
||||
|
||||
ptrdiff_t __xargmatch_internal (char const *context,
|
||||
char const *arg, char const *const *arglist,
|
||||
char const *vallist, size_t valsize,
|
||||
argmatch_exit_fn exit_fn);
|
||||
|
||||
/* Programmer friendly interface to __xargmatch_internal. */
|
||||
|
||||
# define XARGMATCH(Context, Arg, Arglist, Vallist) \
|
||||
((Vallist) [__xargmatch_internal (Context, Arg, Arglist, \
|
||||
(char const *) (Vallist), \
|
||||
sizeof *(Vallist), \
|
||||
argmatch_die)])
|
||||
|
||||
/* Convert a value into a corresponding argument. */
|
||||
|
||||
char const *argmatch_to_argument (char const *value,
|
||||
char const *const *arglist,
|
||||
char const *vallist, size_t valsize);
|
||||
|
||||
# define ARGMATCH_TO_ARGUMENT(Value, Arglist, Vallist) \
|
||||
argmatch_to_argument (Value, Arglist, \
|
||||
(char const *) (Vallist), sizeof *(Vallist))
|
||||
|
||||
#endif /* ARGMATCH_H_ */
|
||||
|
|
@ -1,93 +0,0 @@
|
|||
/* closeout.c - close standard output
|
||||
|
||||
Copyright (C) 1998, 1999, 2000, 2001, 2002, 2004 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, write to the Free Software Foundation,
|
||||
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
||||
|
||||
#if HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#include "closeout.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "gettext.h"
|
||||
#define _(msgid) gettext (msgid)
|
||||
|
||||
#include "error.h"
|
||||
#include "exitfail.h"
|
||||
#include "quotearg.h"
|
||||
#include "unlocked-io.h"
|
||||
#include "__fpending.h"
|
||||
|
||||
static const char *file_name;
|
||||
|
||||
/* Set the file name to be reported in the event an error is detected
|
||||
by close_stdout. */
|
||||
void
|
||||
close_stdout_set_file_name (const char *file)
|
||||
{
|
||||
file_name = file;
|
||||
}
|
||||
|
||||
/* Close standard output, exiting with status 'exit_failure' on failure.
|
||||
If a program writes *anything* to stdout, that program should `fflush'
|
||||
stdout and make sure that it succeeds before exiting. Otherwise,
|
||||
suppose that you go to the extreme of checking the return status
|
||||
of every function that does an explicit write to stdout. The last
|
||||
printf can succeed in writing to the internal stream buffer, and yet
|
||||
the fclose(stdout) could still fail (due e.g., to a disk full error)
|
||||
when it tries to write out that buffered data. Thus, you would be
|
||||
left with an incomplete output file and the offending program would
|
||||
exit successfully.
|
||||
|
||||
FIXME: note the fflush suggested above is implicit in the fclose
|
||||
we actually do below. Consider doing only the fflush and/or using
|
||||
setvbuf to inhibit buffering.
|
||||
|
||||
Besides, it's wasteful to check the return value from every call
|
||||
that writes to stdout -- just let the internal stream state record
|
||||
the failure. That's what the ferror test is checking below.
|
||||
|
||||
It's important to detect such failures and exit nonzero because many
|
||||
tools (most notably `make' and other build-management systems) depend
|
||||
on being able to detect failure in other tools via their exit status. */
|
||||
|
||||
void
|
||||
close_stdout (void)
|
||||
{
|
||||
int e = ferror (stdout) ? 0 : -1;
|
||||
|
||||
/* If the stream's error bit is clear and there is nothing to flush,
|
||||
then return right away. */
|
||||
if (e && __fpending (stdout) == 0)
|
||||
return;
|
||||
|
||||
if (fclose (stdout) != 0)
|
||||
e = errno;
|
||||
|
||||
if (0 <= e)
|
||||
{
|
||||
char const *write_error = _("write error");
|
||||
if (file_name)
|
||||
error (exit_failure, e, "%s: %s", quotearg_colon (file_name),
|
||||
write_error);
|
||||
else
|
||||
error (exit_failure, e, "%s", write_error);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,33 +0,0 @@
|
|||
/* Close standard output.
|
||||
|
||||
Copyright (C) 1998, 2000, 2003, 2004 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, write to the Free Software Foundation,
|
||||
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
||||
|
||||
#ifndef CLOSEOUT_H
|
||||
# define CLOSEOUT_H 1
|
||||
|
||||
# ifdef __cplusplus
|
||||
extern "C" {
|
||||
# endif
|
||||
|
||||
void close_stdout_set_file_name (const char *file);
|
||||
void close_stdout (void);
|
||||
|
||||
# ifdef __cplusplus
|
||||
}
|
||||
# endif
|
||||
|
||||
#endif
|
||||
|
|
@ -1,59 +0,0 @@
|
|||
/* Invoke dup, but avoid some glitches.
|
||||
Copyright (C) 2001, 2004 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, write to the Free Software Foundation,
|
||||
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
||||
|
||||
/* Written by Paul Eggert. */
|
||||
|
||||
#if HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
#if HAVE_FCNTL_H
|
||||
# include <fcntl.h>
|
||||
#endif
|
||||
|
||||
#if HAVE_UNISTD_H
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
#ifndef STDERR_FILENO
|
||||
# define STDERR_FILENO 2
|
||||
#endif
|
||||
|
||||
#include <unistd-safer.h>
|
||||
|
||||
/* Like dup, but do not return STDIN_FILENO, STDOUT_FILENO, or
|
||||
STDERR_FILENO. */
|
||||
|
||||
int
|
||||
dup_safer (int fd)
|
||||
{
|
||||
#ifdef F_DUPFD
|
||||
return fcntl (fd, F_DUPFD, STDERR_FILENO + 1);
|
||||
#else
|
||||
int f = dup (fd);
|
||||
if (0 <= f && f <= STDERR_FILENO)
|
||||
{
|
||||
int f1 = dup_safer (f);
|
||||
int e = errno;
|
||||
close (f);
|
||||
errno = e;
|
||||
f = f1;
|
||||
}
|
||||
return f;
|
||||
#endif
|
||||
}
|
||||
|
|
@ -1,306 +0,0 @@
|
|||
/* Error handler for noninteractive utilities
|
||||
Copyright (C) 1990-1998, 2000-2002, 2003, 2004 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
|
||||
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, write to the Free Software Foundation,
|
||||
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
||||
|
||||
/* Written by David MacKenzie <djm@gnu.ai.mit.edu>. */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#include "error.h"
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef _LIBC
|
||||
# include <libintl.h>
|
||||
#else
|
||||
# include "gettext.h"
|
||||
#endif
|
||||
|
||||
#ifdef _LIBC
|
||||
# include <wchar.h>
|
||||
# define mbsrtowcs __mbsrtowcs
|
||||
#endif
|
||||
|
||||
#if !_LIBC
|
||||
# include "unlocked-io.h"
|
||||
#endif
|
||||
|
||||
#ifndef _
|
||||
# define _(String) String
|
||||
#endif
|
||||
|
||||
/* If NULL, error will flush stdout, then print on stderr the program
|
||||
name, a colon and a space. Otherwise, error will call this
|
||||
function without parameters instead. */
|
||||
void (*error_print_progname) (void);
|
||||
|
||||
/* This variable is incremented each time `error' is called. */
|
||||
unsigned int error_message_count;
|
||||
|
||||
#ifdef _LIBC
|
||||
/* In the GNU C library, there is a predefined variable for this. */
|
||||
|
||||
# define program_name program_invocation_name
|
||||
# include <errno.h>
|
||||
# include <libio/libioP.h>
|
||||
|
||||
/* In GNU libc we want do not want to use the common name `error' directly.
|
||||
Instead make it a weak alias. */
|
||||
extern void __error (int status, int errnum, const char *message, ...)
|
||||
__attribute__ ((__format__ (__printf__, 3, 4)));
|
||||
extern void __error_at_line (int status, int errnum, const char *file_name,
|
||||
unsigned int line_number, const char *message,
|
||||
...)
|
||||
__attribute__ ((__format__ (__printf__, 5, 6)));;
|
||||
# define error __error
|
||||
# define error_at_line __error_at_line
|
||||
|
||||
# include <libio/iolibio.h>
|
||||
# define fflush(s) INTUSE(_IO_fflush) (s)
|
||||
# undef putc
|
||||
# define putc(c, fp) INTUSE(_IO_putc) (c, fp)
|
||||
|
||||
# include <bits/libc-lock.h>
|
||||
|
||||
#else /* not _LIBC */
|
||||
|
||||
# if !HAVE_DECL_STRERROR_R && STRERROR_R_CHAR_P
|
||||
# ifndef HAVE_DECL_STRERROR_R
|
||||
"this configure-time declaration test was not run"
|
||||
# endif
|
||||
char *strerror_r ();
|
||||
# endif
|
||||
|
||||
# ifndef SIZE_MAX
|
||||
# define SIZE_MAX ((size_t) -1)
|
||||
# endif
|
||||
|
||||
/* The calling program should define program_name and set it to the
|
||||
name of the executing program. */
|
||||
extern char *program_name;
|
||||
|
||||
# if HAVE_STRERROR_R || defined strerror_r
|
||||
# define __strerror_r strerror_r
|
||||
# endif
|
||||
#endif /* not _LIBC */
|
||||
|
||||
static void
|
||||
print_errno_message (int errnum)
|
||||
{
|
||||
char const *s = NULL;
|
||||
|
||||
#if defined HAVE_STRERROR_R || _LIBC
|
||||
char errbuf[1024];
|
||||
# if STRERROR_R_CHAR_P || _LIBC
|
||||
s = __strerror_r (errnum, errbuf, sizeof errbuf);
|
||||
# else
|
||||
if (__strerror_r (errnum, errbuf, sizeof errbuf) == 0)
|
||||
s = errbuf;
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if !_LIBC
|
||||
if (! s && ! (s = strerror (errnum)))
|
||||
s = _("Unknown system error");
|
||||
#endif
|
||||
|
||||
#if _LIBC
|
||||
if (_IO_fwide (stderr, 0) > 0)
|
||||
{
|
||||
__fwprintf (stderr, L": %s", s);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
fprintf (stderr, ": %s", s);
|
||||
}
|
||||
|
||||
static void
|
||||
error_tail (int status, int errnum, const char *message, va_list args)
|
||||
{
|
||||
#if _LIBC
|
||||
if (_IO_fwide (stderr, 0) > 0)
|
||||
{
|
||||
# define ALLOCA_LIMIT 2000
|
||||
size_t len = strlen (message) + 1;
|
||||
const wchar_t *wmessage = L"out of memory";
|
||||
wchar_t *wbuf = (len < ALLOCA_LIMIT
|
||||
? alloca (len * sizeof *wbuf)
|
||||
: len <= SIZE_MAX / sizeof *wbuf
|
||||
? malloc (len * sizeof *wbuf)
|
||||
: NULL);
|
||||
|
||||
if (wbuf)
|
||||
{
|
||||
size_t res;
|
||||
mbstate_t st;
|
||||
const char *tmp = message;
|
||||
memset (&st, '\0', sizeof (st));
|
||||
res = mbsrtowcs (wbuf, &tmp, len, &st);
|
||||
wmessage = res == (size_t) -1 ? L"???" : wbuf;
|
||||
}
|
||||
|
||||
__vfwprintf (stderr, wmessage, args);
|
||||
if (! (len < ALLOCA_LIMIT))
|
||||
free (wbuf);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
vfprintf (stderr, message, args);
|
||||
va_end (args);
|
||||
|
||||
++error_message_count;
|
||||
if (errnum)
|
||||
print_errno_message (errnum);
|
||||
#if _LIBC
|
||||
if (_IO_fwide (stderr, 0) > 0)
|
||||
putwc (L'\n', stderr);
|
||||
else
|
||||
#endif
|
||||
putc ('\n', stderr);
|
||||
fflush (stderr);
|
||||
if (status)
|
||||
exit (status);
|
||||
}
|
||||
|
||||
|
||||
/* Print the program name and error message MESSAGE, which is a printf-style
|
||||
format string with optional args.
|
||||
If ERRNUM is nonzero, print its corresponding system error message.
|
||||
Exit with status STATUS if it is nonzero. */
|
||||
void
|
||||
error (int status, int errnum, const char *message, ...)
|
||||
{
|
||||
va_list args;
|
||||
|
||||
#if defined _LIBC && defined __libc_ptf_call
|
||||
/* We do not want this call to be cut short by a thread
|
||||
cancellation. Therefore disable cancellation for now. */
|
||||
int state = PTHREAD_CANCEL_ENABLE;
|
||||
__libc_ptf_call (pthread_setcancelstate, (PTHREAD_CANCEL_DISABLE, &state),
|
||||
0);
|
||||
#endif
|
||||
|
||||
fflush (stdout);
|
||||
#ifdef _LIBC
|
||||
_IO_flockfile (stderr);
|
||||
#endif
|
||||
if (error_print_progname)
|
||||
(*error_print_progname) ();
|
||||
else
|
||||
{
|
||||
#if _LIBC
|
||||
if (_IO_fwide (stderr, 0) > 0)
|
||||
__fwprintf (stderr, L"%s: ", program_name);
|
||||
else
|
||||
#endif
|
||||
fprintf (stderr, "%s: ", program_name);
|
||||
}
|
||||
|
||||
va_start (args, message);
|
||||
error_tail (status, errnum, message, args);
|
||||
|
||||
#ifdef _LIBC
|
||||
_IO_funlockfile (stderr);
|
||||
# ifdef __libc_ptf_call
|
||||
__libc_ptf_call (pthread_setcancelstate, (state, NULL), 0);
|
||||
# endif
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Sometimes we want to have at most one error per line. This
|
||||
variable controls whether this mode is selected or not. */
|
||||
int error_one_per_line;
|
||||
|
||||
void
|
||||
error_at_line (int status, int errnum, const char *file_name,
|
||||
unsigned int line_number, const char *message, ...)
|
||||
{
|
||||
va_list args;
|
||||
|
||||
if (error_one_per_line)
|
||||
{
|
||||
static const char *old_file_name;
|
||||
static unsigned int old_line_number;
|
||||
|
||||
if (old_line_number == line_number
|
||||
&& (file_name == old_file_name
|
||||
|| strcmp (old_file_name, file_name) == 0))
|
||||
/* Simply return and print nothing. */
|
||||
return;
|
||||
|
||||
old_file_name = file_name;
|
||||
old_line_number = line_number;
|
||||
}
|
||||
|
||||
#if defined _LIBC && defined __libc_ptf_call
|
||||
/* We do not want this call to be cut short by a thread
|
||||
cancellation. Therefore disable cancellation for now. */
|
||||
int state = PTHREAD_CANCEL_ENABLE;
|
||||
__libc_ptf_call (pthread_setcancelstate, (PTHREAD_CANCEL_DISABLE, &state),
|
||||
0);
|
||||
#endif
|
||||
|
||||
fflush (stdout);
|
||||
#ifdef _LIBC
|
||||
_IO_flockfile (stderr);
|
||||
#endif
|
||||
if (error_print_progname)
|
||||
(*error_print_progname) ();
|
||||
else
|
||||
{
|
||||
#if _LIBC
|
||||
if (_IO_fwide (stderr, 0) > 0)
|
||||
__fwprintf (stderr, L"%s: ", program_name);
|
||||
else
|
||||
#endif
|
||||
fprintf (stderr, "%s:", program_name);
|
||||
}
|
||||
|
||||
if (file_name != NULL)
|
||||
{
|
||||
#if _LIBC
|
||||
if (_IO_fwide (stderr, 0) > 0)
|
||||
__fwprintf (stderr, L"%s:%d: ", file_name, line_number);
|
||||
else
|
||||
#endif
|
||||
fprintf (stderr, "%s:%d: ", file_name, line_number);
|
||||
}
|
||||
|
||||
va_start (args, message);
|
||||
error_tail (status, errnum, message, args);
|
||||
|
||||
#ifdef _LIBC
|
||||
_IO_funlockfile (stderr);
|
||||
# ifdef __libc_ptf_call
|
||||
__libc_ptf_call (pthread_setcancelstate, (state, NULL), 0);
|
||||
# endif
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef _LIBC
|
||||
/* Make the weak alias. */
|
||||
# undef error
|
||||
# undef error_at_line
|
||||
weak_alias (__error, error)
|
||||
weak_alias (__error_at_line, error_at_line)
|
||||
#endif
|
||||
|
|
@ -1,66 +0,0 @@
|
|||
/* Declaration for error-reporting function
|
||||
Copyright (C) 1995, 1996, 1997, 2003 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
|
||||
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, write to the Free Software Foundation,
|
||||
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
||||
|
||||
#ifndef _ERROR_H
|
||||
#define _ERROR_H 1
|
||||
|
||||
#ifndef __attribute__
|
||||
/* This feature is available in gcc versions 2.5 and later. */
|
||||
# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5)
|
||||
# define __attribute__(Spec) /* empty */
|
||||
# endif
|
||||
/* The __-protected variants of `format' and `printf' attributes
|
||||
are accepted by gcc versions 2.6.4 (effectively 2.7) and later. */
|
||||
# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
|
||||
# define __format__ format
|
||||
# define __printf__ printf
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Print a message with `fprintf (stderr, FORMAT, ...)';
|
||||
if ERRNUM is nonzero, follow it with ": " and strerror (ERRNUM).
|
||||
If STATUS is nonzero, terminate the program with `exit (STATUS)'. */
|
||||
|
||||
extern void error (int __status, int __errnum, const char *__format, ...)
|
||||
__attribute__ ((__format__ (__printf__, 3, 4)));
|
||||
|
||||
extern void error_at_line (int __status, int __errnum, const char *__fname,
|
||||
unsigned int __lineno, const char *__format, ...)
|
||||
__attribute__ ((__format__ (__printf__, 5, 6)));
|
||||
|
||||
/* If NULL, error will flush stdout, then print on stderr the program
|
||||
name, a colon and a space. Otherwise, error will call this
|
||||
function without parameters instead. */
|
||||
extern void (*error_print_progname) (void);
|
||||
|
||||
/* This variable is incremented each time `error' is called. */
|
||||
extern unsigned int error_message_count;
|
||||
|
||||
/* Sometimes we want to have at most one error per line. This
|
||||
variable controls whether this mode is selected or not. */
|
||||
extern int error_one_per_line;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* error.h */
|
||||
|
|
@ -1,32 +0,0 @@
|
|||
/* exit() function.
|
||||
Copyright (C) 1995, 2001 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, write to the Free Software Foundation,
|
||||
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
||||
|
||||
#ifndef _EXIT_H
|
||||
#define _EXIT_H
|
||||
|
||||
/* Get exit() declaration. */
|
||||
#include <stdlib.h>
|
||||
|
||||
/* Some systems do not define EXIT_*, even with STDC_HEADERS. */
|
||||
#ifndef EXIT_SUCCESS
|
||||
# define EXIT_SUCCESS 0
|
||||
#endif
|
||||
#ifndef EXIT_FAILURE
|
||||
# define EXIT_FAILURE 1
|
||||
#endif
|
||||
|
||||
#endif /* _EXIT_H */
|
||||
|
|
@ -1,27 +0,0 @@
|
|||
/* Failure exit status
|
||||
|
||||
Copyright (C) 2002, 2003 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; see the file COPYING.
|
||||
If not, write to the Free Software Foundation,
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
||||
|
||||
#if HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#include "exitfail.h"
|
||||
#include "exit.h"
|
||||
|
||||
int volatile exit_failure = EXIT_FAILURE;
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
/* Failure exit status
|
||||
|
||||
Copyright (C) 2002 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; see the file COPYING.
|
||||
If not, write to the Free Software Foundation,
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
||||
|
||||
extern int volatile exit_failure;
|
||||
|
|
@ -1,72 +0,0 @@
|
|||
/* Invoke fopen, but avoid some glitches.
|
||||
Copyright (C) 2001, 2004 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, write to the Free Software Foundation,
|
||||
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
||||
|
||||
/* Written by Paul Eggert. */
|
||||
|
||||
#if HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#if HAVE_UNISTD_H
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
#include <unistd-safer.h>
|
||||
|
||||
#ifndef STDERR_FILENO
|
||||
# define STDERR_FILENO 2
|
||||
#endif
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <stdio-safer.h>
|
||||
|
||||
/* Like fopen, but do not return stdin, stdout, or stderr. */
|
||||
|
||||
FILE *
|
||||
fopen_safer (char const *file, char const *mode)
|
||||
{
|
||||
FILE *fp = fopen (file, mode);
|
||||
|
||||
if (fp)
|
||||
{
|
||||
int fd = fileno (fp);
|
||||
|
||||
if (0 <= fd && fd <= STDERR_FILENO)
|
||||
{
|
||||
int f = dup_safer (fd);
|
||||
|
||||
if (f < 0)
|
||||
{
|
||||
int e = errno;
|
||||
fclose (fp);
|
||||
errno = e;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (fclose (fp) != 0
|
||||
|| ! (fp = fdopen (f, mode)))
|
||||
{
|
||||
int e = errno;
|
||||
close (f);
|
||||
errno = e;
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return fp;
|
||||
}
|
||||
|
|
@ -1,68 +0,0 @@
|
|||
/* Convenience header for conditional use of GNU <libintl.h>.
|
||||
Copyright (C) 1995-1998, 2000-2002 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, write to the Free Software Foundation,
|
||||
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
||||
|
||||
#ifndef _LIBGETTEXT_H
|
||||
#define _LIBGETTEXT_H 1
|
||||
|
||||
/* NLS can be disabled through the configure --disable-nls option. */
|
||||
#if ENABLE_NLS
|
||||
|
||||
/* Get declarations of GNU message catalog functions. */
|
||||
# include <libintl.h>
|
||||
|
||||
#else
|
||||
|
||||
/* Solaris /usr/include/locale.h includes /usr/include/libintl.h, which
|
||||
chokes if dcgettext is defined as a macro. So include it now, to make
|
||||
later inclusions of <locale.h> a NOP. We don't include <libintl.h>
|
||||
as well because people using "gettext.h" will not include <libintl.h>,
|
||||
and also including <libintl.h> would fail on SunOS 4, whereas <locale.h>
|
||||
is OK. */
|
||||
#if defined(__sun)
|
||||
# include <locale.h>
|
||||
#endif
|
||||
|
||||
/* Disabled NLS.
|
||||
The casts to 'const char *' serve the purpose of producing warnings
|
||||
for invalid uses of the value returned from these functions.
|
||||
On pre-ANSI systems without 'const', the config.h file is supposed to
|
||||
contain "#define const". */
|
||||
# define gettext(Msgid) ((const char *) (Msgid))
|
||||
# define dgettext(Domainname, Msgid) ((const char *) (Msgid))
|
||||
# define dcgettext(Domainname, Msgid, Category) ((const char *) (Msgid))
|
||||
# define ngettext(Msgid1, Msgid2, N) \
|
||||
((N) == 1 ? (const char *) (Msgid1) : (const char *) (Msgid2))
|
||||
# define dngettext(Domainname, Msgid1, Msgid2, N) \
|
||||
((N) == 1 ? (const char *) (Msgid1) : (const char *) (Msgid2))
|
||||
# define dcngettext(Domainname, Msgid1, Msgid2, N, Category) \
|
||||
((N) == 1 ? (const char *) (Msgid1) : (const char *) (Msgid2))
|
||||
# define textdomain(Domainname) ((const char *) (Domainname))
|
||||
# define bindtextdomain(Domainname, Dirname) ((const char *) (Dirname))
|
||||
# define bind_textdomain_codeset(Domainname, Codeset) ((const char *) (Codeset))
|
||||
|
||||
#endif
|
||||
|
||||
/* A pseudo function call that serves as a marker for the automated
|
||||
extraction of messages, but does not call gettext(). The run-time
|
||||
translation is done at a different place in the code.
|
||||
The argument, String, should be a literal string. Concatenated strings
|
||||
and other string expressions won't work.
|
||||
The macro's expansion is not parenthesized, so that it is suitable as
|
||||
initializer for static 'char[]' or 'const char[]' variables. */
|
||||
#define gettext_noop(String) String
|
||||
|
||||
#endif /* _LIBGETTEXT_H */
|
||||
|
|
@ -1,76 +0,0 @@
|
|||
/* hard-locale.c -- Determine whether a locale is hard.
|
||||
|
||||
Copyright (C) 1997, 1998, 1999, 2002, 2003, 2004 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, write to the Free Software Foundation,
|
||||
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
||||
/* $FreeBSD$ */
|
||||
|
||||
#if HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#include "hard-locale.h"
|
||||
|
||||
#if HAVE_LOCALE_H
|
||||
# include <locale.h>
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
/* Return true if the current CATEGORY locale is hard, i.e. if you
|
||||
can't get away with assuming traditional C or POSIX behavior. */
|
||||
bool
|
||||
hard_locale (int category)
|
||||
{
|
||||
#if ! HAVE_SETLOCALE
|
||||
return false;
|
||||
#else
|
||||
|
||||
bool hard = true;
|
||||
char const *p = setlocale (category, NULL);
|
||||
|
||||
if (p)
|
||||
{
|
||||
# if defined(__FreeBSD__) || (defined __GLIBC__ && 2 <= __GLIBC__)
|
||||
if (strcmp (p, "C") == 0 || strcmp (p, "POSIX") == 0)
|
||||
hard = false;
|
||||
# else
|
||||
char *locale = malloc (strlen (p) + 1);
|
||||
if (locale)
|
||||
{
|
||||
strcpy (locale, p);
|
||||
|
||||
/* Temporarily set the locale to the "C" and "POSIX" locales
|
||||
to find their names, so that we can determine whether one
|
||||
or the other is the caller's locale. */
|
||||
if (((p = setlocale (category, "C"))
|
||||
&& strcmp (p, locale) == 0)
|
||||
|| ((p = setlocale (category, "POSIX"))
|
||||
&& strcmp (p, locale) == 0))
|
||||
hard = false;
|
||||
|
||||
/* Restore the caller's locale. */
|
||||
setlocale (category, locale);
|
||||
free (locale);
|
||||
}
|
||||
# endif
|
||||
}
|
||||
|
||||
return hard;
|
||||
|
||||
#endif
|
||||
}
|
||||
|
|
@ -1,26 +0,0 @@
|
|||
/* Determine whether a locale is hard.
|
||||
|
||||
Copyright (C) 1999, 2003, 2004 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, write to the Free Software Foundation,
|
||||
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
||||
|
||||
#ifndef HARD_LOCALE_H_
|
||||
# define HARD_LOCALE_H_ 1
|
||||
|
||||
# include <stdbool.h>
|
||||
|
||||
bool hard_locale (int);
|
||||
|
||||
#endif /* HARD_LOCALE_H_ */
|
||||
|
|
@ -1,485 +0,0 @@
|
|||
/* human.c -- print human readable file size
|
||||
|
||||
Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004
|
||||
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, write to the Free Software Foundation,
|
||||
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
||||
|
||||
/* Written by Paul Eggert and Larry McVoy. */
|
||||
|
||||
#if HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#include "human.h"
|
||||
|
||||
#ifndef SIZE_MAX
|
||||
# define SIZE_MAX ((size_t) -1)
|
||||
#endif
|
||||
#ifndef UINTMAX_MAX
|
||||
# define UINTMAX_MAX ((uintmax_t) -1)
|
||||
#endif
|
||||
|
||||
#if HAVE_LOCALE_H && HAVE_LOCALECONV
|
||||
# include <locale.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "gettext.h"
|
||||
#define _(msgid) gettext (msgid)
|
||||
|
||||
#include <argmatch.h>
|
||||
#include <error.h>
|
||||
#include <xstrtol.h>
|
||||
|
||||
/* The maximum length of a suffix like "KiB". */
|
||||
#define HUMAN_READABLE_SUFFIX_LENGTH_MAX 3
|
||||
|
||||
static const char power_letter[] =
|
||||
{
|
||||
0, /* not used */
|
||||
'K', /* kibi ('k' for kilo is a special case) */
|
||||
'M', /* mega or mebi */
|
||||
'G', /* giga or gibi */
|
||||
'T', /* tera or tebi */
|
||||
'P', /* peta or pebi */
|
||||
'E', /* exa or exbi */
|
||||
'Z', /* zetta or 2**70 */
|
||||
'Y' /* yotta or 2**80 */
|
||||
};
|
||||
|
||||
|
||||
/* If INEXACT_STYLE is not human_round_to_nearest, and if easily
|
||||
possible, adjust VALUE according to the style. */
|
||||
|
||||
static long double
|
||||
adjust_value (int inexact_style, long double value)
|
||||
{
|
||||
/* Do not use the floorl or ceill functions, as that would mean
|
||||
checking for their presence and possibly linking with the
|
||||
standard math library, which is a porting pain. So leave the
|
||||
value alone if it is too large to easily round. */
|
||||
if (inexact_style != human_round_to_nearest && value < UINTMAX_MAX)
|
||||
{
|
||||
uintmax_t u = value;
|
||||
value = u + (inexact_style == human_ceiling && u != value);
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
/* Group the digits of NUMBER according to the grouping rules of the
|
||||
current locale. NUMBER contains NUMBERLEN digits. Modify the
|
||||
bytes pointed to by NUMBER in place, subtracting 1 from NUMBER for
|
||||
each byte inserted. Return the starting address of the modified
|
||||
number.
|
||||
|
||||
To group the digits, use GROUPING and THOUSANDS_SEP as in `struct
|
||||
lconv' from <locale.h>. */
|
||||
|
||||
static char *
|
||||
group_number (char *number, size_t numberlen,
|
||||
char const *grouping, char const *thousands_sep)
|
||||
{
|
||||
register char *d;
|
||||
size_t grouplen = SIZE_MAX;
|
||||
size_t thousands_seplen = strlen (thousands_sep);
|
||||
size_t i = numberlen;
|
||||
|
||||
/* The maximum possible value for NUMBERLEN is the number of digits
|
||||
in the square of the largest uintmax_t, so double the size of
|
||||
uintmax_t before converting to a bound. 302 / 1000 is ceil
|
||||
(log10 (2.0)). Add 1 for integer division truncation. */
|
||||
char buf[2 * sizeof (uintmax_t) * CHAR_BIT * 302 / 1000 + 1];
|
||||
|
||||
memcpy (buf, number, numberlen);
|
||||
d = number + numberlen;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
unsigned char g = *grouping;
|
||||
|
||||
if (g)
|
||||
{
|
||||
grouplen = g < CHAR_MAX ? g : i;
|
||||
grouping++;
|
||||
}
|
||||
|
||||
if (i < grouplen)
|
||||
grouplen = i;
|
||||
|
||||
d -= grouplen;
|
||||
i -= grouplen;
|
||||
memcpy (d, buf + i, grouplen);
|
||||
if (i == 0)
|
||||
return d;
|
||||
|
||||
d -= thousands_seplen;
|
||||
memcpy (d, thousands_sep, thousands_seplen);
|
||||
}
|
||||
}
|
||||
|
||||
/* Convert N to a human readable format in BUF, using the options OPTS.
|
||||
|
||||
N is expressed in units of FROM_BLOCK_SIZE. FROM_BLOCK_SIZE must
|
||||
be nonnegative.
|
||||
|
||||
Use units of TO_BLOCK_SIZE in the output number. TO_BLOCK_SIZE
|
||||
must be positive.
|
||||
|
||||
Use (OPTS & (human_round_to_nearest | human_floor | human_ceiling))
|
||||
to determine whether to take the ceiling or floor of any result
|
||||
that cannot be expressed exactly.
|
||||
|
||||
If (OPTS & human_group_digits), group the thousands digits
|
||||
according to the locale, e.g., `1,000,000' in an American English
|
||||
locale.
|
||||
|
||||
If (OPTS & human_autoscale), deduce the output block size
|
||||
automatically; TO_BLOCK_SIZE must be 1 but it has no effect on the
|
||||
output. Use powers of 1024 if (OPTS & human_base_1024), and powers
|
||||
of 1000 otherwise. For example, assuming powers of 1024, 8500
|
||||
would be converted to 8.3, 133456345 to 127, 56990456345 to 53, and
|
||||
so on. Numbers smaller than the power aren't modified.
|
||||
human_autoscale is normally used together with human_SI.
|
||||
|
||||
If (OPTS & human_SI), append an SI prefix indicating which power is
|
||||
being used. If in addition (OPTS & human_B), append "B" (if base
|
||||
1000) or "iB" (if base 1024) to the SI prefix. When ((OPTS &
|
||||
human_SI) && ! (OPTS & human_autoscale)), TO_BLOCK_SIZE must be a
|
||||
power of 1024 or of 1000, depending on (OPTS &
|
||||
human_base_1024). */
|
||||
|
||||
char *
|
||||
human_readable (uintmax_t n, char *buf, int opts,
|
||||
uintmax_t from_block_size, uintmax_t to_block_size)
|
||||
{
|
||||
int inexact_style =
|
||||
opts & (human_round_to_nearest | human_floor | human_ceiling);
|
||||
unsigned int base = opts & human_base_1024 ? 1024 : 1000;
|
||||
uintmax_t amt;
|
||||
int tenths;
|
||||
int exponent = -1;
|
||||
int exponent_max = sizeof power_letter - 1;
|
||||
char *p;
|
||||
char *psuffix;
|
||||
char const *integerlim;
|
||||
|
||||
/* 0 means adjusted N == AMT.TENTHS;
|
||||
1 means AMT.TENTHS < adjusted N < AMT.TENTHS + 0.05;
|
||||
2 means adjusted N == AMT.TENTHS + 0.05;
|
||||
3 means AMT.TENTHS + 0.05 < adjusted N < AMT.TENTHS + 0.1. */
|
||||
int rounding;
|
||||
|
||||
char const *decimal_point = ".";
|
||||
size_t decimal_pointlen = 1;
|
||||
char const *grouping = "";
|
||||
char const *thousands_sep = "";
|
||||
#if HAVE_LOCALE_H && HAVE_LOCALECONV
|
||||
struct lconv const *l = localeconv ();
|
||||
size_t pointlen = strlen (l->decimal_point);
|
||||
if (0 < pointlen && pointlen <= MB_LEN_MAX)
|
||||
{
|
||||
decimal_point = l->decimal_point;
|
||||
decimal_pointlen = pointlen;
|
||||
}
|
||||
grouping = l->grouping;
|
||||
if (strlen (l->thousands_sep) <= MB_LEN_MAX)
|
||||
thousands_sep = l->thousands_sep;
|
||||
#endif
|
||||
|
||||
psuffix = buf + LONGEST_HUMAN_READABLE - HUMAN_READABLE_SUFFIX_LENGTH_MAX;
|
||||
p = psuffix;
|
||||
|
||||
/* Adjust AMT out of FROM_BLOCK_SIZE units and into TO_BLOCK_SIZE
|
||||
units. If this can be done exactly with integer arithmetic, do
|
||||
not use floating point operations. */
|
||||
if (to_block_size <= from_block_size)
|
||||
{
|
||||
if (from_block_size % to_block_size == 0)
|
||||
{
|
||||
uintmax_t multiplier = from_block_size / to_block_size;
|
||||
amt = n * multiplier;
|
||||
if (amt / multiplier == n)
|
||||
{
|
||||
tenths = 0;
|
||||
rounding = 0;
|
||||
goto use_integer_arithmetic;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (from_block_size != 0 && to_block_size % from_block_size == 0)
|
||||
{
|
||||
uintmax_t divisor = to_block_size / from_block_size;
|
||||
uintmax_t r10 = (n % divisor) * 10;
|
||||
uintmax_t r2 = (r10 % divisor) * 2;
|
||||
amt = n / divisor;
|
||||
tenths = r10 / divisor;
|
||||
rounding = r2 < divisor ? 0 < r2 : 2 + (divisor < r2);
|
||||
goto use_integer_arithmetic;
|
||||
}
|
||||
|
||||
{
|
||||
/* Either the result cannot be computed easily using uintmax_t,
|
||||
or from_block_size is zero. Fall back on floating point.
|
||||
FIXME: This can yield answers that are slightly off. */
|
||||
|
||||
long double dto_block_size = to_block_size;
|
||||
long double damt = n * (from_block_size / dto_block_size);
|
||||
size_t buflen;
|
||||
size_t nonintegerlen;
|
||||
|
||||
if (! (opts & human_autoscale))
|
||||
{
|
||||
sprintf (buf, "%.0Lf", adjust_value (inexact_style, damt));
|
||||
buflen = strlen (buf);
|
||||
nonintegerlen = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
long double e = 1;
|
||||
exponent = 0;
|
||||
|
||||
do
|
||||
{
|
||||
e *= base;
|
||||
exponent++;
|
||||
}
|
||||
while (e * base <= damt && exponent < exponent_max);
|
||||
|
||||
damt /= e;
|
||||
|
||||
sprintf (buf, "%.1Lf", adjust_value (inexact_style, damt));
|
||||
buflen = strlen (buf);
|
||||
nonintegerlen = decimal_pointlen + 1;
|
||||
|
||||
if (1 + nonintegerlen + ! (opts & human_base_1024) < buflen
|
||||
|| ((opts & human_suppress_point_zero)
|
||||
&& buf[buflen - 1] == '0'))
|
||||
{
|
||||
sprintf (buf, "%.0Lf",
|
||||
adjust_value (inexact_style, damt * 10) / 10);
|
||||
buflen = strlen (buf);
|
||||
nonintegerlen = 0;
|
||||
}
|
||||
}
|
||||
|
||||
p = psuffix - buflen;
|
||||
memmove (p, buf, buflen);
|
||||
integerlim = p + buflen - nonintegerlen;
|
||||
}
|
||||
goto do_grouping;
|
||||
|
||||
use_integer_arithmetic:
|
||||
{
|
||||
/* The computation can be done exactly, with integer arithmetic.
|
||||
|
||||
Use power of BASE notation if requested and if adjusted AMT is
|
||||
large enough. */
|
||||
|
||||
if (opts & human_autoscale)
|
||||
{
|
||||
exponent = 0;
|
||||
|
||||
if (base <= amt)
|
||||
{
|
||||
do
|
||||
{
|
||||
unsigned int r10 = (amt % base) * 10 + tenths;
|
||||
unsigned int r2 = (r10 % base) * 2 + (rounding >> 1);
|
||||
amt /= base;
|
||||
tenths = r10 / base;
|
||||
rounding = (r2 < base
|
||||
? (r2 + rounding) != 0
|
||||
: 2 + (base < r2 + rounding));
|
||||
exponent++;
|
||||
}
|
||||
while (base <= amt && exponent < exponent_max);
|
||||
|
||||
if (amt < 10)
|
||||
{
|
||||
if (inexact_style == human_round_to_nearest
|
||||
? 2 < rounding + (tenths & 1)
|
||||
: inexact_style == human_ceiling && 0 < rounding)
|
||||
{
|
||||
tenths++;
|
||||
rounding = 0;
|
||||
|
||||
if (tenths == 10)
|
||||
{
|
||||
amt++;
|
||||
tenths = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (amt < 10
|
||||
&& (tenths || ! (opts & human_suppress_point_zero)))
|
||||
{
|
||||
*--p = '0' + tenths;
|
||||
p -= decimal_pointlen;
|
||||
memcpy (p, decimal_point, decimal_pointlen);
|
||||
tenths = rounding = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (inexact_style == human_round_to_nearest
|
||||
? 5 < tenths + (0 < rounding + (amt & 1))
|
||||
: inexact_style == human_ceiling && 0 < tenths + rounding)
|
||||
{
|
||||
amt++;
|
||||
|
||||
if ((opts & human_autoscale)
|
||||
&& amt == base && exponent < exponent_max)
|
||||
{
|
||||
exponent++;
|
||||
if (! (opts & human_suppress_point_zero))
|
||||
{
|
||||
*--p = '0';
|
||||
p -= decimal_pointlen;
|
||||
memcpy (p, decimal_point, decimal_pointlen);
|
||||
}
|
||||
amt = 1;
|
||||
}
|
||||
}
|
||||
|
||||
integerlim = p;
|
||||
|
||||
do
|
||||
{
|
||||
int digit = amt % 10;
|
||||
*--p = digit + '0';
|
||||
}
|
||||
while ((amt /= 10) != 0);
|
||||
}
|
||||
|
||||
do_grouping:
|
||||
if (opts & human_group_digits)
|
||||
p = group_number (p, integerlim - p, grouping, thousands_sep);
|
||||
|
||||
if (opts & human_SI)
|
||||
{
|
||||
if (exponent < 0)
|
||||
{
|
||||
uintmax_t power;
|
||||
exponent = 0;
|
||||
for (power = 1; power < to_block_size; power *= base)
|
||||
if (++exponent == exponent_max)
|
||||
break;
|
||||
}
|
||||
|
||||
if (exponent)
|
||||
*psuffix++ = (! (opts & human_base_1024) && exponent == 1
|
||||
? 'k'
|
||||
: power_letter[exponent]);
|
||||
|
||||
if (opts & human_B)
|
||||
{
|
||||
if ((opts & human_base_1024) && exponent)
|
||||
*psuffix++ = 'i';
|
||||
*psuffix++ = 'B';
|
||||
}
|
||||
}
|
||||
|
||||
*psuffix = '\0';
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
|
||||
/* The default block size used for output. This number may change in
|
||||
the future as disks get larger. */
|
||||
#ifndef DEFAULT_BLOCK_SIZE
|
||||
# define DEFAULT_BLOCK_SIZE 1024
|
||||
#endif
|
||||
|
||||
static char const *const block_size_args[] = { "human-readable", "si", 0 };
|
||||
static int const block_size_opts[] =
|
||||
{
|
||||
human_autoscale + human_SI + human_base_1024,
|
||||
human_autoscale + human_SI
|
||||
};
|
||||
|
||||
static uintmax_t
|
||||
default_block_size (void)
|
||||
{
|
||||
return getenv ("POSIXLY_CORRECT") ? 512 : DEFAULT_BLOCK_SIZE;
|
||||
}
|
||||
|
||||
static strtol_error
|
||||
humblock (char const *spec, uintmax_t *block_size, int *options)
|
||||
{
|
||||
int i;
|
||||
int opts = 0;
|
||||
|
||||
if (! spec
|
||||
&& ! (spec = getenv ("BLOCK_SIZE"))
|
||||
&& ! (spec = getenv ("BLOCKSIZE")))
|
||||
*block_size = default_block_size ();
|
||||
else
|
||||
{
|
||||
if (*spec == '\'')
|
||||
{
|
||||
opts |= human_group_digits;
|
||||
spec++;
|
||||
}
|
||||
|
||||
if (0 <= (i = ARGMATCH (spec, block_size_args, block_size_opts)))
|
||||
{
|
||||
opts |= block_size_opts[i];
|
||||
*block_size = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
char *ptr;
|
||||
strtol_error e = xstrtoumax (spec, &ptr, 0, block_size,
|
||||
"eEgGkKmMpPtTyYzZ0");
|
||||
if (e != LONGINT_OK)
|
||||
return e;
|
||||
for (; ! ('0' <= *spec && *spec <= '9'); spec++)
|
||||
if (spec == ptr)
|
||||
{
|
||||
opts |= human_SI;
|
||||
if (ptr[-1] == 'B')
|
||||
opts |= human_B;
|
||||
if (ptr[-1] != 'B' || ptr[-2] == 'i')
|
||||
opts |= human_base_1024;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
*options = opts;
|
||||
return LONGINT_OK;
|
||||
}
|
||||
|
||||
int
|
||||
human_options (char const *spec, bool report_errors, uintmax_t *block_size)
|
||||
{
|
||||
int opts;
|
||||
strtol_error e = humblock (spec, block_size, &opts);
|
||||
if (*block_size == 0)
|
||||
{
|
||||
*block_size = default_block_size ();
|
||||
e = LONGINT_INVALID;
|
||||
}
|
||||
if (e != LONGINT_OK && report_errors)
|
||||
STRTOL_FATAL_ERROR (spec, _("block size"), e);
|
||||
return opts;
|
||||
}
|
||||
|
|
@ -1,88 +0,0 @@
|
|||
/* human.h -- print human readable file size
|
||||
|
||||
Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004
|
||||
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, write to the Free Software Foundation,
|
||||
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
||||
|
||||
/* Written by Paul Eggert and Larry McVoy. */
|
||||
|
||||
#ifndef HUMAN_H_
|
||||
# define HUMAN_H_ 1
|
||||
|
||||
# if HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
# endif
|
||||
|
||||
# include <limits.h>
|
||||
# include <stdbool.h>
|
||||
|
||||
# if HAVE_STDINT_H
|
||||
# include <stdint.h>
|
||||
# endif
|
||||
# if HAVE_UNISTD_H
|
||||
# include <unistd.h>
|
||||
# endif
|
||||
|
||||
/* A conservative bound on the maximum length of a human-readable string.
|
||||
The output can be the square of the largest uintmax_t, so double
|
||||
its size before converting to a bound.
|
||||
302 / 1000 is ceil (log10 (2.0)). Add 1 for integer division truncation.
|
||||
Also, the output can have a thousands separator between every digit,
|
||||
so multiply by MB_LEN_MAX + 1 and then subtract MB_LEN_MAX.
|
||||
Finally, append 3, the maximum length of a suffix. */
|
||||
# define LONGEST_HUMAN_READABLE \
|
||||
((2 * sizeof (uintmax_t) * CHAR_BIT * 302 / 1000 + 1) * (MB_LEN_MAX + 1) \
|
||||
- MB_LEN_MAX + 3)
|
||||
|
||||
/* Options for human_readable. */
|
||||
enum
|
||||
{
|
||||
/* Unless otherwise specified these options may be ORed together. */
|
||||
|
||||
/* The following three options are mutually exclusive. */
|
||||
/* Round to plus infinity (default). */
|
||||
human_ceiling = 0,
|
||||
/* Round to nearest, ties to even. */
|
||||
human_round_to_nearest = 1,
|
||||
/* Round to minus infinity. */
|
||||
human_floor = 2,
|
||||
|
||||
/* Group digits together, e.g. `1,000,000'. This uses the
|
||||
locale-defined grouping; the traditional C locale does not group,
|
||||
so this has effect only if some other locale is in use. */
|
||||
human_group_digits = 4,
|
||||
|
||||
/* When autoscaling, suppress ".0" at end. */
|
||||
human_suppress_point_zero = 8,
|
||||
|
||||
/* Scale output and use SI-style units, ignoring the output block size. */
|
||||
human_autoscale = 16,
|
||||
|
||||
/* Prefer base 1024 to base 1000. */
|
||||
human_base_1024 = 32,
|
||||
|
||||
/* Append SI prefix, e.g. "k" or "M". */
|
||||
human_SI = 64,
|
||||
|
||||
/* Append "B" (if base 1000) or "iB" (if base 1024) to SI prefix. */
|
||||
human_B = 128
|
||||
};
|
||||
|
||||
char *human_readable (uintmax_t, char *, int, uintmax_t, uintmax_t);
|
||||
|
||||
int human_options (char const *, bool, uintmax_t *);
|
||||
|
||||
#endif /* HUMAN_H_ */
|
||||
|
|
@ -1,49 +0,0 @@
|
|||
/* inttostr.c -- convert integers to printable strings
|
||||
|
||||
Copyright (C) 2001 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, write to the Free Software Foundation,
|
||||
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
||||
|
||||
/* Written by Paul Eggert */
|
||||
|
||||
#include "inttostr.h"
|
||||
|
||||
/* Convert I to a printable string in BUF, which must be at least
|
||||
INT_BUFSIZE_BOUND (INTTYPE) bytes long. Return the address of the
|
||||
printable string, which need not start at BUF. */
|
||||
|
||||
char *
|
||||
inttostr (inttype i, char *buf)
|
||||
{
|
||||
char *p = buf + INT_STRLEN_BOUND (inttype);
|
||||
*p = 0;
|
||||
|
||||
if (i < 0)
|
||||
{
|
||||
do
|
||||
*--p = '0' - i % 10;
|
||||
while ((i /= 10) != 0);
|
||||
|
||||
*--p = '-';
|
||||
}
|
||||
else
|
||||
{
|
||||
do
|
||||
*--p = '0' + i % 10;
|
||||
while ((i /= 10) != 0);
|
||||
}
|
||||
|
||||
return p;
|
||||
}
|
||||
|
|
@ -1,47 +0,0 @@
|
|||
/* inttostr.h -- convert integers to printable strings
|
||||
|
||||
Copyright (C) 2001, 2002, 2003, 2004 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, write to the Free Software Foundation,
|
||||
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
||||
|
||||
/* Written by Paul Eggert */
|
||||
|
||||
#if HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#if HAVE_INTTYPES_H
|
||||
# include <inttypes.h>
|
||||
#endif
|
||||
#if HAVE_STDINT_H
|
||||
# include <stdint.h>
|
||||
#endif
|
||||
|
||||
#include <limits.h>
|
||||
|
||||
#if HAVE_SYS_TYPES_H
|
||||
# include <sys/types.h>
|
||||
#endif
|
||||
|
||||
/* Upper bound on the string length of an integer converted to string.
|
||||
302 / 1000 is ceil (log10 (2.0)). Subtract 1 for the sign bit;
|
||||
add 1 for integer division truncation; add 1 more for a minus sign. */
|
||||
#define INT_STRLEN_BOUND(t) ((sizeof (t) * CHAR_BIT - 1) * 302 / 1000 + 2)
|
||||
|
||||
#define INT_BUFSIZE_BOUND(t) (INT_STRLEN_BOUND (t) + 1)
|
||||
|
||||
char *offtostr (off_t, char *);
|
||||
char *imaxtostr (intmax_t, char *);
|
||||
char *umaxtostr (uintmax_t, char *);
|
||||
|
|
@ -1,91 +0,0 @@
|
|||
/* Utility to accept --help and --version options as unobtrusively as possible.
|
||||
|
||||
Copyright (C) 1993, 1994, 1998, 1999, 2000, 2002, 2003, 2004 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, write to the Free Software Foundation,
|
||||
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
||||
|
||||
/* Written by Jim Meyering. */
|
||||
|
||||
#if HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
/* Specification. */
|
||||
#include "long-options.h"
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <getopt.h>
|
||||
|
||||
#include "version-etc.h"
|
||||
|
||||
static struct option const long_options[] =
|
||||
{
|
||||
{"help", no_argument, 0, 'h'},
|
||||
{"version", no_argument, 0, 'v'},
|
||||
{0, 0, 0, 0}
|
||||
};
|
||||
|
||||
/* Process long options --help and --version, but only if argc == 2.
|
||||
Be careful not to gobble up `--'. */
|
||||
|
||||
void
|
||||
parse_long_options (int argc,
|
||||
char **argv,
|
||||
const char *command_name,
|
||||
const char *package,
|
||||
const char *version,
|
||||
void (*usage_func) (int),
|
||||
/* const char *author1, ...*/ ...)
|
||||
{
|
||||
int c;
|
||||
int saved_opterr;
|
||||
|
||||
saved_opterr = opterr;
|
||||
|
||||
/* Don't print an error message for unrecognized options. */
|
||||
opterr = 0;
|
||||
|
||||
if (argc == 2
|
||||
&& (c = getopt_long (argc, argv, "+", long_options, NULL)) != -1)
|
||||
{
|
||||
switch (c)
|
||||
{
|
||||
case 'h':
|
||||
(*usage_func) (EXIT_SUCCESS);
|
||||
|
||||
case 'v':
|
||||
{
|
||||
va_list authors;
|
||||
va_start (authors, usage_func);
|
||||
version_etc_va (stdout, command_name, package, version, authors);
|
||||
exit (0);
|
||||
}
|
||||
|
||||
default:
|
||||
/* Don't process any other long-named options. */
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Restore previous value. */
|
||||
opterr = saved_opterr;
|
||||
|
||||
/* Reset this to zero so that getopt internals get initialized from
|
||||
the probably-new parameters when/if getopt is called later. */
|
||||
optind = 0;
|
||||
}
|
||||
|
|
@ -1,26 +0,0 @@
|
|||
/* long-options.h -- declaration for --help- and --version-handling function.
|
||||
Copyright (C) 1993, 1994, 1998, 1999, 2003 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, write to the Free Software Foundation,
|
||||
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
||||
|
||||
/* Written by Jim Meyering. */
|
||||
|
||||
void parse_long_options (int _argc,
|
||||
char **_argv,
|
||||
const char *_command_name,
|
||||
const char *_package,
|
||||
const char *_version,
|
||||
void (*_usage) (int),
|
||||
/* const char *author1, ...*/ ...);
|
||||
|
|
@ -1,85 +0,0 @@
|
|||
/* Locale-specific memory comparison.
|
||||
Copyright (C) 1999, 2002, 2003, 2004 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, write to the Free Software Foundation,
|
||||
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
||||
|
||||
/* Contributed by Paul Eggert <eggert@twinsun.com>. */
|
||||
|
||||
#if HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#include "memcoll.h"
|
||||
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
|
||||
/* Compare S1 (with length S1LEN) and S2 (with length S2LEN) according
|
||||
to the LC_COLLATE locale. S1 and S2 do not overlap, and are not
|
||||
adjacent. Perhaps temporarily modify the bytes after S1 and S2,
|
||||
but restore their original contents before returning. Set errno to an
|
||||
error number if there is an error, and to zero otherwise. */
|
||||
int
|
||||
memcoll (char *s1, size_t s1len, char *s2, size_t s2len)
|
||||
{
|
||||
int diff;
|
||||
|
||||
#if HAVE_STRCOLL
|
||||
|
||||
char n1 = s1[s1len];
|
||||
char n2 = s2[s2len];
|
||||
|
||||
s1[s1len++] = '\0';
|
||||
s2[s2len++] = '\0';
|
||||
|
||||
while (! (errno = 0, (diff = strcoll (s1, s2)) || errno))
|
||||
{
|
||||
/* strcoll found no difference, but perhaps it was fooled by NUL
|
||||
characters in the data. Work around this problem by advancing
|
||||
past the NUL chars. */
|
||||
size_t size1 = strlen (s1) + 1;
|
||||
size_t size2 = strlen (s2) + 1;
|
||||
s1 += size1;
|
||||
s2 += size2;
|
||||
s1len -= size1;
|
||||
s2len -= size2;
|
||||
|
||||
if (s1len == 0)
|
||||
{
|
||||
if (s2len != 0)
|
||||
diff = -1;
|
||||
break;
|
||||
}
|
||||
else if (s2len == 0)
|
||||
{
|
||||
diff = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
s1[s1len - 1] = n1;
|
||||
s2[s2len - 1] = n2;
|
||||
|
||||
#else
|
||||
|
||||
diff = memcmp (s1, s2, s1len < s2len ? s1len : s2len);
|
||||
if (! diff)
|
||||
diff = s1len < s2len ? -1 : s1len != s2len;
|
||||
errno = 0;
|
||||
|
||||
#endif
|
||||
|
||||
return diff;
|
||||
}
|
||||
|
|
@ -1,28 +0,0 @@
|
|||
/* Locale-specific memory comparison.
|
||||
|
||||
Copyright (C) 1999, 2003 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, write to the Free Software Foundation,
|
||||
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
||||
|
||||
/* Contributed by Paul Eggert <eggert@twinsun.com>. */
|
||||
|
||||
#ifndef MEMCOLL_H_
|
||||
# define MEMCOLL_H_ 1
|
||||
|
||||
# include <stddef.h>
|
||||
|
||||
int memcoll (char *, size_t, char *, size_t);
|
||||
|
||||
#endif /* MEMCOLL_H_ */
|
||||
|
|
@ -1,54 +0,0 @@
|
|||
/* Define PATH_MAX somehow. Requires sys/types.h.
|
||||
Copyright (C) 1992, 1999, 2001, 2003 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, write to the Free Software Foundation,
|
||||
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
||||
|
||||
#ifndef _PATHMAX_H
|
||||
# define _PATHMAX_H
|
||||
|
||||
# if HAVE_UNISTD_H
|
||||
# include <unistd.h>
|
||||
# endif
|
||||
|
||||
/* Non-POSIX BSD systems might have gcc's limits.h, which doesn't define
|
||||
PATH_MAX but might cause redefinition warnings when sys/param.h is
|
||||
later included (as on MORE/BSD 4.3). */
|
||||
# if defined _POSIX_VERSION || !defined __GNUC__
|
||||
# include <limits.h>
|
||||
# endif
|
||||
|
||||
# ifndef _POSIX_PATH_MAX
|
||||
# define _POSIX_PATH_MAX 255
|
||||
# endif
|
||||
|
||||
# if !defined PATH_MAX && defined _PC_PATH_MAX
|
||||
# define PATH_MAX (pathconf ("/", _PC_PATH_MAX) < 1 ? 1024 \
|
||||
: pathconf ("/", _PC_PATH_MAX))
|
||||
# endif
|
||||
|
||||
/* Don't include sys/param.h if it already has been. */
|
||||
# if defined HAVE_SYS_PARAM_H && !defined PATH_MAX && !defined MAXPATHLEN
|
||||
# include <sys/param.h>
|
||||
# endif
|
||||
|
||||
# if !defined PATH_MAX && defined MAXPATHLEN
|
||||
# define PATH_MAX MAXPATHLEN
|
||||
# endif
|
||||
|
||||
# ifndef PATH_MAX
|
||||
# define PATH_MAX _POSIX_PATH_MAX
|
||||
# endif
|
||||
|
||||
#endif /* _PATHMAX_H */
|
||||
|
|
@ -1,307 +0,0 @@
|
|||
/* Calculate the size of physical memory.
|
||||
Copyright (C) 2000, 2001, 2003 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, write to the Free Software Foundation,
|
||||
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
||||
|
||||
/* Written by Paul Eggert. */
|
||||
|
||||
#if HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#include "physmem.h"
|
||||
|
||||
#if HAVE_UNISTD_H
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
#if HAVE_SYS_PSTAT_H
|
||||
# include <sys/pstat.h>
|
||||
#endif
|
||||
|
||||
#if HAVE_SYS_SYSMP_H
|
||||
# include <sys/sysmp.h>
|
||||
#endif
|
||||
|
||||
#if HAVE_SYS_SYSINFO_H && HAVE_MACHINE_HAL_SYSINFO_H
|
||||
# include <sys/sysinfo.h>
|
||||
# include <machine/hal_sysinfo.h>
|
||||
#endif
|
||||
|
||||
#if HAVE_SYS_TABLE_H
|
||||
# include <sys/table.h>
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#if HAVE_SYS_PARAM_H
|
||||
# include <sys/param.h>
|
||||
#endif
|
||||
|
||||
#if HAVE_SYS_SYSCTL_H
|
||||
# include <sys/sysctl.h>
|
||||
#endif
|
||||
|
||||
#if HAVE_SYS_SYSTEMCFG_H
|
||||
# include <sys/systemcfg.h>
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
# define WIN32_LEAN_AND_MEAN
|
||||
# include <windows.h>
|
||||
/* MEMORYSTATUSEX is missing from older windows headers, so define
|
||||
a local replacement. */
|
||||
typedef struct
|
||||
{
|
||||
DWORD dwLength;
|
||||
DWORD dwMemoryLoad;
|
||||
DWORDLONG ullTotalPhys;
|
||||
DWORDLONG ullAvailPhys;
|
||||
DWORDLONG ullTotalPageFile;
|
||||
DWORDLONG ullAvailPageFile;
|
||||
DWORDLONG ullTotalVirtual;
|
||||
DWORDLONG ullAvailVirtual;
|
||||
DWORDLONG ullAvailExtendedVirtual;
|
||||
} lMEMORYSTATUSEX;
|
||||
typedef WINBOOL (WINAPI *PFN_MS_EX) (lMEMORYSTATUSEX*);
|
||||
#endif
|
||||
|
||||
#define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0]))
|
||||
|
||||
/* Return the total amount of physical memory. */
|
||||
double
|
||||
physmem_total (void)
|
||||
{
|
||||
#if defined _SC_PHYS_PAGES && defined _SC_PAGESIZE
|
||||
{ /* This works on linux-gnu, solaris2 and cygwin. */
|
||||
double pages = sysconf (_SC_PHYS_PAGES);
|
||||
double pagesize = sysconf (_SC_PAGESIZE);
|
||||
if (0 <= pages && 0 <= pagesize)
|
||||
return pages * pagesize;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if HAVE_PSTAT_GETSTATIC
|
||||
{ /* This works on hpux11. */
|
||||
struct pst_static pss;
|
||||
if (0 <= pstat_getstatic (&pss, sizeof pss, 1, 0))
|
||||
{
|
||||
double pages = pss.physical_memory;
|
||||
double pagesize = pss.page_size;
|
||||
if (0 <= pages && 0 <= pagesize)
|
||||
return pages * pagesize;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if HAVE_SYSMP && defined MP_SAGET && defined MPSA_RMINFO && defined _SC_PAGESIZE
|
||||
{ /* This works on irix6. */
|
||||
struct rminfo realmem;
|
||||
if (sysmp (MP_SAGET, MPSA_RMINFO, &realmem, sizeof realmem) == 0)
|
||||
{
|
||||
double pagesize = sysconf (_SC_PAGESIZE);
|
||||
double pages = realmem.physmem;
|
||||
if (0 <= pages && 0 <= pagesize)
|
||||
return pages * pagesize;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if HAVE_GETSYSINFO && defined GSI_PHYSMEM
|
||||
{ /* This works on Tru64 UNIX V4/5. */
|
||||
int physmem;
|
||||
|
||||
if (getsysinfo (GSI_PHYSMEM, (caddr_t) &physmem, sizeof (physmem),
|
||||
NULL, NULL, NULL) == 1)
|
||||
{
|
||||
double kbytes = physmem;
|
||||
|
||||
if (0 <= kbytes)
|
||||
return kbytes * 1024.0;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if HAVE_SYSCTL && defined HW_PHYSMEM
|
||||
{ /* This works on *bsd and darwin. */
|
||||
unsigned int physmem;
|
||||
size_t len = sizeof physmem;
|
||||
static int mib[2] = { CTL_HW, HW_PHYSMEM };
|
||||
|
||||
if (sysctl (mib, ARRAY_SIZE (mib), &physmem, &len, NULL, 0) == 0
|
||||
&& len == sizeof (physmem))
|
||||
return (double) physmem;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if HAVE__SYSTEM_CONFIGURATION
|
||||
/* This works on AIX. */
|
||||
return _system_configuration.physmem;
|
||||
#endif
|
||||
|
||||
#if defined _WIN32
|
||||
{ /* this works on windows */
|
||||
PFN_MS_EX pfnex;
|
||||
HMODULE h = GetModuleHandle ("kernel32.dll");
|
||||
|
||||
if (!h)
|
||||
return 0.0;
|
||||
|
||||
/* Use GlobalMemoryStatusEx if available. */
|
||||
if ((pfnex = (PFN_MS_EX) GetProcAddress (h, "GlobalMemoryStatusEx")))
|
||||
{
|
||||
lMEMORYSTATUSEX lms_ex;
|
||||
lms_ex.dwLength = sizeof lms_ex;
|
||||
if (!pfnex (&lms_ex))
|
||||
return 0.0;
|
||||
return (double) lms_ex.ullTotalPhys;
|
||||
}
|
||||
|
||||
/* Fall back to GlobalMemoryStatus which is always available.
|
||||
but returns wrong results for physical memory > 4GB. */
|
||||
else
|
||||
{
|
||||
MEMORYSTATUS ms;
|
||||
GlobalMemoryStatus (&ms);
|
||||
return (double) ms.dwTotalPhys;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Guess 64 MB. It's probably an older host, so guess small. */
|
||||
return 64 * 1024 * 1024;
|
||||
}
|
||||
|
||||
/* Return the amount of physical memory available. */
|
||||
double
|
||||
physmem_available (void)
|
||||
{
|
||||
#if defined _SC_AVPHYS_PAGES && defined _SC_PAGESIZE
|
||||
{ /* This works on linux-gnu, solaris2 and cygwin. */
|
||||
double pages = sysconf (_SC_AVPHYS_PAGES);
|
||||
double pagesize = sysconf (_SC_PAGESIZE);
|
||||
if (0 <= pages && 0 <= pagesize)
|
||||
return pages * pagesize;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if HAVE_PSTAT_GETSTATIC && HAVE_PSTAT_GETDYNAMIC
|
||||
{ /* This works on hpux11. */
|
||||
struct pst_static pss;
|
||||
struct pst_dynamic psd;
|
||||
if (0 <= pstat_getstatic (&pss, sizeof pss, 1, 0)
|
||||
&& 0 <= pstat_getdynamic (&psd, sizeof psd, 1, 0))
|
||||
{
|
||||
double pages = psd.psd_free;
|
||||
double pagesize = pss.page_size;
|
||||
if (0 <= pages && 0 <= pagesize)
|
||||
return pages * pagesize;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if HAVE_SYSMP && defined MP_SAGET && defined MPSA_RMINFO && defined _SC_PAGESIZE
|
||||
{ /* This works on irix6. */
|
||||
struct rminfo realmem;
|
||||
if (sysmp (MP_SAGET, MPSA_RMINFO, &realmem, sizeof realmem) == 0)
|
||||
{
|
||||
double pagesize = sysconf (_SC_PAGESIZE);
|
||||
double pages = realmem.availrmem;
|
||||
if (0 <= pages && 0 <= pagesize)
|
||||
return pages * pagesize;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if HAVE_TABLE && defined TBL_VMSTATS
|
||||
{ /* This works on Tru64 UNIX V4/5. */
|
||||
struct tbl_vmstats vmstats;
|
||||
|
||||
if (table (TBL_VMSTATS, 0, &vmstats, 1, sizeof (vmstats)) == 1)
|
||||
{
|
||||
double pages = vmstats.free_count;
|
||||
double pagesize = vmstats.pagesize;
|
||||
|
||||
if (0 <= pages && 0 <= pagesize)
|
||||
return pages * pagesize;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if HAVE_SYSCTL && defined HW_USERMEM
|
||||
{ /* This works on *bsd and darwin. */
|
||||
unsigned int usermem;
|
||||
size_t len = sizeof usermem;
|
||||
static int mib[2] = { CTL_HW, HW_USERMEM };
|
||||
|
||||
if (sysctl (mib, ARRAY_SIZE (mib), &usermem, &len, NULL, 0) == 0
|
||||
&& len == sizeof (usermem))
|
||||
return (double) usermem;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined _WIN32
|
||||
{ /* this works on windows */
|
||||
PFN_MS_EX pfnex;
|
||||
HMODULE h = GetModuleHandle ("kernel32.dll");
|
||||
|
||||
if (!h)
|
||||
return 0.0;
|
||||
|
||||
/* Use GlobalMemoryStatusEx if available. */
|
||||
if ((pfnex = (PFN_MS_EX) GetProcAddress (h, "GlobalMemoryStatusEx")))
|
||||
{
|
||||
lMEMORYSTATUSEX lms_ex;
|
||||
lms_ex.dwLength = sizeof lms_ex;
|
||||
if (!pfnex (&lms_ex))
|
||||
return 0.0;
|
||||
return (double) lms_ex.ullAvailPhys;
|
||||
}
|
||||
|
||||
/* Fall back to GlobalMemoryStatus which is always available.
|
||||
but returns wrong results for physical memory > 4GB */
|
||||
else
|
||||
{
|
||||
MEMORYSTATUS ms;
|
||||
GlobalMemoryStatus (&ms);
|
||||
return (double) ms.dwAvailPhys;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Guess 25% of physical memory. */
|
||||
return physmem_total () / 4;
|
||||
}
|
||||
|
||||
|
||||
#if DEBUG
|
||||
|
||||
# include <stdio.h>
|
||||
# include <stdlib.h>
|
||||
|
||||
int
|
||||
main (void)
|
||||
{
|
||||
printf ("%12.f %12.f\n", physmem_total (), physmem_available ());
|
||||
exit (0);
|
||||
}
|
||||
|
||||
#endif /* DEBUG */
|
||||
|
||||
/*
|
||||
Local Variables:
|
||||
compile-command: "gcc -DDEBUG -DHAVE_CONFIG_H -I.. -g -O -Wall -W physmem.c"
|
||||
End:
|
||||
*/
|
||||
|
|
@ -1,27 +0,0 @@
|
|||
/* Calculate the size of physical memory.
|
||||
|
||||
Copyright (C) 2000, 2003 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, write to the Free Software Foundation,
|
||||
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
||||
|
||||
/* Written by Paul Eggert. */
|
||||
|
||||
#ifndef PHYSMEM_H_
|
||||
# define PHYSMEM_H_ 1
|
||||
|
||||
double physmem_total (void);
|
||||
double physmem_available (void);
|
||||
|
||||
#endif /* PHYSMEM_H_ */
|
||||
|
|
@ -1,59 +0,0 @@
|
|||
/* Which POSIX version to conform to, for utilities.
|
||||
|
||||
Copyright (C) 2002, 2003, 2004 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, write to the Free Software Foundation,
|
||||
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
||||
|
||||
/* Written by Paul Eggert. */
|
||||
|
||||
#if HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#include "posixver.h"
|
||||
|
||||
#include <limits.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#if HAVE_UNISTD_H
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
#ifndef _POSIX2_VERSION
|
||||
# define _POSIX2_VERSION 0
|
||||
#endif
|
||||
|
||||
#ifndef DEFAULT_POSIX2_VERSION
|
||||
# define DEFAULT_POSIX2_VERSION _POSIX2_VERSION
|
||||
#endif
|
||||
|
||||
/* The POSIX version that utilities should conform to. The default is
|
||||
specified by the system. */
|
||||
|
||||
int
|
||||
posix2_version (void)
|
||||
{
|
||||
long int v = DEFAULT_POSIX2_VERSION;
|
||||
char const *s = getenv ("_POSIX2_VERSION");
|
||||
|
||||
if (s && *s)
|
||||
{
|
||||
char *e;
|
||||
long int i = strtol (s, &e, 10);
|
||||
if (! *e)
|
||||
v = i;
|
||||
}
|
||||
|
||||
return v < INT_MIN ? INT_MIN : v < INT_MAX ? v : INT_MAX;
|
||||
}
|
||||
|
|
@ -1 +0,0 @@
|
|||
int posix2_version (void);
|
||||
|
|
@ -1,41 +0,0 @@
|
|||
/* quote.c - quote arguments for output
|
||||
Copyright (C) 1998, 1999, 2000, 2001, 2003 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, write to the Free Software Foundation,
|
||||
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
||||
|
||||
/* Written by Paul Eggert <eggert@twinsun.com> */
|
||||
|
||||
#if HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#include "quotearg.h"
|
||||
#include "quote.h"
|
||||
|
||||
/* Return an unambiguous printable representation of NAME,
|
||||
allocated in slot N, suitable for diagnostics. */
|
||||
char const *
|
||||
quote_n (int n, char const *name)
|
||||
{
|
||||
return quotearg_n_style (n, locale_quoting_style, name);
|
||||
}
|
||||
|
||||
/* Return an unambiguous printable representation of NAME,
|
||||
suitable for diagnostics. */
|
||||
char const *
|
||||
quote (char const *name)
|
||||
{
|
||||
return quote_n (0, name);
|
||||
}
|
||||
|
|
@ -1,22 +0,0 @@
|
|||
/* quote.h - prototypes for quote.c
|
||||
|
||||
Copyright (C) 1998, 1999, 2000, 2001, 2003 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, write to the Free Software Foundation,
|
||||
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
||||
|
||||
|
||||
char const *quote_n (int n, char const *name);
|
||||
char const *quote (char const *name);
|
||||
|
|
@ -1,673 +0,0 @@
|
|||
/* quotearg.c - quote arguments for output
|
||||
|
||||
Copyright (C) 1998, 1999, 2000, 2001, 2002, 2004 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, write to the Free Software Foundation,
|
||||
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
||||
|
||||
/* Written by Paul Eggert <eggert@twinsun.com> */
|
||||
|
||||
#if HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#include "quotearg.h"
|
||||
|
||||
#include "xalloc.h"
|
||||
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "gettext.h"
|
||||
#define _(msgid) gettext (msgid)
|
||||
#define N_(msgid) msgid
|
||||
|
||||
#if HAVE_WCHAR_H
|
||||
|
||||
/* BSD/OS 4.1 wchar.h requires FILE and struct tm to be declared. */
|
||||
# include <stdio.h>
|
||||
# include <time.h>
|
||||
|
||||
# include <wchar.h>
|
||||
#endif
|
||||
|
||||
#if !HAVE_MBRTOWC
|
||||
/* Disable multibyte processing entirely. Since MB_CUR_MAX is 1, the
|
||||
other macros are defined only for documentation and to satisfy C
|
||||
syntax. */
|
||||
# undef MB_CUR_MAX
|
||||
# define MB_CUR_MAX 1
|
||||
# define mbrtowc(pwc, s, n, ps) ((*(pwc) = *(s)) != 0)
|
||||
# define iswprint(wc) isprint ((unsigned char) (wc))
|
||||
# undef HAVE_MBSINIT
|
||||
#endif
|
||||
|
||||
#if !defined mbsinit && !HAVE_MBSINIT
|
||||
# define mbsinit(ps) 1
|
||||
#endif
|
||||
|
||||
#ifndef iswprint
|
||||
# if HAVE_WCTYPE_H
|
||||
# include <wctype.h>
|
||||
# endif
|
||||
# if !defined iswprint && !HAVE_ISWPRINT
|
||||
# define iswprint(wc) 1
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef SIZE_MAX
|
||||
# define SIZE_MAX ((size_t) -1)
|
||||
#endif
|
||||
|
||||
#define INT_BITS (sizeof (int) * CHAR_BIT)
|
||||
|
||||
struct quoting_options
|
||||
{
|
||||
/* Basic quoting style. */
|
||||
enum quoting_style style;
|
||||
|
||||
/* Quote the characters indicated by this bit vector even if the
|
||||
quoting style would not normally require them to be quoted. */
|
||||
int quote_these_too[(UCHAR_MAX / INT_BITS) + 1];
|
||||
};
|
||||
|
||||
/* Names of quoting styles. */
|
||||
char const *const quoting_style_args[] =
|
||||
{
|
||||
"literal",
|
||||
"shell",
|
||||
"shell-always",
|
||||
"c",
|
||||
"escape",
|
||||
"locale",
|
||||
"clocale",
|
||||
0
|
||||
};
|
||||
|
||||
/* Correspondences to quoting style names. */
|
||||
enum quoting_style const quoting_style_vals[] =
|
||||
{
|
||||
literal_quoting_style,
|
||||
shell_quoting_style,
|
||||
shell_always_quoting_style,
|
||||
c_quoting_style,
|
||||
escape_quoting_style,
|
||||
locale_quoting_style,
|
||||
clocale_quoting_style
|
||||
};
|
||||
|
||||
/* The default quoting options. */
|
||||
static struct quoting_options default_quoting_options;
|
||||
|
||||
/* Allocate a new set of quoting options, with contents initially identical
|
||||
to O if O is not null, or to the default if O is null.
|
||||
It is the caller's responsibility to free the result. */
|
||||
struct quoting_options *
|
||||
clone_quoting_options (struct quoting_options *o)
|
||||
{
|
||||
int e = errno;
|
||||
struct quoting_options *p = xmalloc (sizeof *p);
|
||||
*p = *(o ? o : &default_quoting_options);
|
||||
errno = e;
|
||||
return p;
|
||||
}
|
||||
|
||||
/* Get the value of O's quoting style. If O is null, use the default. */
|
||||
enum quoting_style
|
||||
get_quoting_style (struct quoting_options *o)
|
||||
{
|
||||
return (o ? o : &default_quoting_options)->style;
|
||||
}
|
||||
|
||||
/* In O (or in the default if O is null),
|
||||
set the value of the quoting style to S. */
|
||||
void
|
||||
set_quoting_style (struct quoting_options *o, enum quoting_style s)
|
||||
{
|
||||
(o ? o : &default_quoting_options)->style = s;
|
||||
}
|
||||
|
||||
/* In O (or in the default if O is null),
|
||||
set the value of the quoting options for character C to I.
|
||||
Return the old value. Currently, the only values defined for I are
|
||||
0 (the default) and 1 (which means to quote the character even if
|
||||
it would not otherwise be quoted). */
|
||||
int
|
||||
set_char_quoting (struct quoting_options *o, char c, int i)
|
||||
{
|
||||
unsigned char uc = c;
|
||||
int *p = (o ? o : &default_quoting_options)->quote_these_too + uc / INT_BITS;
|
||||
int shift = uc % INT_BITS;
|
||||
int r = (*p >> shift) & 1;
|
||||
*p ^= ((i & 1) ^ r) << shift;
|
||||
return r;
|
||||
}
|
||||
|
||||
/* MSGID approximates a quotation mark. Return its translation if it
|
||||
has one; otherwise, return either it or "\"", depending on S. */
|
||||
static char const *
|
||||
gettext_quote (char const *msgid, enum quoting_style s)
|
||||
{
|
||||
char const *translation = _(msgid);
|
||||
if (translation == msgid && s == clocale_quoting_style)
|
||||
translation = "\"";
|
||||
return translation;
|
||||
}
|
||||
|
||||
/* Place into buffer BUFFER (of size BUFFERSIZE) a quoted version of
|
||||
argument ARG (of size ARGSIZE), using QUOTING_STYLE and the
|
||||
non-quoting-style part of O to control quoting.
|
||||
Terminate the output with a null character, and return the written
|
||||
size of the output, not counting the terminating null.
|
||||
If BUFFERSIZE is too small to store the output string, return the
|
||||
value that would have been returned had BUFFERSIZE been large enough.
|
||||
If ARGSIZE is SIZE_MAX, use the string length of the argument for ARGSIZE.
|
||||
|
||||
This function acts like quotearg_buffer (BUFFER, BUFFERSIZE, ARG,
|
||||
ARGSIZE, O), except it uses QUOTING_STYLE instead of the quoting
|
||||
style specified by O, and O may not be null. */
|
||||
|
||||
static size_t
|
||||
quotearg_buffer_restyled (char *buffer, size_t buffersize,
|
||||
char const *arg, size_t argsize,
|
||||
enum quoting_style quoting_style,
|
||||
struct quoting_options const *o)
|
||||
{
|
||||
size_t i;
|
||||
size_t len = 0;
|
||||
char const *quote_string = 0;
|
||||
size_t quote_string_len = 0;
|
||||
bool backslash_escapes = false;
|
||||
bool unibyte_locale = MB_CUR_MAX == 1;
|
||||
|
||||
#define STORE(c) \
|
||||
do \
|
||||
{ \
|
||||
if (len < buffersize) \
|
||||
buffer[len] = (c); \
|
||||
len++; \
|
||||
} \
|
||||
while (0)
|
||||
|
||||
switch (quoting_style)
|
||||
{
|
||||
case c_quoting_style:
|
||||
STORE ('"');
|
||||
backslash_escapes = true;
|
||||
quote_string = "\"";
|
||||
quote_string_len = 1;
|
||||
break;
|
||||
|
||||
case escape_quoting_style:
|
||||
backslash_escapes = true;
|
||||
break;
|
||||
|
||||
case locale_quoting_style:
|
||||
case clocale_quoting_style:
|
||||
{
|
||||
/* Get translations for open and closing quotation marks.
|
||||
|
||||
The message catalog should translate "`" to a left
|
||||
quotation mark suitable for the locale, and similarly for
|
||||
"'". If the catalog has no translation,
|
||||
locale_quoting_style quotes `like this', and
|
||||
clocale_quoting_style quotes "like this".
|
||||
|
||||
For example, an American English Unicode locale should
|
||||
translate "`" to U+201C (LEFT DOUBLE QUOTATION MARK), and
|
||||
should translate "'" to U+201D (RIGHT DOUBLE QUOTATION
|
||||
MARK). A British English Unicode locale should instead
|
||||
translate these to U+2018 (LEFT SINGLE QUOTATION MARK) and
|
||||
U+2019 (RIGHT SINGLE QUOTATION MARK), respectively. */
|
||||
|
||||
char const *left = gettext_quote (N_("`"), quoting_style);
|
||||
char const *right = gettext_quote (N_("'"), quoting_style);
|
||||
for (quote_string = left; *quote_string; quote_string++)
|
||||
STORE (*quote_string);
|
||||
backslash_escapes = true;
|
||||
quote_string = right;
|
||||
quote_string_len = strlen (quote_string);
|
||||
}
|
||||
break;
|
||||
|
||||
case shell_always_quoting_style:
|
||||
STORE ('\'');
|
||||
quote_string = "'";
|
||||
quote_string_len = 1;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
for (i = 0; ! (argsize == SIZE_MAX ? arg[i] == '\0' : i == argsize); i++)
|
||||
{
|
||||
unsigned char c;
|
||||
unsigned char esc;
|
||||
|
||||
if (backslash_escapes
|
||||
&& quote_string_len
|
||||
&& i + quote_string_len <= argsize
|
||||
&& memcmp (arg + i, quote_string, quote_string_len) == 0)
|
||||
STORE ('\\');
|
||||
|
||||
c = arg[i];
|
||||
switch (c)
|
||||
{
|
||||
case '\0':
|
||||
if (backslash_escapes)
|
||||
{
|
||||
STORE ('\\');
|
||||
STORE ('0');
|
||||
STORE ('0');
|
||||
c = '0';
|
||||
}
|
||||
break;
|
||||
|
||||
case '?':
|
||||
switch (quoting_style)
|
||||
{
|
||||
case shell_quoting_style:
|
||||
goto use_shell_always_quoting_style;
|
||||
|
||||
case c_quoting_style:
|
||||
if (i + 2 < argsize && arg[i + 1] == '?')
|
||||
switch (arg[i + 2])
|
||||
{
|
||||
case '!': case '\'':
|
||||
case '(': case ')': case '-': case '/':
|
||||
case '<': case '=': case '>':
|
||||
/* Escape the second '?' in what would otherwise be
|
||||
a trigraph. */
|
||||
c = arg[i + 2];
|
||||
i += 2;
|
||||
STORE ('?');
|
||||
STORE ('\\');
|
||||
STORE ('?');
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case '\a': esc = 'a'; goto c_escape;
|
||||
case '\b': esc = 'b'; goto c_escape;
|
||||
case '\f': esc = 'f'; goto c_escape;
|
||||
case '\n': esc = 'n'; goto c_and_shell_escape;
|
||||
case '\r': esc = 'r'; goto c_and_shell_escape;
|
||||
case '\t': esc = 't'; goto c_and_shell_escape;
|
||||
case '\v': esc = 'v'; goto c_escape;
|
||||
case '\\': esc = c; goto c_and_shell_escape;
|
||||
|
||||
c_and_shell_escape:
|
||||
if (quoting_style == shell_quoting_style)
|
||||
goto use_shell_always_quoting_style;
|
||||
c_escape:
|
||||
if (backslash_escapes)
|
||||
{
|
||||
c = esc;
|
||||
goto store_escape;
|
||||
}
|
||||
break;
|
||||
|
||||
case '{': case '}': /* sometimes special if isolated */
|
||||
if (! (argsize == SIZE_MAX ? arg[1] == '\0' : argsize == 1))
|
||||
break;
|
||||
/* Fall through. */
|
||||
case '#': case '~':
|
||||
if (i != 0)
|
||||
break;
|
||||
/* Fall through. */
|
||||
case ' ':
|
||||
case '!': /* special in bash */
|
||||
case '"': case '$': case '&':
|
||||
case '(': case ')': case '*': case ';':
|
||||
case '<':
|
||||
case '=': /* sometimes special in 0th or (with "set -k") later args */
|
||||
case '>': case '[':
|
||||
case '^': /* special in old /bin/sh, e.g. SunOS 4.1.4 */
|
||||
case '`': case '|':
|
||||
/* A shell special character. In theory, '$' and '`' could
|
||||
be the first bytes of multibyte characters, which means
|
||||
we should check them with mbrtowc, but in practice this
|
||||
doesn't happen so it's not worth worrying about. */
|
||||
if (quoting_style == shell_quoting_style)
|
||||
goto use_shell_always_quoting_style;
|
||||
break;
|
||||
|
||||
case '\'':
|
||||
switch (quoting_style)
|
||||
{
|
||||
case shell_quoting_style:
|
||||
goto use_shell_always_quoting_style;
|
||||
|
||||
case shell_always_quoting_style:
|
||||
STORE ('\'');
|
||||
STORE ('\\');
|
||||
STORE ('\'');
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case '%': case '+': case ',': case '-': case '.': case '/':
|
||||
case '0': case '1': case '2': case '3': case '4': case '5':
|
||||
case '6': case '7': case '8': case '9': case ':':
|
||||
case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
|
||||
case 'G': case 'H': case 'I': case 'J': case 'K': case 'L':
|
||||
case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R':
|
||||
case 'S': case 'T': case 'U': case 'V': case 'W': case 'X':
|
||||
case 'Y': case 'Z': case ']': case '_': case 'a': case 'b':
|
||||
case 'c': case 'd': case 'e': case 'f': case 'g': case 'h':
|
||||
case 'i': case 'j': case 'k': case 'l': case 'm': case 'n':
|
||||
case 'o': case 'p': case 'q': case 'r': case 's': case 't':
|
||||
case 'u': case 'v': case 'w': case 'x': case 'y': case 'z':
|
||||
/* These characters don't cause problems, no matter what the
|
||||
quoting style is. They cannot start multibyte sequences. */
|
||||
break;
|
||||
|
||||
default:
|
||||
/* If we have a multibyte sequence, copy it until we reach
|
||||
its end, find an error, or come back to the initial shift
|
||||
state. For C-like styles, if the sequence has
|
||||
unprintable characters, escape the whole sequence, since
|
||||
we can't easily escape single characters within it. */
|
||||
{
|
||||
/* Length of multibyte sequence found so far. */
|
||||
size_t m;
|
||||
|
||||
bool printable;
|
||||
|
||||
if (unibyte_locale)
|
||||
{
|
||||
m = 1;
|
||||
printable = isprint (c) != 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
mbstate_t mbstate;
|
||||
memset (&mbstate, 0, sizeof mbstate);
|
||||
|
||||
m = 0;
|
||||
printable = true;
|
||||
if (argsize == SIZE_MAX)
|
||||
argsize = strlen (arg);
|
||||
|
||||
do
|
||||
{
|
||||
wchar_t w;
|
||||
size_t bytes = mbrtowc (&w, &arg[i + m],
|
||||
argsize - (i + m), &mbstate);
|
||||
if (bytes == 0)
|
||||
break;
|
||||
else if (bytes == (size_t) -1)
|
||||
{
|
||||
printable = false;
|
||||
break;
|
||||
}
|
||||
else if (bytes == (size_t) -2)
|
||||
{
|
||||
printable = false;
|
||||
while (i + m < argsize && arg[i + m])
|
||||
m++;
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Work around a bug with older shells that "see" a '\'
|
||||
that is really the 2nd byte of a multibyte character.
|
||||
In practice the problem is limited to ASCII
|
||||
chars >= '@' that are shell special chars. */
|
||||
if ('[' == 0x5b && quoting_style == shell_quoting_style)
|
||||
{
|
||||
size_t j;
|
||||
for (j = 1; j < bytes; j++)
|
||||
switch (arg[i + m + j])
|
||||
{
|
||||
case '[': case '\\': case '^':
|
||||
case '`': case '|':
|
||||
goto use_shell_always_quoting_style;
|
||||
}
|
||||
}
|
||||
|
||||
if (! iswprint (w))
|
||||
printable = false;
|
||||
m += bytes;
|
||||
}
|
||||
}
|
||||
while (! mbsinit (&mbstate));
|
||||
}
|
||||
|
||||
if (1 < m || (backslash_escapes && ! printable))
|
||||
{
|
||||
/* Output a multibyte sequence, or an escaped
|
||||
unprintable unibyte character. */
|
||||
size_t ilim = i + m;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
if (backslash_escapes && ! printable)
|
||||
{
|
||||
STORE ('\\');
|
||||
STORE ('0' + (c >> 6));
|
||||
STORE ('0' + ((c >> 3) & 7));
|
||||
c = '0' + (c & 7);
|
||||
}
|
||||
if (ilim <= i + 1)
|
||||
break;
|
||||
STORE (c);
|
||||
c = arg[++i];
|
||||
}
|
||||
|
||||
goto store_c;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (! (backslash_escapes
|
||||
&& o->quote_these_too[c / INT_BITS] & (1 << (c % INT_BITS))))
|
||||
goto store_c;
|
||||
|
||||
store_escape:
|
||||
STORE ('\\');
|
||||
|
||||
store_c:
|
||||
STORE (c);
|
||||
}
|
||||
|
||||
if (i == 0 && quoting_style == shell_quoting_style)
|
||||
goto use_shell_always_quoting_style;
|
||||
|
||||
if (quote_string)
|
||||
for (; *quote_string; quote_string++)
|
||||
STORE (*quote_string);
|
||||
|
||||
if (len < buffersize)
|
||||
buffer[len] = '\0';
|
||||
return len;
|
||||
|
||||
use_shell_always_quoting_style:
|
||||
return quotearg_buffer_restyled (buffer, buffersize, arg, argsize,
|
||||
shell_always_quoting_style, o);
|
||||
}
|
||||
|
||||
/* Place into buffer BUFFER (of size BUFFERSIZE) a quoted version of
|
||||
argument ARG (of size ARGSIZE), using O to control quoting.
|
||||
If O is null, use the default.
|
||||
Terminate the output with a null character, and return the written
|
||||
size of the output, not counting the terminating null.
|
||||
If BUFFERSIZE is too small to store the output string, return the
|
||||
value that would have been returned had BUFFERSIZE been large enough.
|
||||
If ARGSIZE is SIZE_MAX, use the string length of the argument for
|
||||
ARGSIZE. */
|
||||
size_t
|
||||
quotearg_buffer (char *buffer, size_t buffersize,
|
||||
char const *arg, size_t argsize,
|
||||
struct quoting_options const *o)
|
||||
{
|
||||
struct quoting_options const *p = o ? o : &default_quoting_options;
|
||||
int e = errno;
|
||||
size_t r = quotearg_buffer_restyled (buffer, buffersize, arg, argsize,
|
||||
p->style, p);
|
||||
errno = e;
|
||||
return r;
|
||||
}
|
||||
|
||||
/* Like quotearg_buffer (..., ARG, ARGSIZE, O), except return newly
|
||||
allocated storage containing the quoted string. */
|
||||
char *
|
||||
quotearg_alloc (char const *arg, size_t argsize,
|
||||
struct quoting_options const *o)
|
||||
{
|
||||
int e = errno;
|
||||
size_t bufsize = quotearg_buffer (0, 0, arg, argsize, o) + 1;
|
||||
char *buf = xmalloc (bufsize);
|
||||
quotearg_buffer (buf, bufsize, arg, argsize, o);
|
||||
errno = e;
|
||||
return buf;
|
||||
}
|
||||
|
||||
/* Use storage slot N to return a quoted version of argument ARG.
|
||||
ARG is of size ARGSIZE, but if that is SIZE_MAX, ARG is a
|
||||
null-terminated string.
|
||||
OPTIONS specifies the quoting options.
|
||||
The returned value points to static storage that can be
|
||||
reused by the next call to this function with the same value of N.
|
||||
N must be nonnegative. N is deliberately declared with type "int"
|
||||
to allow for future extensions (using negative values). */
|
||||
static char *
|
||||
quotearg_n_options (int n, char const *arg, size_t argsize,
|
||||
struct quoting_options const *options)
|
||||
{
|
||||
int e = errno;
|
||||
|
||||
/* Preallocate a slot 0 buffer, so that the caller can always quote
|
||||
one small component of a "memory exhausted" message in slot 0. */
|
||||
static char slot0[256];
|
||||
static unsigned int nslots = 1;
|
||||
unsigned int n0 = n;
|
||||
struct slotvec
|
||||
{
|
||||
size_t size;
|
||||
char *val;
|
||||
};
|
||||
static struct slotvec slotvec0 = {sizeof slot0, slot0};
|
||||
static struct slotvec *slotvec = &slotvec0;
|
||||
|
||||
if (n < 0)
|
||||
abort ();
|
||||
|
||||
if (nslots <= n0)
|
||||
{
|
||||
unsigned int n1 = n0 + 1;
|
||||
|
||||
if (xalloc_oversized (n1, sizeof *slotvec))
|
||||
xalloc_die ();
|
||||
|
||||
if (slotvec == &slotvec0)
|
||||
{
|
||||
slotvec = xmalloc (sizeof *slotvec);
|
||||
*slotvec = slotvec0;
|
||||
}
|
||||
slotvec = xrealloc (slotvec, n1 * sizeof *slotvec);
|
||||
memset (slotvec + nslots, 0, (n1 - nslots) * sizeof *slotvec);
|
||||
nslots = n1;
|
||||
}
|
||||
|
||||
{
|
||||
size_t size = slotvec[n].size;
|
||||
char *val = slotvec[n].val;
|
||||
size_t qsize = quotearg_buffer (val, size, arg, argsize, options);
|
||||
|
||||
if (size <= qsize)
|
||||
{
|
||||
slotvec[n].size = size = qsize + 1;
|
||||
if (val != slot0)
|
||||
free (val);
|
||||
slotvec[n].val = val = xmalloc (size);
|
||||
quotearg_buffer (val, size, arg, argsize, options);
|
||||
}
|
||||
|
||||
errno = e;
|
||||
return val;
|
||||
}
|
||||
}
|
||||
|
||||
char *
|
||||
quotearg_n (int n, char const *arg)
|
||||
{
|
||||
return quotearg_n_options (n, arg, SIZE_MAX, &default_quoting_options);
|
||||
}
|
||||
|
||||
char *
|
||||
quotearg (char const *arg)
|
||||
{
|
||||
return quotearg_n (0, arg);
|
||||
}
|
||||
|
||||
/* Return quoting options for STYLE, with no extra quoting. */
|
||||
static struct quoting_options
|
||||
quoting_options_from_style (enum quoting_style style)
|
||||
{
|
||||
struct quoting_options o;
|
||||
o.style = style;
|
||||
memset (o.quote_these_too, 0, sizeof o.quote_these_too);
|
||||
return o;
|
||||
}
|
||||
|
||||
char *
|
||||
quotearg_n_style (int n, enum quoting_style s, char const *arg)
|
||||
{
|
||||
struct quoting_options const o = quoting_options_from_style (s);
|
||||
return quotearg_n_options (n, arg, SIZE_MAX, &o);
|
||||
}
|
||||
|
||||
char *
|
||||
quotearg_n_style_mem (int n, enum quoting_style s,
|
||||
char const *arg, size_t argsize)
|
||||
{
|
||||
struct quoting_options const o = quoting_options_from_style (s);
|
||||
return quotearg_n_options (n, arg, argsize, &o);
|
||||
}
|
||||
|
||||
char *
|
||||
quotearg_style (enum quoting_style s, char const *arg)
|
||||
{
|
||||
return quotearg_n_style (0, s, arg);
|
||||
}
|
||||
|
||||
char *
|
||||
quotearg_char (char const *arg, char ch)
|
||||
{
|
||||
struct quoting_options options;
|
||||
options = default_quoting_options;
|
||||
set_char_quoting (&options, ch, 1);
|
||||
return quotearg_n_options (0, arg, SIZE_MAX, &options);
|
||||
}
|
||||
|
||||
char *
|
||||
quotearg_colon (char const *arg)
|
||||
{
|
||||
return quotearg_char (arg, ':');
|
||||
}
|
||||
|
|
@ -1,137 +0,0 @@
|
|||
/* quotearg.h - quote arguments for output
|
||||
|
||||
Copyright (C) 1998, 1999, 2000, 2001, 2002, 2004 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, write to the Free Software Foundation,
|
||||
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
||||
|
||||
/* Written by Paul Eggert <eggert@twinsun.com> */
|
||||
|
||||
#ifndef QUOTEARG_H_
|
||||
# define QUOTEARG_H_ 1
|
||||
|
||||
# include <stddef.h>
|
||||
|
||||
/* Basic quoting styles. */
|
||||
enum quoting_style
|
||||
{
|
||||
/* Output names as-is (ls --quoting-style=literal). */
|
||||
literal_quoting_style,
|
||||
|
||||
/* Quote names for the shell if they contain shell metacharacters
|
||||
or would cause ambiguous output (ls --quoting-style=shell). */
|
||||
shell_quoting_style,
|
||||
|
||||
/* Quote names for the shell, even if they would normally not
|
||||
require quoting (ls --quoting-style=shell-always). */
|
||||
shell_always_quoting_style,
|
||||
|
||||
/* Quote names as for a C language string (ls --quoting-style=c). */
|
||||
c_quoting_style,
|
||||
|
||||
/* Like c_quoting_style except omit the surrounding double-quote
|
||||
characters (ls --quoting-style=escape). */
|
||||
escape_quoting_style,
|
||||
|
||||
/* Like clocale_quoting_style, but quote `like this' instead of
|
||||
"like this" in the default C locale (ls --quoting-style=locale). */
|
||||
locale_quoting_style,
|
||||
|
||||
/* Like c_quoting_style except use quotation marks appropriate for
|
||||
the locale (ls --quoting-style=clocale). */
|
||||
clocale_quoting_style
|
||||
};
|
||||
|
||||
/* For now, --quoting-style=literal is the default, but this may change. */
|
||||
# ifndef DEFAULT_QUOTING_STYLE
|
||||
# define DEFAULT_QUOTING_STYLE literal_quoting_style
|
||||
# endif
|
||||
|
||||
/* Names of quoting styles and their corresponding values. */
|
||||
extern char const *const quoting_style_args[];
|
||||
extern enum quoting_style const quoting_style_vals[];
|
||||
|
||||
struct quoting_options;
|
||||
|
||||
/* The functions listed below set and use a hidden variable
|
||||
that contains the default quoting style options. */
|
||||
|
||||
/* Allocate a new set of quoting options, with contents initially identical
|
||||
to O if O is not null, or to the default if O is null.
|
||||
It is the caller's responsibility to free the result. */
|
||||
struct quoting_options *clone_quoting_options (struct quoting_options *o);
|
||||
|
||||
/* Get the value of O's quoting style. If O is null, use the default. */
|
||||
enum quoting_style get_quoting_style (struct quoting_options *o);
|
||||
|
||||
/* In O (or in the default if O is null),
|
||||
set the value of the quoting style to S. */
|
||||
void set_quoting_style (struct quoting_options *o, enum quoting_style s);
|
||||
|
||||
/* In O (or in the default if O is null),
|
||||
set the value of the quoting options for character C to I.
|
||||
Return the old value. Currently, the only values defined for I are
|
||||
0 (the default) and 1 (which means to quote the character even if
|
||||
it would not otherwise be quoted). */
|
||||
int set_char_quoting (struct quoting_options *o, char c, int i);
|
||||
|
||||
/* Place into buffer BUFFER (of size BUFFERSIZE) a quoted version of
|
||||
argument ARG (of size ARGSIZE), using O to control quoting.
|
||||
If O is null, use the default.
|
||||
Terminate the output with a null character, and return the written
|
||||
size of the output, not counting the terminating null.
|
||||
If BUFFERSIZE is too small to store the output string, return the
|
||||
value that would have been returned had BUFFERSIZE been large enough.
|
||||
If ARGSIZE is -1, use the string length of the argument for ARGSIZE. */
|
||||
size_t quotearg_buffer (char *buffer, size_t buffersize,
|
||||
char const *arg, size_t argsize,
|
||||
struct quoting_options const *o);
|
||||
|
||||
/* Like quotearg_buffer, except return the result in a newly allocated
|
||||
buffer. It is the caller's responsibility to free the result. */
|
||||
char *quotearg_alloc (char const *arg, size_t argsize,
|
||||
struct quoting_options const *o);
|
||||
|
||||
/* Use storage slot N to return a quoted version of the string ARG.
|
||||
Use the default quoting options.
|
||||
The returned value points to static storage that can be
|
||||
reused by the next call to this function with the same value of N.
|
||||
N must be nonnegative. */
|
||||
char *quotearg_n (int n, char const *arg);
|
||||
|
||||
/* Equivalent to quotearg_n (0, ARG). */
|
||||
char *quotearg (char const *arg);
|
||||
|
||||
/* Use style S and storage slot N to return a quoted version of the string ARG.
|
||||
This is like quotearg_n (N, ARG), except that it uses S with no other
|
||||
options to specify the quoting method. */
|
||||
char *quotearg_n_style (int n, enum quoting_style s, char const *arg);
|
||||
|
||||
/* Use style S and storage slot N to return a quoted version of the
|
||||
argument ARG of size ARGSIZE. This is like quotearg_n_style
|
||||
(N, S, ARG), except it can quote null bytes. */
|
||||
char *quotearg_n_style_mem (int n, enum quoting_style s,
|
||||
char const *arg, size_t argsize);
|
||||
|
||||
/* Equivalent to quotearg_n_style (0, S, ARG). */
|
||||
char *quotearg_style (enum quoting_style s, char const *arg);
|
||||
|
||||
/* Like quotearg (ARG), except also quote any instances of CH. */
|
||||
char *quotearg_char (char const *arg, char ch);
|
||||
|
||||
/* Equivalent to quotearg_char (ARG, ':'). */
|
||||
char *quotearg_colon (char const *arg);
|
||||
|
||||
#endif /* !QUOTEARG_H_ */
|
||||
|
|
@ -1,255 +0,0 @@
|
|||
/* stat-related macros
|
||||
|
||||
Copyright (C) 1993, 1994, 2001, 2002, 2004 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, write to the Free Software Foundation,
|
||||
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
||||
|
||||
/* Written by Paul Eggert and Jim Meyering. */
|
||||
|
||||
#ifndef STAT_MACROS_H
|
||||
# define STAT_MACROS_H 1
|
||||
|
||||
# if ! defined S_ISREG && ! defined S_IFREG
|
||||
# error "you must include <sys/stat.h> before including this file"
|
||||
# endif
|
||||
|
||||
# ifndef S_IFMT
|
||||
# define S_IFMT 0170000
|
||||
# endif
|
||||
|
||||
# if STAT_MACROS_BROKEN
|
||||
# undef S_ISBLK
|
||||
# undef S_ISCHR
|
||||
# undef S_ISDIR
|
||||
# undef S_ISDOOR
|
||||
# undef S_ISFIFO
|
||||
# undef S_ISLNK
|
||||
# undef S_ISNAM
|
||||
# undef S_ISMPB
|
||||
# undef S_ISMPC
|
||||
# undef S_ISNWK
|
||||
# undef S_ISREG
|
||||
# undef S_ISSOCK
|
||||
# endif
|
||||
|
||||
|
||||
# ifndef S_ISBLK
|
||||
# ifdef S_IFBLK
|
||||
# define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
|
||||
# else
|
||||
# define S_ISBLK(m) 0
|
||||
# endif
|
||||
# endif
|
||||
|
||||
# ifndef S_ISCHR
|
||||
# ifdef S_IFCHR
|
||||
# define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
|
||||
# else
|
||||
# define S_ISCHR(m) 0
|
||||
# endif
|
||||
# endif
|
||||
|
||||
# ifndef S_ISDIR
|
||||
# ifdef S_IFDIR
|
||||
# define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
|
||||
# else
|
||||
# define S_ISDIR(m) 0
|
||||
# endif
|
||||
# endif
|
||||
|
||||
# ifndef S_ISDOOR /* Solaris 2.5 and up */
|
||||
# ifdef S_IFDOOR
|
||||
# define S_ISDOOR(m) (((m) & S_IFMT) == S_IFDOOR)
|
||||
# else
|
||||
# define S_ISDOOR(m) 0
|
||||
# endif
|
||||
# endif
|
||||
|
||||
# ifndef S_ISFIFO
|
||||
# ifdef S_IFIFO
|
||||
# define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
|
||||
# else
|
||||
# define S_ISFIFO(m) 0
|
||||
# endif
|
||||
# endif
|
||||
|
||||
# ifndef S_ISLNK
|
||||
# ifdef S_IFLNK
|
||||
# define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
|
||||
# else
|
||||
# define S_ISLNK(m) 0
|
||||
# endif
|
||||
# endif
|
||||
|
||||
# ifndef S_ISMPB /* V7 */
|
||||
# ifdef S_IFMPB
|
||||
# define S_ISMPB(m) (((m) & S_IFMT) == S_IFMPB)
|
||||
# define S_ISMPC(m) (((m) & S_IFMT) == S_IFMPC)
|
||||
# else
|
||||
# define S_ISMPB(m) 0
|
||||
# define S_ISMPC(m) 0
|
||||
# endif
|
||||
# endif
|
||||
|
||||
# ifndef S_ISNAM /* Xenix */
|
||||
# ifdef S_IFNAM
|
||||
# define S_ISNAM(m) (((m) & S_IFMT) == S_IFNAM)
|
||||
# else
|
||||
# define S_ISNAM(m) 0
|
||||
# endif
|
||||
# endif
|
||||
|
||||
# ifndef S_ISNWK /* HP/UX */
|
||||
# ifdef S_IFNWK
|
||||
# define S_ISNWK(m) (((m) & S_IFMT) == S_IFNWK)
|
||||
# else
|
||||
# define S_ISNWK(m) 0
|
||||
# endif
|
||||
# endif
|
||||
|
||||
# ifndef S_ISREG
|
||||
# ifdef S_IFREG
|
||||
# define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
|
||||
# else
|
||||
# define S_ISREG(m) 0
|
||||
# endif
|
||||
# endif
|
||||
|
||||
# ifndef S_ISSOCK
|
||||
# ifdef S_IFSOCK
|
||||
# define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
|
||||
# else
|
||||
# define S_ISSOCK(m) 0
|
||||
# endif
|
||||
# endif
|
||||
|
||||
|
||||
# ifndef S_TYPEISMQ
|
||||
# define S_TYPEISMQ(p) 0
|
||||
# endif
|
||||
|
||||
# ifndef S_TYPEISTMO
|
||||
# define S_TYPEISTMO(p) 0
|
||||
# endif
|
||||
|
||||
|
||||
# ifndef S_TYPEISSEM
|
||||
# ifdef S_INSEM
|
||||
# define S_TYPEISSEM(p) (S_ISNAM ((p)->st_mode) && (p)->st_rdev == S_INSEM)
|
||||
# else
|
||||
# define S_TYPEISSEM(p) 0
|
||||
# endif
|
||||
# endif
|
||||
|
||||
# ifndef S_TYPEISSHM
|
||||
# ifdef S_INSHD
|
||||
# define S_TYPEISSHM(p) (S_ISNAM ((p)->st_mode) && (p)->st_rdev == S_INSHD)
|
||||
# else
|
||||
# define S_TYPEISSHM(p) 0
|
||||
# endif
|
||||
# endif
|
||||
|
||||
/* contiguous */
|
||||
# ifndef S_ISCTG
|
||||
# define S_ISCTG(p) 0
|
||||
# endif
|
||||
|
||||
/* Cray DMF (data migration facility): off line, with data */
|
||||
# ifndef S_ISOFD
|
||||
# define S_ISOFD(p) 0
|
||||
# endif
|
||||
|
||||
/* Cray DMF (data migration facility): off line, with no data */
|
||||
# ifndef S_ISOFL
|
||||
# define S_ISOFL(p) 0
|
||||
# endif
|
||||
|
||||
/* If any of the following are undefined,
|
||||
define them to their de facto standard values. */
|
||||
# if !S_ISUID
|
||||
# define S_ISUID 04000
|
||||
# endif
|
||||
# if !S_ISGID
|
||||
# define S_ISGID 02000
|
||||
# endif
|
||||
|
||||
/* S_ISVTX is a common extension to POSIX. */
|
||||
# ifndef S_ISVTX
|
||||
# define S_ISVTX 01000
|
||||
# endif
|
||||
|
||||
# if !S_IRUSR && S_IREAD
|
||||
# define S_IRUSR S_IREAD
|
||||
# endif
|
||||
# if !S_IRUSR
|
||||
# define S_IRUSR 00400
|
||||
# endif
|
||||
# if !S_IRGRP
|
||||
# define S_IRGRP (S_IRUSR >> 3)
|
||||
# endif
|
||||
# if !S_IROTH
|
||||
# define S_IROTH (S_IRUSR >> 6)
|
||||
# endif
|
||||
|
||||
# if !S_IWUSR && S_IWRITE
|
||||
# define S_IWUSR S_IWRITE
|
||||
# endif
|
||||
# if !S_IWUSR
|
||||
# define S_IWUSR 00200
|
||||
# endif
|
||||
# if !S_IWGRP
|
||||
# define S_IWGRP (S_IWUSR >> 3)
|
||||
# endif
|
||||
# if !S_IWOTH
|
||||
# define S_IWOTH (S_IWUSR >> 6)
|
||||
# endif
|
||||
|
||||
# if !S_IXUSR && S_IEXEC
|
||||
# define S_IXUSR S_IEXEC
|
||||
# endif
|
||||
# if !S_IXUSR
|
||||
# define S_IXUSR 00100
|
||||
# endif
|
||||
# if !S_IXGRP
|
||||
# define S_IXGRP (S_IXUSR >> 3)
|
||||
# endif
|
||||
# if !S_IXOTH
|
||||
# define S_IXOTH (S_IXUSR >> 6)
|
||||
# endif
|
||||
|
||||
# if !S_IRWXU
|
||||
# define S_IRWXU (S_IRUSR | S_IWUSR | S_IXUSR)
|
||||
# endif
|
||||
# if !S_IRWXG
|
||||
# define S_IRWXG (S_IRGRP | S_IWGRP | S_IXGRP)
|
||||
# endif
|
||||
# if !S_IRWXO
|
||||
# define S_IRWXO (S_IROTH | S_IWOTH | S_IXOTH)
|
||||
# endif
|
||||
|
||||
/* S_IXUGO is a common extension to POSIX. */
|
||||
# if !S_IXUGO
|
||||
# define S_IXUGO (S_IXUSR | S_IXGRP | S_IXOTH)
|
||||
# endif
|
||||
|
||||
# ifndef S_IRWXUGO
|
||||
# define S_IRWXUGO (S_IRWXU | S_IRWXG | S_IRWXO)
|
||||
# endif
|
||||
|
||||
/* All the mode bits that can be affected by chmod. */
|
||||
# define CHMOD_MODE_BITS \
|
||||
(S_ISUID | S_ISGID | S_ISVTX | S_IRWXU | S_IRWXG | S_IRWXO)
|
||||
|
||||
#endif /* STAT_MACROS_H */
|
||||
|
|
@ -1,23 +0,0 @@
|
|||
/* Invoke stdio functions, but avoid some glitches.
|
||||
|
||||
Copyright (C) 2001, 2003 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, write to the Free Software Foundation,
|
||||
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
||||
|
||||
/* Written by Paul Eggert. */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
FILE *fopen_safer (char const *, char const *);
|
||||
|
|
@ -1,48 +0,0 @@
|
|||
/* Find the length of STRING, but scan at most MAXLEN characters.
|
||||
Copyright (C) 1996, 1997, 1998, 2000-2003 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
|
||||
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, write to the Free Software Foundation,
|
||||
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
||||
|
||||
#if HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
#undef strnlen
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#undef __strnlen
|
||||
#undef strnlen
|
||||
|
||||
#ifndef _LIBC
|
||||
# define strnlen rpl_strnlen
|
||||
#endif
|
||||
|
||||
#ifndef weak_alias
|
||||
# define __strnlen strnlen
|
||||
#endif
|
||||
|
||||
/* Find the length of STRING, but scan at most MAXLEN characters.
|
||||
If no '\0' terminator is found in that many characters, return MAXLEN. */
|
||||
|
||||
size_t
|
||||
__strnlen (const char *string, size_t maxlen)
|
||||
{
|
||||
const char *end = memchr (string, '\0', maxlen);
|
||||
return end ? (size_t) (end - string) : maxlen;
|
||||
}
|
||||
#ifdef weak_alias
|
||||
weak_alias (__strnlen, strnlen)
|
||||
#endif
|
||||
|
|
@ -1,71 +0,0 @@
|
|||
/* timespec -- System time interface
|
||||
|
||||
Copyright (C) 2000, 2002, 2004 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, write to the Free Software Foundation,
|
||||
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
||||
|
||||
#if ! defined TIMESPEC_H
|
||||
# define TIMESPEC_H
|
||||
|
||||
/* You must include config.h before including this file. */
|
||||
|
||||
# include <sys/types.h>
|
||||
# if TIME_WITH_SYS_TIME
|
||||
# include <sys/time.h>
|
||||
# include <time.h>
|
||||
# else
|
||||
# if HAVE_SYS_TIME_H
|
||||
# include <sys/time.h>
|
||||
# else
|
||||
# include <time.h>
|
||||
# endif
|
||||
# endif
|
||||
|
||||
# if ! HAVE_STRUCT_TIMESPEC
|
||||
/* Some systems don't define this struct, e.g., AIX 4.1, Ultrix 4.3. */
|
||||
struct timespec
|
||||
{
|
||||
time_t tv_sec;
|
||||
long tv_nsec;
|
||||
};
|
||||
# endif
|
||||
|
||||
# ifdef ST_MTIM_NSEC
|
||||
# define ST_TIME_CMP_NS(a, b, ns) ((a).ns < (b).ns ? -1 : (a).ns > (b).ns)
|
||||
# else
|
||||
# define ST_TIME_CMP_NS(a, b, ns) 0
|
||||
# endif
|
||||
# define ST_TIME_CMP(a, b, s, ns) \
|
||||
((a).s < (b).s ? -1 : (a).s > (b).s ? 1 : ST_TIME_CMP_NS(a, b, ns))
|
||||
# define ATIME_CMP(a, b) ST_TIME_CMP (a, b, st_atime, st_atim.ST_MTIM_NSEC)
|
||||
# define CTIME_CMP(a, b) ST_TIME_CMP (a, b, st_ctime, st_ctim.ST_MTIM_NSEC)
|
||||
# define MTIME_CMP(a, b) ST_TIME_CMP (a, b, st_mtime, st_mtim.ST_MTIM_NSEC)
|
||||
|
||||
# ifdef ST_MTIM_NSEC
|
||||
# define TIMESPEC_NS(timespec) ((timespec).ST_MTIM_NSEC)
|
||||
# else
|
||||
# define TIMESPEC_NS(timespec) 0
|
||||
# endif
|
||||
|
||||
# if ! HAVE_DECL_NANOSLEEP
|
||||
/* Don't specify a prototype here. Some systems (e.g., OSF) declare
|
||||
nanosleep with a conflicting one (const-less first parameter). */
|
||||
int nanosleep ();
|
||||
# endif
|
||||
|
||||
int gettime (struct timespec *);
|
||||
int settime (struct timespec const *);
|
||||
|
||||
#endif
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
#define inttostr umaxtostr
|
||||
#define inttype uintmax_t
|
||||
#include "inttostr.c"
|
||||
|
|
@ -1,21 +0,0 @@
|
|||
/* Invoke unistd functions, but avoid some glitches.
|
||||
|
||||
Copyright (C) 2001, 2003 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, write to the Free Software Foundation,
|
||||
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
||||
|
||||
/* Written by Paul Eggert. */
|
||||
|
||||
int dup_safer (int);
|
||||
|
|
@ -1,181 +0,0 @@
|
|||
/* Utility to help print --version output in a consistent format.
|
||||
Copyright (C) 1999-2004 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, write to the Free Software Foundation,
|
||||
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
||||
|
||||
/* $FreeBSD$ */
|
||||
|
||||
/* Written by Jim Meyering. */
|
||||
|
||||
#if HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
/* Specification. */
|
||||
#include "version-etc.h"
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "unlocked-io.h"
|
||||
|
||||
#include "gettext.h"
|
||||
#define _(msgid) gettext (msgid)
|
||||
|
||||
/* Default copyright goes to the FSF. */
|
||||
|
||||
const char* version_etc_copyright =
|
||||
/* Do *not* mark this string for translation. */
|
||||
"Copyright (C) 2004 Free Software Foundation, Inc.";
|
||||
|
||||
|
||||
/* Like version_etc, below, but with the NULL-terminated author list
|
||||
provided via a variable of type va_list. */
|
||||
void
|
||||
version_etc_va (FILE *stream,
|
||||
const char *command_name, const char *package,
|
||||
const char *version, va_list authors)
|
||||
{
|
||||
size_t n_authors;
|
||||
|
||||
/* Count the number of authors. */
|
||||
{
|
||||
va_list tmp_authors;
|
||||
|
||||
#ifdef va_copy
|
||||
va_copy (tmp_authors, authors);
|
||||
#else
|
||||
tmp_authors = authors;
|
||||
#endif
|
||||
|
||||
n_authors = 0;
|
||||
while (va_arg (tmp_authors, const char *) != NULL)
|
||||
++n_authors;
|
||||
#ifdef va_copy
|
||||
va_end (tmp_authors);
|
||||
#endif
|
||||
}
|
||||
|
||||
if (command_name)
|
||||
fprintf (stream, "%s (%s) %s\n", command_name, package, version);
|
||||
else
|
||||
fprintf (stream, "%s %s\n", package, version);
|
||||
|
||||
switch (n_authors)
|
||||
{
|
||||
case 0:
|
||||
/* The caller must provide at least one author name. */
|
||||
abort ();
|
||||
case 1:
|
||||
/* TRANSLATORS: %s denotes an author name. */
|
||||
vfprintf (stream, _("Written by %s.\n"), authors);
|
||||
break;
|
||||
case 2:
|
||||
/* TRANSLATORS: Each %s denotes an author name. */
|
||||
vfprintf (stream, _("Written by %s and %s.\n"), authors);
|
||||
break;
|
||||
case 3:
|
||||
/* TRANSLATORS: Each %s denotes an author name. */
|
||||
vfprintf (stream, _("Written by %s, %s, and %s.\n"), authors);
|
||||
break;
|
||||
case 4:
|
||||
/* TRANSLATORS: Each %s denotes an author name.
|
||||
You can use line breaks, estimating that each author name occupies
|
||||
ca. 16 screen columns and that a screen line has ca. 80 columns. */
|
||||
vfprintf (stream, _("Written by %s, %s, %s,\nand %s.\n"), authors);
|
||||
break;
|
||||
case 5:
|
||||
/* TRANSLATORS: Each %s denotes an author name.
|
||||
You can use line breaks, estimating that each author name occupies
|
||||
ca. 16 screen columns and that a screen line has ca. 80 columns. */
|
||||
vfprintf (stream, _("Written by %s, %s, %s,\n%s, and %s.\n"), authors);
|
||||
break;
|
||||
case 6:
|
||||
/* TRANSLATORS: Each %s denotes an author name.
|
||||
You can use line breaks, estimating that each author name occupies
|
||||
ca. 16 screen columns and that a screen line has ca. 80 columns. */
|
||||
vfprintf (stream, _("Written by %s, %s, %s,\n%s, %s, and %s.\n"),
|
||||
authors);
|
||||
break;
|
||||
case 7:
|
||||
/* TRANSLATORS: Each %s denotes an author name.
|
||||
You can use line breaks, estimating that each author name occupies
|
||||
ca. 16 screen columns and that a screen line has ca. 80 columns. */
|
||||
vfprintf (stream, _("Written by %s, %s, %s,\n%s, %s, %s, and %s.\n"),
|
||||
authors);
|
||||
break;
|
||||
case 8:
|
||||
/* TRANSLATORS: Each %s denotes an author name.
|
||||
You can use line breaks, estimating that each author name occupies
|
||||
ca. 16 screen columns and that a screen line has ca. 80 columns. */
|
||||
vfprintf (stream, _("\
|
||||
Written by %s, %s, %s,\n%s, %s, %s, %s,\nand %s.\n"),
|
||||
authors);
|
||||
break;
|
||||
case 9:
|
||||
/* TRANSLATORS: Each %s denotes an author name.
|
||||
You can use line breaks, estimating that each author name occupies
|
||||
ca. 16 screen columns and that a screen line has ca. 80 columns. */
|
||||
vfprintf (stream, _("\
|
||||
Written by %s, %s, %s,\n%s, %s, %s, %s,\n%s, and %s.\n"),
|
||||
authors);
|
||||
break;
|
||||
default:
|
||||
/* 10 or more authors. Use an abbreviation, since the human reader
|
||||
will probably not want to read the entire list anyway. */
|
||||
/* TRANSLATORS: Each %s denotes an author name.
|
||||
You can use line breaks, estimating that each author name occupies
|
||||
ca. 16 screen columns and that a screen line has ca. 80 columns. */
|
||||
vfprintf (stream, _("\
|
||||
Written by %s, %s, %s,\n%s, %s, %s, %s,\n%s, %s, and others.\n"),
|
||||
authors);
|
||||
break;
|
||||
}
|
||||
va_end (authors);
|
||||
putc ('\n', stream);
|
||||
|
||||
fputs (version_etc_copyright, stream);
|
||||
putc ('\n', stream);
|
||||
|
||||
fputs (_("\
|
||||
This is free software; see the source for copying conditions. There is NO\n\
|
||||
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n"),
|
||||
stream);
|
||||
}
|
||||
|
||||
|
||||
/* Display the --version information the standard way.
|
||||
|
||||
If COMMAND_NAME is NULL, the PACKAGE is asumed to be the name of
|
||||
the program. The formats are therefore:
|
||||
|
||||
PACKAGE VERSION
|
||||
|
||||
or
|
||||
|
||||
COMMAND_NAME (PACKAGE) VERSION.
|
||||
|
||||
The author names are passed as separate arguments, with an additional
|
||||
NULL argument at the end. */
|
||||
void
|
||||
version_etc (FILE *stream,
|
||||
const char *command_name, const char *package,
|
||||
const char *version, /* const char *author1, ...*/ ...)
|
||||
{
|
||||
va_list authors;
|
||||
|
||||
va_start (authors, version);
|
||||
version_etc_va (stream, command_name, package, version, authors);
|
||||
}
|
||||
|
|
@ -1,37 +0,0 @@
|
|||
/* Utility to help print --version output in a consistent format.
|
||||
Copyright (C) 1999, 2003 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, write to the Free Software Foundation,
|
||||
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
||||
|
||||
/* Written by Jim Meyering. */
|
||||
|
||||
#ifndef VERSION_ETC_H
|
||||
# define VERSION_ETC_H 1
|
||||
|
||||
# include <stdarg.h>
|
||||
# include <stdio.h>
|
||||
|
||||
extern const char *version_etc_copyright;
|
||||
|
||||
extern void version_etc_va (FILE *stream,
|
||||
const char *command_name, const char *package,
|
||||
const char *version, va_list authors);
|
||||
|
||||
extern void version_etc (FILE *stream,
|
||||
const char *command_name, const char *package,
|
||||
const char *version,
|
||||
/* const char *author1, ...*/ ...);
|
||||
|
||||
#endif /* VERSION_ETC_H */
|
||||
|
|
@ -1,45 +0,0 @@
|
|||
/* Report a memory allocation failure and exit.
|
||||
|
||||
Copyright (C) 1997, 1998, 1999, 2000, 2002, 2003, 2004 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, write to the Free Software Foundation,
|
||||
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
||||
|
||||
#if HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#include "xalloc.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "error.h"
|
||||
#include "exitfail.h"
|
||||
|
||||
#include "gettext.h"
|
||||
#define _(msgid) gettext (msgid)
|
||||
#define N_(msgid) msgid
|
||||
|
||||
void
|
||||
xalloc_die (void)
|
||||
{
|
||||
error (exit_failure, 0, "%s", _("memory exhausted"));
|
||||
|
||||
/* The `noreturn' cannot be given to error, since it may return if
|
||||
its first argument is 0. To help compilers understand the
|
||||
xalloc_die does not return, call abort. Also, the abort is a
|
||||
safety feature if exit_failure is 0 (which shouldn't happen). */
|
||||
abort ();
|
||||
}
|
||||
|
|
@ -1,90 +0,0 @@
|
|||
/* xalloc.h -- malloc with out-of-memory checking
|
||||
|
||||
Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
|
||||
1999, 2000, 2003, 2004 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, write to the Free Software Foundation,
|
||||
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
||||
|
||||
#ifndef XALLOC_H_
|
||||
# define XALLOC_H_
|
||||
|
||||
# include <stddef.h>
|
||||
|
||||
|
||||
# ifdef __cplusplus
|
||||
extern "C" {
|
||||
# endif
|
||||
|
||||
|
||||
# ifndef __attribute__
|
||||
# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 8) || __STRICT_ANSI__
|
||||
# define __attribute__(x)
|
||||
# endif
|
||||
# endif
|
||||
|
||||
# ifndef ATTRIBUTE_NORETURN
|
||||
# define ATTRIBUTE_NORETURN __attribute__ ((__noreturn__))
|
||||
# endif
|
||||
|
||||
/* This function is always triggered when memory is exhausted.
|
||||
It must be defined by the application, either explicitly
|
||||
or by using gnulib's xalloc-die module. This is the
|
||||
function to call when one wants the program to die because of a
|
||||
memory allocation failure. */
|
||||
extern void xalloc_die (void) ATTRIBUTE_NORETURN;
|
||||
|
||||
void *xmalloc (size_t s);
|
||||
void *xnmalloc (size_t n, size_t s);
|
||||
void *xzalloc (size_t s);
|
||||
void *xcalloc (size_t n, size_t s);
|
||||
void *xrealloc (void *p, size_t s);
|
||||
void *xnrealloc (void *p, size_t n, size_t s);
|
||||
void *x2realloc (void *p, size_t *pn);
|
||||
void *x2nrealloc (void *p, size_t *pn, size_t s);
|
||||
void *xclone (void const *p, size_t s);
|
||||
char *xstrdup (const char *str);
|
||||
|
||||
/* Return 1 if an array of N objects, each of size S, cannot exist due
|
||||
to size arithmetic overflow. S must be positive and N must be
|
||||
nonnegative. This is a macro, not an inline function, so that it
|
||||
works correctly even when SIZE_MAX < N.
|
||||
|
||||
By gnulib convention, SIZE_MAX represents overflow in size
|
||||
calculations, so the conservative dividend to use here is
|
||||
SIZE_MAX - 1, since SIZE_MAX might represent an overflowed value.
|
||||
However, malloc (SIZE_MAX) fails on all known hosts where
|
||||
sizeof (ptrdiff_t) <= sizeof (size_t), so do not bother to test for
|
||||
exactly-SIZE_MAX allocations on such hosts; this avoids a test and
|
||||
branch when S is known to be 1. */
|
||||
# define xalloc_oversized(n, s) \
|
||||
((size_t) (sizeof (ptrdiff_t) <= sizeof (size_t) ? -1 : -2) / (s) < (n))
|
||||
|
||||
/* These macros are deprecated; they will go away soon, and are retained
|
||||
temporarily only to ease conversion to the functions described above. */
|
||||
# define CCLONE(p, n) xclone (p, (n) * sizeof *(p))
|
||||
# define CLONE(p) xclone (p, sizeof *(p))
|
||||
# define NEW(type, var) type *var = xmalloc (sizeof (type))
|
||||
# define XCALLOC(type, n) xcalloc (n, sizeof (type))
|
||||
# define XMALLOC(type, n) xnmalloc (n, sizeof (type))
|
||||
# define XREALLOC(p, type, n) xnrealloc (p, n, sizeof (type))
|
||||
# define XFREE(p) free (p)
|
||||
|
||||
|
||||
# ifdef __cplusplus
|
||||
}
|
||||
# endif
|
||||
|
||||
|
||||
#endif /* !XALLOC_H_ */
|
||||
|
|
@ -1,221 +0,0 @@
|
|||
/* xmalloc.c -- malloc with out of memory checking
|
||||
|
||||
Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
|
||||
1999, 2000, 2002, 2003, 2004 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, write to the Free Software Foundation,
|
||||
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
||||
|
||||
#if HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#include "xalloc.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifndef SIZE_MAX
|
||||
# define SIZE_MAX ((size_t) -1)
|
||||
#endif
|
||||
|
||||
/* Allocate an array of N objects, each with S bytes of memory,
|
||||
dynamically, with error checking. S must be nonzero. */
|
||||
|
||||
static inline void *
|
||||
xnmalloc_inline (size_t n, size_t s)
|
||||
{
|
||||
void *p;
|
||||
if (xalloc_oversized (n, s) || (! (p = malloc (n * s)) && n != 0))
|
||||
xalloc_die ();
|
||||
return p;
|
||||
}
|
||||
|
||||
void *
|
||||
xnmalloc (size_t n, size_t s)
|
||||
{
|
||||
return xnmalloc_inline (n, s);
|
||||
}
|
||||
|
||||
/* Allocate N bytes of memory dynamically, with error checking. */
|
||||
|
||||
void *
|
||||
xmalloc (size_t n)
|
||||
{
|
||||
return xnmalloc_inline (n, 1);
|
||||
}
|
||||
|
||||
/* Change the size of an allocated block of memory P to an array of N
|
||||
objects each of S bytes, with error checking. S must be nonzero. */
|
||||
|
||||
static inline void *
|
||||
xnrealloc_inline (void *p, size_t n, size_t s)
|
||||
{
|
||||
if (xalloc_oversized (n, s) || (! (p = realloc (p, n * s)) && n != 0))
|
||||
xalloc_die ();
|
||||
return p;
|
||||
}
|
||||
|
||||
void *
|
||||
xnrealloc (void *p, size_t n, size_t s)
|
||||
{
|
||||
return xnrealloc_inline (p, n, s);
|
||||
}
|
||||
|
||||
/* Change the size of an allocated block of memory P to N bytes,
|
||||
with error checking. */
|
||||
|
||||
void *
|
||||
xrealloc (void *p, size_t n)
|
||||
{
|
||||
return xnrealloc_inline (p, n, 1);
|
||||
}
|
||||
|
||||
|
||||
/* If P is null, allocate a block of at least *PN such objects;
|
||||
otherwise, reallocate P so that it contains more than *PN objects
|
||||
each of S bytes. *PN must be nonzero unless P is null, and S must
|
||||
be nonzero. Set *PN to the new number of objects, and return the
|
||||
pointer to the new block. *PN is never set to zero, and the
|
||||
returned pointer is never null.
|
||||
|
||||
Repeated reallocations are guaranteed to make progress, either by
|
||||
allocating an initial block with a nonzero size, or by allocating a
|
||||
larger block.
|
||||
|
||||
In the following implementation, nonzero sizes are doubled so that
|
||||
repeated reallocations have O(N log N) overall cost rather than
|
||||
O(N**2) cost, but the specification for this function does not
|
||||
guarantee that sizes are doubled.
|
||||
|
||||
Here is an example of use:
|
||||
|
||||
int *p = NULL;
|
||||
size_t used = 0;
|
||||
size_t allocated = 0;
|
||||
|
||||
void
|
||||
append_int (int value)
|
||||
{
|
||||
if (used == allocated)
|
||||
p = x2nrealloc (p, &allocated, sizeof *p);
|
||||
p[used++] = value;
|
||||
}
|
||||
|
||||
This causes x2nrealloc to allocate a block of some nonzero size the
|
||||
first time it is called.
|
||||
|
||||
To have finer-grained control over the initial size, set *PN to a
|
||||
nonzero value before calling this function with P == NULL. For
|
||||
example:
|
||||
|
||||
int *p = NULL;
|
||||
size_t used = 0;
|
||||
size_t allocated = 0;
|
||||
size_t allocated1 = 1000;
|
||||
|
||||
void
|
||||
append_int (int value)
|
||||
{
|
||||
if (used == allocated)
|
||||
{
|
||||
p = x2nrealloc (p, &allocated1, sizeof *p);
|
||||
allocated = allocated1;
|
||||
}
|
||||
p[used++] = value;
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
static inline void *
|
||||
x2nrealloc_inline (void *p, size_t *pn, size_t s)
|
||||
{
|
||||
size_t n = *pn;
|
||||
|
||||
if (! p)
|
||||
{
|
||||
if (! n)
|
||||
{
|
||||
/* The approximate size to use for initial small allocation
|
||||
requests, when the invoking code specifies an old size of
|
||||
zero. 64 bytes is the largest "small" request for the
|
||||
GNU C library malloc. */
|
||||
enum { DEFAULT_MXFAST = 64 };
|
||||
|
||||
n = DEFAULT_MXFAST / s;
|
||||
n += !n;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (SIZE_MAX / 2 / s < n)
|
||||
xalloc_die ();
|
||||
n *= 2;
|
||||
}
|
||||
|
||||
*pn = n;
|
||||
return xrealloc (p, n * s);
|
||||
}
|
||||
|
||||
void *
|
||||
x2nrealloc (void *p, size_t *pn, size_t s)
|
||||
{
|
||||
return x2nrealloc_inline (p, pn, s);
|
||||
}
|
||||
|
||||
/* If P is null, allocate a block of at least *PN bytes; otherwise,
|
||||
reallocate P so that it contains more than *PN bytes. *PN must be
|
||||
nonzero unless P is null. Set *PN to the new block's size, and
|
||||
return the pointer to the new block. *PN is never set to zero, and
|
||||
the returned pointer is never null. */
|
||||
|
||||
void *
|
||||
x2realloc (void *p, size_t *pn)
|
||||
{
|
||||
return x2nrealloc_inline (p, pn, 1);
|
||||
}
|
||||
|
||||
/* Allocate S bytes of zeroed memory dynamically, with error checking.
|
||||
There's no need for xnzalloc (N, S), since it would be equivalent
|
||||
to xcalloc (N, S). */
|
||||
|
||||
void *
|
||||
xzalloc (size_t s)
|
||||
{
|
||||
return memset (xmalloc (s), 0, s);
|
||||
}
|
||||
|
||||
/* Allocate zeroed memory for N elements of S bytes, with error
|
||||
checking. S must be nonzero. */
|
||||
|
||||
void *
|
||||
xcalloc (size_t n, size_t s)
|
||||
{
|
||||
void *p;
|
||||
/* Test for overflow, since some calloc implementations don't have
|
||||
proper overflow checks. */
|
||||
if (xalloc_oversized (n, s) || (! (p = calloc (n, s)) && n != 0))
|
||||
xalloc_die ();
|
||||
return p;
|
||||
}
|
||||
|
||||
/* Clone an object P of size S, with error checking. There's no need
|
||||
for xnclone (P, N, S), since xclone (P, N * S) works without any
|
||||
need for an arithmetic overflow check. */
|
||||
|
||||
void *
|
||||
xclone (void const *p, size_t s)
|
||||
{
|
||||
return memcpy (xmalloc (s), p, s);
|
||||
}
|
||||
|
|
@ -1,59 +0,0 @@
|
|||
/* Locale-specific memory comparison.
|
||||
Copyright (C) 2002, 2003, 2004 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, write to the Free Software Foundation,
|
||||
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
||||
|
||||
/* Contributed by Paul Eggert <eggert@twinsun.com>. */
|
||||
|
||||
#if HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "gettext.h"
|
||||
#define _(msgid) gettext (msgid)
|
||||
|
||||
#include "error.h"
|
||||
#include "exitfail.h"
|
||||
#include "memcoll.h"
|
||||
#include "quotearg.h"
|
||||
#include "xmemcoll.h"
|
||||
|
||||
/* Compare S1 (with length S1LEN) and S2 (with length S2LEN) according
|
||||
to the LC_COLLATE locale. S1 and S2 do not overlap, and are not
|
||||
adjacent. Temporarily modify the bytes after S1 and S2, but
|
||||
restore their original contents before returning. Report an error
|
||||
and exit if there is an error. */
|
||||
|
||||
int
|
||||
xmemcoll (char *s1, size_t s1len, char *s2, size_t s2len)
|
||||
{
|
||||
int diff = memcoll (s1, s1len, s2, s2len);
|
||||
int collation_errno = errno;
|
||||
|
||||
if (collation_errno)
|
||||
{
|
||||
error (0, collation_errno, _("string comparison failed"));
|
||||
error (0, 0, _("Set LC_ALL='C' to work around the problem."));
|
||||
error (exit_failure, 0,
|
||||
_("The strings compared were %s and %s."),
|
||||
quotearg_n_style_mem (0, locale_quoting_style, s1, s1len),
|
||||
quotearg_n_style_mem (1, locale_quoting_style, s2, s2len));
|
||||
}
|
||||
|
||||
return diff;
|
||||
}
|
||||
|
|
@ -1,2 +0,0 @@
|
|||
#include <stddef.h>
|
||||
int xmemcoll (char *, size_t, char *, size_t);
|
||||
|
|
@ -1,291 +0,0 @@
|
|||
/* A more useful interface to strtol.
|
||||
|
||||
Copyright (C) 1995, 1996, 1998, 1999, 2000, 2001, 2003, 2004 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, write to the Free Software Foundation,
|
||||
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
||||
|
||||
/* Written by Jim Meyering. */
|
||||
|
||||
#if HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#ifndef __strtol
|
||||
# define __strtol strtol
|
||||
# define __strtol_t long int
|
||||
# define __xstrtol xstrtol
|
||||
# define STRTOL_T_MINIMUM LONG_MIN
|
||||
# define STRTOL_T_MAXIMUM LONG_MAX
|
||||
#endif
|
||||
|
||||
/* Some pre-ANSI implementations (e.g. SunOS 4)
|
||||
need stderr defined if assertion checking is enabled. */
|
||||
#include <stdio.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
/* The extra casts work around common compiler bugs. */
|
||||
#define TYPE_SIGNED(t) (! ((t) 0 < (t) -1))
|
||||
#define TYPE_MINIMUM(t) ((t) (TYPE_SIGNED (t) \
|
||||
? ~ (t) 0 << (sizeof (t) * CHAR_BIT - 1) \
|
||||
: (t) 0))
|
||||
#define TYPE_MAXIMUM(t) ((t) (~ (t) 0 - TYPE_MINIMUM (t)))
|
||||
|
||||
#ifndef STRTOL_T_MINIMUM
|
||||
# define STRTOL_T_MINIMUM TYPE_MINIMUM (__strtol_t)
|
||||
# define STRTOL_T_MAXIMUM TYPE_MAXIMUM (__strtol_t)
|
||||
#endif
|
||||
|
||||
#if defined (STDC_HEADERS) || (!defined (isascii) && !defined (HAVE_ISASCII))
|
||||
# define IN_CTYPE_DOMAIN(c) 1
|
||||
#else
|
||||
# define IN_CTYPE_DOMAIN(c) isascii(c)
|
||||
#endif
|
||||
|
||||
#define ISSPACE(c) (IN_CTYPE_DOMAIN (c) && isspace (c))
|
||||
|
||||
#include "xstrtol.h"
|
||||
|
||||
#if !HAVE_DECL_STRTOIMAX && !defined strtoimax
|
||||
intmax_t strtoimax ();
|
||||
#endif
|
||||
|
||||
#if !HAVE_DECL_STRTOUMAX && !defined strtoumax
|
||||
uintmax_t strtoumax ();
|
||||
#endif
|
||||
|
||||
static strtol_error
|
||||
bkm_scale (__strtol_t *x, int scale_factor)
|
||||
{
|
||||
if (TYPE_SIGNED (__strtol_t) && *x < STRTOL_T_MINIMUM / scale_factor)
|
||||
{
|
||||
*x = STRTOL_T_MINIMUM;
|
||||
return LONGINT_OVERFLOW;
|
||||
}
|
||||
if (STRTOL_T_MAXIMUM / scale_factor < *x)
|
||||
{
|
||||
*x = STRTOL_T_MAXIMUM;
|
||||
return LONGINT_OVERFLOW;
|
||||
}
|
||||
*x *= scale_factor;
|
||||
return LONGINT_OK;
|
||||
}
|
||||
|
||||
static strtol_error
|
||||
bkm_scale_by_power (__strtol_t *x, int base, int power)
|
||||
{
|
||||
strtol_error err = LONGINT_OK;
|
||||
while (power--)
|
||||
err |= bkm_scale (x, base);
|
||||
return err;
|
||||
}
|
||||
|
||||
/* FIXME: comment. */
|
||||
|
||||
strtol_error
|
||||
__xstrtol (const char *s, char **ptr, int strtol_base,
|
||||
__strtol_t *val, const char *valid_suffixes)
|
||||
{
|
||||
char *t_ptr;
|
||||
char **p;
|
||||
__strtol_t tmp;
|
||||
strtol_error err = LONGINT_OK;
|
||||
|
||||
assert (0 <= strtol_base && strtol_base <= 36);
|
||||
|
||||
p = (ptr ? ptr : &t_ptr);
|
||||
|
||||
if (! TYPE_SIGNED (__strtol_t))
|
||||
{
|
||||
const char *q = s;
|
||||
unsigned char ch = *q;
|
||||
while (ISSPACE (ch))
|
||||
ch = *++q;
|
||||
if (ch == '-')
|
||||
return LONGINT_INVALID;
|
||||
}
|
||||
|
||||
errno = 0;
|
||||
tmp = __strtol (s, p, strtol_base);
|
||||
|
||||
if (*p == s)
|
||||
{
|
||||
/* If there is no number but there is a valid suffix, assume the
|
||||
number is 1. The string is invalid otherwise. */
|
||||
if (valid_suffixes && **p && strchr (valid_suffixes, **p))
|
||||
tmp = 1;
|
||||
else
|
||||
return LONGINT_INVALID;
|
||||
}
|
||||
else if (errno != 0)
|
||||
{
|
||||
if (errno != ERANGE)
|
||||
return LONGINT_INVALID;
|
||||
err = LONGINT_OVERFLOW;
|
||||
}
|
||||
|
||||
/* Let valid_suffixes == NULL mean `allow any suffix'. */
|
||||
/* FIXME: update all callers except the ones that allow suffixes
|
||||
after the number, changing last parameter NULL to `""'. */
|
||||
if (!valid_suffixes)
|
||||
{
|
||||
*val = tmp;
|
||||
return err;
|
||||
}
|
||||
|
||||
if (**p != '\0')
|
||||
{
|
||||
int base = 1024;
|
||||
int suffixes = 1;
|
||||
strtol_error overflow;
|
||||
|
||||
if (!strchr (valid_suffixes, **p))
|
||||
{
|
||||
*val = tmp;
|
||||
return err | LONGINT_INVALID_SUFFIX_CHAR;
|
||||
}
|
||||
|
||||
if (strchr (valid_suffixes, '0'))
|
||||
{
|
||||
/* The ``valid suffix'' '0' is a special flag meaning that
|
||||
an optional second suffix is allowed, which can change
|
||||
the base. A suffix "B" (e.g. "100MB") stands for a power
|
||||
of 1000, whereas a suffix "iB" (e.g. "100MiB") stands for
|
||||
a power of 1024. If no suffix (e.g. "100M"), assume
|
||||
power-of-1024. */
|
||||
|
||||
switch (p[0][1])
|
||||
{
|
||||
case 'i':
|
||||
if (p[0][2] == 'B')
|
||||
suffixes += 2;
|
||||
break;
|
||||
|
||||
case 'B':
|
||||
case 'D': /* 'D' is obsolescent */
|
||||
base = 1000;
|
||||
suffixes++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
switch (**p)
|
||||
{
|
||||
case 'b':
|
||||
overflow = bkm_scale (&tmp, 512);
|
||||
break;
|
||||
|
||||
case 'B':
|
||||
overflow = bkm_scale (&tmp, 1024);
|
||||
break;
|
||||
|
||||
case 'c':
|
||||
overflow = 0;
|
||||
break;
|
||||
|
||||
case 'E': /* exa or exbi */
|
||||
overflow = bkm_scale_by_power (&tmp, base, 6);
|
||||
break;
|
||||
|
||||
case 'G': /* giga or gibi */
|
||||
case 'g': /* 'g' is undocumented; for compatibility only */
|
||||
overflow = bkm_scale_by_power (&tmp, base, 3);
|
||||
break;
|
||||
|
||||
case 'k': /* kilo */
|
||||
case 'K': /* kibi */
|
||||
overflow = bkm_scale_by_power (&tmp, base, 1);
|
||||
break;
|
||||
|
||||
case 'M': /* mega or mebi */
|
||||
case 'm': /* 'm' is undocumented; for compatibility only */
|
||||
overflow = bkm_scale_by_power (&tmp, base, 2);
|
||||
break;
|
||||
|
||||
case 'P': /* peta or pebi */
|
||||
overflow = bkm_scale_by_power (&tmp, base, 5);
|
||||
break;
|
||||
|
||||
case 'T': /* tera or tebi */
|
||||
case 't': /* 't' is undocumented; for compatibility only */
|
||||
overflow = bkm_scale_by_power (&tmp, base, 4);
|
||||
break;
|
||||
|
||||
case 'w':
|
||||
overflow = bkm_scale (&tmp, 2);
|
||||
break;
|
||||
|
||||
case 'Y': /* yotta or 2**80 */
|
||||
overflow = bkm_scale_by_power (&tmp, base, 8);
|
||||
break;
|
||||
|
||||
case 'Z': /* zetta or 2**70 */
|
||||
overflow = bkm_scale_by_power (&tmp, base, 7);
|
||||
break;
|
||||
|
||||
default:
|
||||
*val = tmp;
|
||||
return err | LONGINT_INVALID_SUFFIX_CHAR;
|
||||
}
|
||||
|
||||
err |= overflow;
|
||||
*p += suffixes;
|
||||
if (**p)
|
||||
err |= LONGINT_INVALID_SUFFIX_CHAR;
|
||||
}
|
||||
|
||||
*val = tmp;
|
||||
return err;
|
||||
}
|
||||
|
||||
#ifdef TESTING_XSTRTO
|
||||
|
||||
# include <stdio.h>
|
||||
# include "error.h"
|
||||
|
||||
char *program_name;
|
||||
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
{
|
||||
strtol_error s_err;
|
||||
int i;
|
||||
|
||||
program_name = argv[0];
|
||||
for (i=1; i<argc; i++)
|
||||
{
|
||||
char *p;
|
||||
__strtol_t val;
|
||||
|
||||
s_err = __xstrtol (argv[i], &p, 0, &val, "bckmw");
|
||||
if (s_err == LONGINT_OK)
|
||||
{
|
||||
printf ("%s->%lu (%s)\n", argv[i], val, p);
|
||||
}
|
||||
else
|
||||
{
|
||||
STRTOL_FATAL_ERROR (argv[i], "arg", s_err);
|
||||
}
|
||||
}
|
||||
exit (0);
|
||||
}
|
||||
|
||||
#endif /* TESTING_XSTRTO */
|
||||
|
|
@ -1,89 +0,0 @@
|
|||
/* A more useful interface to strtol.
|
||||
|
||||
Copyright (C) 1995, 1996, 1998, 1999, 2001, 2002, 2003, 2004 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, write to the Free Software Foundation,
|
||||
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
||||
|
||||
#ifndef XSTRTOL_H_
|
||||
# define XSTRTOL_H_ 1
|
||||
|
||||
# include "exitfail.h"
|
||||
|
||||
# if HAVE_INTTYPES_H
|
||||
# include <inttypes.h>
|
||||
# endif
|
||||
# if HAVE_STDINT_H
|
||||
# include <stdint.h>
|
||||
# endif
|
||||
|
||||
# ifndef _STRTOL_ERROR
|
||||
enum strtol_error
|
||||
{
|
||||
LONGINT_OK = 0,
|
||||
|
||||
/* These two values can be ORed together, to indicate that both
|
||||
errors occurred. */
|
||||
LONGINT_OVERFLOW = 1,
|
||||
LONGINT_INVALID_SUFFIX_CHAR = 2,
|
||||
|
||||
LONGINT_INVALID_SUFFIX_CHAR_WITH_OVERFLOW = (LONGINT_INVALID_SUFFIX_CHAR
|
||||
| LONGINT_OVERFLOW),
|
||||
LONGINT_INVALID = 4
|
||||
};
|
||||
typedef enum strtol_error strtol_error;
|
||||
# endif
|
||||
|
||||
# define _DECLARE_XSTRTOL(name, type) \
|
||||
strtol_error name (const char *, char **, int, type *, const char *);
|
||||
_DECLARE_XSTRTOL (xstrtol, long int)
|
||||
_DECLARE_XSTRTOL (xstrtoul, unsigned long int)
|
||||
_DECLARE_XSTRTOL (xstrtoimax, intmax_t)
|
||||
_DECLARE_XSTRTOL (xstrtoumax, uintmax_t)
|
||||
|
||||
# define _STRTOL_ERROR(Exit_code, Str, Argument_type_string, Err) \
|
||||
do \
|
||||
{ \
|
||||
switch ((Err)) \
|
||||
{ \
|
||||
default: \
|
||||
abort (); \
|
||||
\
|
||||
case LONGINT_INVALID: \
|
||||
error ((Exit_code), 0, "invalid %s `%s'", \
|
||||
(Argument_type_string), (Str)); \
|
||||
break; \
|
||||
\
|
||||
case LONGINT_INVALID_SUFFIX_CHAR: \
|
||||
case LONGINT_INVALID_SUFFIX_CHAR | LONGINT_OVERFLOW: \
|
||||
error ((Exit_code), 0, "invalid character following %s in `%s'", \
|
||||
(Argument_type_string), (Str)); \
|
||||
break; \
|
||||
\
|
||||
case LONGINT_OVERFLOW: \
|
||||
error ((Exit_code), 0, "%s `%s' too large", \
|
||||
(Argument_type_string), (Str)); \
|
||||
break; \
|
||||
} \
|
||||
} \
|
||||
while (0)
|
||||
|
||||
# define STRTOL_FATAL_ERROR(Str, Argument_type_string, Err) \
|
||||
_STRTOL_ERROR (exit_failure, Str, Argument_type_string, Err)
|
||||
|
||||
# define STRTOL_FAIL_WARN(Str, Argument_type_string, Err) \
|
||||
_STRTOL_ERROR (0, Str, Argument_type_string, Err)
|
||||
|
||||
#endif /* not XSTRTOL_H_ */
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
#define __strtol strtoul
|
||||
#define __strtol_t unsigned long int
|
||||
#define __xstrtol xstrtoul
|
||||
#define STRTOL_T_MINIMUM 0
|
||||
#define STRTOL_T_MAXIMUM ULONG_MAX
|
||||
#include "xstrtol.c"
|
||||
|
|
@ -1,33 +0,0 @@
|
|||
/* xstrtoumax.c -- A more useful interface to strtoumax.
|
||||
Copyright (C) 1999, 2003, 2004 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, write to the Free Software Foundation,
|
||||
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
||||
|
||||
/* Written by Paul Eggert. */
|
||||
|
||||
#if HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#include "xstrtol.h"
|
||||
|
||||
#define __strtol strtoumax
|
||||
#define __strtol_t uintmax_t
|
||||
#define __xstrtol xstrtoumax
|
||||
#ifdef UINTMAX_MAX
|
||||
# define STRTOL_T_MINIMUM 0
|
||||
# define STRTOL_T_MAXIMUM UINTMAX_MAX
|
||||
#endif
|
||||
#include "xstrtol.c"
|
||||
|
|
@ -1,113 +0,0 @@
|
|||
.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.33.
|
||||
.TH SORT "1" "March 2004" "sort (coreutils) 5.2.1" "User Commands"
|
||||
.SH NAME
|
||||
sort \- sort lines of text files
|
||||
.SH SYNOPSIS
|
||||
.B sort
|
||||
[\fIOPTION\fR]... [\fIFILE\fR]...
|
||||
.SH DESCRIPTION
|
||||
.\" Add any additional description here
|
||||
.PP
|
||||
Write sorted concatenation of all FILE(s) to standard output.
|
||||
.PP
|
||||
Ordering options:
|
||||
.PP
|
||||
Mandatory arguments to long options are mandatory for short options too.
|
||||
.HP
|
||||
\fB\-b\fR, \fB\-\-ignore\-leading\-blanks\fR ignore leading blanks
|
||||
.TP
|
||||
\fB\-d\fR, \fB\-\-dictionary\-order\fR
|
||||
consider only blanks and alphanumeric characters
|
||||
.TP
|
||||
\fB\-f\fR, \fB\-\-ignore\-case\fR
|
||||
fold lower case to upper case characters
|
||||
.TP
|
||||
\fB\-g\fR, \fB\-\-general\-numeric\-sort\fR
|
||||
compare according to general numerical value
|
||||
.TP
|
||||
\fB\-i\fR, \fB\-\-ignore\-nonprinting\fR
|
||||
consider only printable characters
|
||||
.TP
|
||||
\fB\-M\fR, \fB\-\-month\-sort\fR
|
||||
compare (unknown) < `JAN' < ... < `DEC'
|
||||
.TP
|
||||
\fB\-n\fR, \fB\-\-numeric\-sort\fR
|
||||
compare according to string numerical value
|
||||
.TP
|
||||
\fB\-r\fR, \fB\-\-reverse\fR
|
||||
reverse the result of comparisons
|
||||
.PP
|
||||
Other options:
|
||||
.TP
|
||||
\fB\-c\fR, \fB\-\-check\fR
|
||||
check whether input is sorted; do not sort
|
||||
.TP
|
||||
\fB\-k\fR, \fB\-\-key\fR=\fIPOS1[\fR,POS2]
|
||||
start a key at POS1, end it at POS 2 (origin 1)
|
||||
.TP
|
||||
\fB\-m\fR, \fB\-\-merge\fR
|
||||
merge already sorted files; do not sort
|
||||
.TP
|
||||
\fB\-o\fR, \fB\-\-output\fR=\fIFILE\fR
|
||||
write result to FILE instead of standard output
|
||||
.TP
|
||||
\fB\-s\fR, \fB\-\-stable\fR
|
||||
stabilize sort by disabling last-resort comparison
|
||||
.TP
|
||||
\fB\-S\fR, \fB\-\-buffer\-size\fR=\fISIZE\fR
|
||||
use SIZE for main memory buffer
|
||||
.HP
|
||||
\fB\-t\fR, \fB\-\-field\-separator\fR=\fISEP\fR use SEP instead of non-blank to blank transition
|
||||
.TP
|
||||
\fB\-T\fR, \fB\-\-temporary\-directory\fR=\fIDIR\fR
|
||||
use DIR for temporaries, not $TMPDIR or /tmp;
|
||||
multiple options specify multiple directories
|
||||
.TP
|
||||
\fB\-u\fR, \fB\-\-unique\fR
|
||||
with \fB\-c\fR, check for strict ordering;
|
||||
without \fB\-c\fR, output only the first of an equal run
|
||||
.TP
|
||||
\fB\-z\fR, \fB\-\-zero\-terminated\fR
|
||||
end lines with 0 byte, not newline
|
||||
.TP
|
||||
\fB\-\-help\fR
|
||||
display this help and exit
|
||||
.TP
|
||||
\fB\-\-version\fR
|
||||
output version information and exit
|
||||
.PP
|
||||
POS is F[.C][OPTS], where F is the field number and C the character position
|
||||
in the field. OPTS is one or more single-letter ordering options, which
|
||||
override global ordering options for that key. If no key is given, use the
|
||||
entire line as the key.
|
||||
.PP
|
||||
SIZE may be followed by the following multiplicative suffixes:
|
||||
% 1% of memory, b 1, K 1024 (default), and so on for M, G, T, P, E, Z, Y.
|
||||
.PP
|
||||
With no FILE, or when FILE is -, read standard input.
|
||||
.PP
|
||||
*** WARNING ***
|
||||
The locale specified by the environment affects sort order.
|
||||
Set LC_ALL=C to get the traditional sort order that uses
|
||||
native byte values.
|
||||
.SH AUTHOR
|
||||
Written by Mike Haertel and Paul Eggert.
|
||||
.SH "REPORTING BUGS"
|
||||
Report bugs to <bug-coreutils@gnu.org>.
|
||||
.SH COPYRIGHT
|
||||
Copyright \(co 2004 Free Software Foundation, Inc.
|
||||
.br
|
||||
This is free software; see the source for copying conditions. There is NO
|
||||
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
.SH "SEE ALSO"
|
||||
The full documentation for
|
||||
.B sort
|
||||
is maintained as a Texinfo manual. If the
|
||||
.B info
|
||||
and
|
||||
.B sort
|
||||
programs are properly installed at your site, the command
|
||||
.IP
|
||||
.B info coreutils sort
|
||||
.PP
|
||||
should give you access to the complete manual.
|
||||
File diff suppressed because it is too large
Load diff
|
|
@ -1,831 +0,0 @@
|
|||
/* system-dependent definitions for fileutils, textutils, and sh-utils packages.
|
||||
Copyright (C) 1989, 1991-2004 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, write to the Free Software Foundation,
|
||||
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
||||
|
||||
#include <alloca.h>
|
||||
|
||||
/* Include sys/types.h before this file. */
|
||||
|
||||
#if 2 <= __GLIBC__ && 2 <= __GLIBC_MINOR__
|
||||
# if ! defined _SYS_TYPES_H
|
||||
you must include <sys/types.h> before including this file
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#include <sys/stat.h>
|
||||
|
||||
#if !defined HAVE_MKFIFO
|
||||
# define mkfifo(path, mode) (mknod ((path), (mode) | S_IFIFO, 0))
|
||||
#endif
|
||||
|
||||
#if HAVE_SYS_PARAM_H
|
||||
# include <sys/param.h>
|
||||
#endif
|
||||
|
||||
/* <unistd.h> should be included before any preprocessor test
|
||||
of _POSIX_VERSION. */
|
||||
#if HAVE_UNISTD_H
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
#ifndef STDIN_FILENO
|
||||
# define STDIN_FILENO 0
|
||||
#endif
|
||||
|
||||
#ifndef STDOUT_FILENO
|
||||
# define STDOUT_FILENO 1
|
||||
#endif
|
||||
|
||||
#ifndef STDERR_FILENO
|
||||
# define STDERR_FILENO 2
|
||||
#endif
|
||||
|
||||
|
||||
/* limits.h must come before pathmax.h because limits.h on some systems
|
||||
undefs PATH_MAX, whereas pathmax.h sets PATH_MAX. */
|
||||
#include <limits.h>
|
||||
|
||||
#include "pathmax.h"
|
||||
#include "localedir.h"
|
||||
|
||||
#if TIME_WITH_SYS_TIME
|
||||
# include <sys/time.h>
|
||||
# include <time.h>
|
||||
#else
|
||||
# if HAVE_SYS_TIME_H
|
||||
# include <sys/time.h>
|
||||
# else
|
||||
# include <time.h>
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* Since major is a function on SVR4, we can't use `ifndef major'. */
|
||||
#if MAJOR_IN_MKDEV
|
||||
# include <sys/mkdev.h>
|
||||
# define HAVE_MAJOR
|
||||
#endif
|
||||
#if MAJOR_IN_SYSMACROS
|
||||
# include <sys/sysmacros.h>
|
||||
# define HAVE_MAJOR
|
||||
#endif
|
||||
#ifdef major /* Might be defined in sys/types.h. */
|
||||
# define HAVE_MAJOR
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_MAJOR
|
||||
# define major(dev) (((dev) >> 8) & 0xff)
|
||||
# define minor(dev) ((dev) & 0xff)
|
||||
# define makedev(maj, min) (((maj) << 8) | (min))
|
||||
#endif
|
||||
#undef HAVE_MAJOR
|
||||
|
||||
#if ! defined makedev && defined mkdev
|
||||
# define makedev(maj, min) mkdev (maj, min)
|
||||
#endif
|
||||
|
||||
#if HAVE_UTIME_H
|
||||
# include <utime.h>
|
||||
#endif
|
||||
|
||||
/* Some systems (even some that do have <utime.h>) don't declare this
|
||||
structure anywhere. */
|
||||
#ifndef HAVE_STRUCT_UTIMBUF
|
||||
struct utimbuf
|
||||
{
|
||||
long actime;
|
||||
long modtime;
|
||||
};
|
||||
#endif
|
||||
|
||||
/* Don't use bcopy! Use memmove if source and destination may overlap,
|
||||
memcpy otherwise. */
|
||||
|
||||
#include <string.h>
|
||||
#if ! HAVE_DECL_MEMRCHR
|
||||
void *memrchr (const void *, int, size_t);
|
||||
#endif
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
/* Some systems don't define the following symbols. */
|
||||
#ifndef ENOSYS
|
||||
# define ENOSYS (-1)
|
||||
#endif
|
||||
#ifndef EISDIR
|
||||
# define EISDIR (-1)
|
||||
#endif
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#define getopt system_getopt
|
||||
#include <stdlib.h>
|
||||
#undef getopt
|
||||
|
||||
/* The following test is to work around the gross typo in
|
||||
systems like Sony NEWS-OS Release 4.0C, whereby EXIT_FAILURE
|
||||
is defined to 0, not 1. */
|
||||
#if !EXIT_FAILURE
|
||||
# undef EXIT_FAILURE
|
||||
# define EXIT_FAILURE 1
|
||||
#endif
|
||||
|
||||
#ifndef EXIT_SUCCESS
|
||||
# define EXIT_SUCCESS 0
|
||||
#endif
|
||||
|
||||
/* Exit statuses for programs like 'env' that exec other programs.
|
||||
EXIT_FAILURE might not be 1, so use EXIT_FAIL in such programs. */
|
||||
enum
|
||||
{
|
||||
EXIT_FAIL = 1,
|
||||
EXIT_CANNOT_INVOKE = 126,
|
||||
EXIT_ENOENT = 127
|
||||
};
|
||||
|
||||
#include "exitfail.h"
|
||||
|
||||
/* Set exit_failure to STATUS if that's not the default already. */
|
||||
static inline void
|
||||
initialize_exit_failure (int status)
|
||||
{
|
||||
if (status != EXIT_FAILURE)
|
||||
exit_failure = status;
|
||||
}
|
||||
|
||||
#if HAVE_FCNTL_H
|
||||
# include <fcntl.h>
|
||||
#else
|
||||
# include <sys/file.h>
|
||||
#endif
|
||||
|
||||
#if !defined SEEK_SET
|
||||
# define SEEK_SET 0
|
||||
# define SEEK_CUR 1
|
||||
# define SEEK_END 2
|
||||
#endif
|
||||
#ifndef F_OK
|
||||
# define F_OK 0
|
||||
# define X_OK 1
|
||||
# define W_OK 2
|
||||
# define R_OK 4
|
||||
#endif
|
||||
|
||||
/* For systems that distinguish between text and binary I/O.
|
||||
O_BINARY is usually declared in fcntl.h */
|
||||
#if !defined O_BINARY && defined _O_BINARY
|
||||
/* For MSC-compatible compilers. */
|
||||
# define O_BINARY _O_BINARY
|
||||
# define O_TEXT _O_TEXT
|
||||
#endif
|
||||
|
||||
#if !defined O_DIRECT
|
||||
# define O_DIRECT 0
|
||||
#endif
|
||||
|
||||
#if !defined O_DSYNC
|
||||
# define O_DSYNC 0
|
||||
#endif
|
||||
|
||||
#if !defined O_NDELAY
|
||||
# define O_NDELAY 0
|
||||
#endif
|
||||
|
||||
#if !defined O_NONBLOCK
|
||||
# define O_NONBLOCK O_NDELAY
|
||||
#endif
|
||||
|
||||
#if !defined O_NOCTTY
|
||||
# define O_NOCTTY 0
|
||||
#endif
|
||||
|
||||
#if !defined O_NOFOLLOW
|
||||
# define O_NOFOLLOW 0
|
||||
#endif
|
||||
|
||||
#if !defined O_RSYNC
|
||||
# define O_RSYNC 0
|
||||
#endif
|
||||
|
||||
#if !defined O_SYNC
|
||||
# define O_SYNC 0
|
||||
#endif
|
||||
|
||||
#ifdef __BEOS__
|
||||
/* BeOS 5 has O_BINARY and O_TEXT, but they have no effect. */
|
||||
# undef O_BINARY
|
||||
# undef O_TEXT
|
||||
#endif
|
||||
|
||||
#if O_BINARY
|
||||
# ifndef __DJGPP__
|
||||
# define setmode _setmode
|
||||
# define fileno(_fp) _fileno (_fp)
|
||||
# endif /* not DJGPP */
|
||||
# define SET_MODE(_f, _m) setmode (_f, _m)
|
||||
# define SET_BINARY(_f) do {if (!isatty(_f)) setmode (_f, O_BINARY);} while (0)
|
||||
# define SET_BINARY2(_f1, _f2) \
|
||||
do { \
|
||||
if (!isatty (_f1)) \
|
||||
{ \
|
||||
setmode (_f1, O_BINARY); \
|
||||
if (!isatty (_f2)) \
|
||||
setmode (_f2, O_BINARY); \
|
||||
} \
|
||||
} while(0)
|
||||
#else
|
||||
# define SET_MODE(_f, _m) (void)0
|
||||
# define SET_BINARY(f) (void)0
|
||||
# define SET_BINARY2(f1,f2) (void)0
|
||||
# ifndef O_BINARY
|
||||
# define O_BINARY 0
|
||||
# endif
|
||||
# define O_TEXT 0
|
||||
#endif /* O_BINARY */
|
||||
|
||||
#if HAVE_DIRENT_H
|
||||
# include <dirent.h>
|
||||
# define NLENGTH(direct) (strlen((direct)->d_name))
|
||||
#else /* not HAVE_DIRENT_H */
|
||||
# define dirent direct
|
||||
# define NLENGTH(direct) ((direct)->d_namlen)
|
||||
# if HAVE_SYS_NDIR_H
|
||||
# include <sys/ndir.h>
|
||||
# endif /* HAVE_SYS_NDIR_H */
|
||||
# if HAVE_SYS_DIR_H
|
||||
# include <sys/dir.h>
|
||||
# endif /* HAVE_SYS_DIR_H */
|
||||
# if HAVE_NDIR_H
|
||||
# include <ndir.h>
|
||||
# endif /* HAVE_NDIR_H */
|
||||
#endif /* HAVE_DIRENT_H */
|
||||
|
||||
#if CLOSEDIR_VOID
|
||||
/* Fake a return value. */
|
||||
# define CLOSEDIR(d) (closedir (d), 0)
|
||||
#else
|
||||
# define CLOSEDIR(d) closedir (d)
|
||||
#endif
|
||||
|
||||
/* Get or fake the disk device blocksize.
|
||||
Usually defined by sys/param.h (if at all). */
|
||||
#if !defined DEV_BSIZE && defined BSIZE
|
||||
# define DEV_BSIZE BSIZE
|
||||
#endif
|
||||
#if !defined DEV_BSIZE && defined BBSIZE /* SGI */
|
||||
# define DEV_BSIZE BBSIZE
|
||||
#endif
|
||||
#ifndef DEV_BSIZE
|
||||
# define DEV_BSIZE 4096
|
||||
#endif
|
||||
|
||||
/* Extract or fake data from a `struct stat'.
|
||||
ST_BLKSIZE: Preferred I/O blocksize for the file, in bytes.
|
||||
ST_NBLOCKS: Number of blocks in the file, including indirect blocks.
|
||||
ST_NBLOCKSIZE: Size of blocks used when calculating ST_NBLOCKS. */
|
||||
#ifndef HAVE_STRUCT_STAT_ST_BLOCKS
|
||||
# define ST_BLKSIZE(statbuf) DEV_BSIZE
|
||||
# if defined _POSIX_SOURCE || !defined BSIZE /* fileblocks.c uses BSIZE. */
|
||||
# define ST_NBLOCKS(statbuf) \
|
||||
((statbuf).st_size / ST_NBLOCKSIZE + ((statbuf).st_size % ST_NBLOCKSIZE != 0))
|
||||
# else /* !_POSIX_SOURCE && BSIZE */
|
||||
# define ST_NBLOCKS(statbuf) \
|
||||
(S_ISREG ((statbuf).st_mode) \
|
||||
|| S_ISDIR ((statbuf).st_mode) \
|
||||
? st_blocks ((statbuf).st_size) : 0)
|
||||
# endif /* !_POSIX_SOURCE && BSIZE */
|
||||
#else /* HAVE_STRUCT_STAT_ST_BLOCKS */
|
||||
/* Some systems, like Sequents, return st_blksize of 0 on pipes.
|
||||
Also, when running `rsh hpux11-system cat any-file', cat would
|
||||
determine that the output stream had an st_blksize of 2147421096.
|
||||
So here we arbitrarily limit the `optimal' block size to 4MB.
|
||||
If anyone knows of a system for which the legitimate value for
|
||||
st_blksize can exceed 4MB, please report it as a bug in this code. */
|
||||
# define ST_BLKSIZE(statbuf) ((0 < (statbuf).st_blksize \
|
||||
&& (statbuf).st_blksize <= (1 << 22)) /* 4MB */ \
|
||||
? (statbuf).st_blksize : DEV_BSIZE)
|
||||
# if defined hpux || defined __hpux__ || defined __hpux
|
||||
/* HP-UX counts st_blocks in 1024-byte units.
|
||||
This loses when mixing HP-UX and BSD file systems with NFS. */
|
||||
# define ST_NBLOCKSIZE 1024
|
||||
# else /* !hpux */
|
||||
# if defined _AIX && defined _I386
|
||||
/* AIX PS/2 counts st_blocks in 4K units. */
|
||||
# define ST_NBLOCKSIZE (4 * 1024)
|
||||
# else /* not AIX PS/2 */
|
||||
# if defined _CRAY
|
||||
# define ST_NBLOCKS(statbuf) \
|
||||
(S_ISREG ((statbuf).st_mode) \
|
||||
|| S_ISDIR ((statbuf).st_mode) \
|
||||
? (statbuf).st_blocks * ST_BLKSIZE(statbuf)/ST_NBLOCKSIZE : 0)
|
||||
# endif /* _CRAY */
|
||||
# endif /* not AIX PS/2 */
|
||||
# endif /* !hpux */
|
||||
#endif /* HAVE_STRUCT_STAT_ST_BLOCKS */
|
||||
|
||||
#ifndef ST_NBLOCKS
|
||||
# define ST_NBLOCKS(statbuf) ((statbuf).st_blocks)
|
||||
#endif
|
||||
|
||||
#ifndef ST_NBLOCKSIZE
|
||||
# define ST_NBLOCKSIZE 512
|
||||
#endif
|
||||
|
||||
/* Redirection and wildcarding when done by the utility itself.
|
||||
Generally a noop, but used in particular for native VMS. */
|
||||
#ifndef initialize_main
|
||||
# define initialize_main(ac, av)
|
||||
#endif
|
||||
|
||||
#include "stat-macros.h"
|
||||
|
||||
#include "timespec.h"
|
||||
|
||||
#ifndef RETSIGTYPE
|
||||
# define RETSIGTYPE void
|
||||
#endif
|
||||
|
||||
#ifdef __DJGPP__
|
||||
/* We need the declaration of setmode. */
|
||||
# include <io.h>
|
||||
/* We need the declaration of __djgpp_set_ctrl_c. */
|
||||
# include <sys/exceptn.h>
|
||||
#endif
|
||||
|
||||
#if HAVE_INTTYPES_H
|
||||
# include <inttypes.h>
|
||||
#endif
|
||||
#if HAVE_STDINT_H
|
||||
# include <stdint.h>
|
||||
#endif
|
||||
|
||||
#if ULONG_MAX < ULLONG_MAX
|
||||
# define LONGEST_MODIFIER "ll"
|
||||
#else
|
||||
# define LONGEST_MODIFIER "l"
|
||||
#endif
|
||||
#if PRI_MACROS_BROKEN
|
||||
# undef PRIdMAX
|
||||
# undef PRIoMAX
|
||||
# undef PRIuMAX
|
||||
# undef PRIxMAX
|
||||
#endif
|
||||
#ifndef PRIdMAX
|
||||
# define PRIdMAX LONGEST_MODIFIER "d"
|
||||
#endif
|
||||
#ifndef PRIoMAX
|
||||
# define PRIoMAX LONGEST_MODIFIER "o"
|
||||
#endif
|
||||
#ifndef PRIuMAX
|
||||
# define PRIuMAX LONGEST_MODIFIER "u"
|
||||
#endif
|
||||
#ifndef PRIxMAX
|
||||
# define PRIxMAX LONGEST_MODIFIER "x"
|
||||
#endif
|
||||
|
||||
#include <ctype.h>
|
||||
|
||||
/* Jim Meyering writes:
|
||||
|
||||
"... Some ctype macros are valid only for character codes that
|
||||
isascii says are ASCII (SGI's IRIX-4.0.5 is one such system --when
|
||||
using /bin/cc or gcc but without giving an ansi option). So, all
|
||||
ctype uses should be through macros like ISPRINT... If
|
||||
STDC_HEADERS is defined, then autoconf has verified that the ctype
|
||||
macros don't need to be guarded with references to isascii. ...
|
||||
Defining isascii to 1 should let any compiler worth its salt
|
||||
eliminate the && through constant folding."
|
||||
|
||||
Bruno Haible adds:
|
||||
|
||||
"... Furthermore, isupper(c) etc. have an undefined result if c is
|
||||
outside the range -1 <= c <= 255. One is tempted to write isupper(c)
|
||||
with c being of type `char', but this is wrong if c is an 8-bit
|
||||
character >= 128 which gets sign-extended to a negative value.
|
||||
The macro ISUPPER protects against this as well." */
|
||||
|
||||
#if STDC_HEADERS || (!defined (isascii) && !HAVE_ISASCII)
|
||||
# define IN_CTYPE_DOMAIN(c) 1
|
||||
#else
|
||||
# define IN_CTYPE_DOMAIN(c) isascii(c)
|
||||
#endif
|
||||
|
||||
#ifdef isblank
|
||||
# define ISBLANK(c) (IN_CTYPE_DOMAIN (c) && isblank (c))
|
||||
#else
|
||||
# define ISBLANK(c) ((c) == ' ' || (c) == '\t')
|
||||
#endif
|
||||
#ifdef isgraph
|
||||
# define ISGRAPH(c) (IN_CTYPE_DOMAIN (c) && isgraph (c))
|
||||
#else
|
||||
# define ISGRAPH(c) (IN_CTYPE_DOMAIN (c) && isprint (c) && !isspace (c))
|
||||
#endif
|
||||
|
||||
/* This is defined in <sys/euc.h> on at least Solaris2.6 systems. */
|
||||
#undef ISPRINT
|
||||
|
||||
#define ISPRINT(c) (IN_CTYPE_DOMAIN (c) && isprint (c))
|
||||
#define ISALNUM(c) (IN_CTYPE_DOMAIN (c) && isalnum (c))
|
||||
#define ISALPHA(c) (IN_CTYPE_DOMAIN (c) && isalpha (c))
|
||||
#define ISCNTRL(c) (IN_CTYPE_DOMAIN (c) && iscntrl (c))
|
||||
#define ISLOWER(c) (IN_CTYPE_DOMAIN (c) && islower (c))
|
||||
#define ISPUNCT(c) (IN_CTYPE_DOMAIN (c) && ispunct (c))
|
||||
#define ISSPACE(c) (IN_CTYPE_DOMAIN (c) && isspace (c))
|
||||
#define ISUPPER(c) (IN_CTYPE_DOMAIN (c) && isupper (c))
|
||||
#define ISXDIGIT(c) (IN_CTYPE_DOMAIN (c) && isxdigit (c))
|
||||
#define ISDIGIT_LOCALE(c) (IN_CTYPE_DOMAIN (c) && isdigit (c))
|
||||
|
||||
#if STDC_HEADERS
|
||||
# define TOLOWER(Ch) tolower (Ch)
|
||||
# define TOUPPER(Ch) toupper (Ch)
|
||||
#else
|
||||
# define TOLOWER(Ch) (ISUPPER (Ch) ? tolower (Ch) : (Ch))
|
||||
# define TOUPPER(Ch) (ISLOWER (Ch) ? toupper (Ch) : (Ch))
|
||||
#endif
|
||||
|
||||
/* ISDIGIT differs from ISDIGIT_LOCALE, as follows:
|
||||
- Its arg may be any int or unsigned int; it need not be an unsigned char.
|
||||
- It's guaranteed to evaluate its argument exactly once.
|
||||
- It's typically faster.
|
||||
POSIX says that only '0' through '9' are digits. Prefer ISDIGIT to
|
||||
ISDIGIT_LOCALE unless it's important to use the locale's definition
|
||||
of `digit' even when the host does not conform to POSIX. */
|
||||
#define ISDIGIT(c) ((unsigned int) (c) - '0' <= 9)
|
||||
|
||||
/* Convert a possibly-signed character to an unsigned character. This is
|
||||
a bit safer than casting to unsigned char, since it catches some type
|
||||
errors that the cast doesn't. */
|
||||
static inline unsigned char to_uchar (char ch) { return ch; }
|
||||
|
||||
/* Take care of NLS matters. */
|
||||
|
||||
#if HAVE_LOCALE_H
|
||||
# include <locale.h>
|
||||
#else
|
||||
# define setlocale(Category, Locale) /* empty */
|
||||
#endif
|
||||
|
||||
#include "gettext.h"
|
||||
#if ! ENABLE_NLS
|
||||
# undef textdomain
|
||||
# define textdomain(Domainname) /* empty */
|
||||
# undef bindtextdomain
|
||||
# define bindtextdomain(Domainname, Dirname) /* empty */
|
||||
#endif
|
||||
|
||||
#define _(msgid) gettext (msgid)
|
||||
#define N_(msgid) msgid
|
||||
|
||||
#ifndef HAVE_SETLOCALE
|
||||
# define HAVE_SETLOCALE 0
|
||||
#endif
|
||||
|
||||
#define STREQ(a, b) (strcmp ((a), (b)) == 0)
|
||||
|
||||
#if !HAVE_DECL_FREE
|
||||
void free ();
|
||||
#endif
|
||||
|
||||
#if !HAVE_DECL_MALLOC
|
||||
char *malloc ();
|
||||
#endif
|
||||
|
||||
#if !HAVE_DECL_MEMCHR
|
||||
char *memchr ();
|
||||
#endif
|
||||
|
||||
#if !HAVE_DECL_REALLOC
|
||||
char *realloc ();
|
||||
#endif
|
||||
|
||||
#if !HAVE_DECL_STPCPY
|
||||
# ifndef stpcpy
|
||||
char *stpcpy ();
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if !HAVE_DECL_STRNDUP
|
||||
char *strndup ();
|
||||
#endif
|
||||
|
||||
#if !HAVE_DECL_STRSTR
|
||||
char *strstr ();
|
||||
#endif
|
||||
|
||||
#if !HAVE_DECL_GETENV
|
||||
char *getenv ();
|
||||
#endif
|
||||
|
||||
#if !HAVE_DECL_LSEEK
|
||||
off_t lseek ();
|
||||
#endif
|
||||
|
||||
/* This is needed on some AIX systems. */
|
||||
#if !HAVE_DECL_STRTOUL
|
||||
unsigned long strtoul ();
|
||||
#endif
|
||||
|
||||
#if !HAVE_DECL_GETLOGIN
|
||||
char *getlogin ();
|
||||
#endif
|
||||
|
||||
#if !HAVE_DECL_TTYNAME
|
||||
char *ttyname ();
|
||||
#endif
|
||||
|
||||
#if !HAVE_DECL_GETEUID
|
||||
uid_t geteuid ();
|
||||
#endif
|
||||
|
||||
#if !HAVE_DECL_GETPWUID
|
||||
struct passwd *getpwuid ();
|
||||
#endif
|
||||
|
||||
#if !HAVE_DECL_GETGRGID
|
||||
struct group *getgrgid ();
|
||||
#endif
|
||||
|
||||
#if !HAVE_DECL_GETUID
|
||||
uid_t getuid ();
|
||||
#endif
|
||||
|
||||
#include "xalloc.h"
|
||||
|
||||
#if ! defined HAVE_MEMPCPY && ! defined mempcpy
|
||||
/* Be CAREFUL that there are no side effects in N. */
|
||||
# define mempcpy(D, S, N) ((void *) ((char *) memcpy (D, S, N) + (N)))
|
||||
#endif
|
||||
|
||||
/* Include automatically-generated macros for unlocked I/O. */
|
||||
#include "unlocked-io.h"
|
||||
|
||||
#define SAME_INODE(Stat_buf_1, Stat_buf_2) \
|
||||
((Stat_buf_1).st_ino == (Stat_buf_2).st_ino \
|
||||
&& (Stat_buf_1).st_dev == (Stat_buf_2).st_dev)
|
||||
|
||||
#define DOT_OR_DOTDOT(Basename) \
|
||||
(Basename[0] == '.' && (Basename[1] == '\0' \
|
||||
|| (Basename[1] == '.' && Basename[2] == '\0')))
|
||||
|
||||
/* A wrapper for readdir so that callers don't see entries for `.' or `..'. */
|
||||
static inline struct dirent const *
|
||||
readdir_ignoring_dot_and_dotdot (DIR *dirp)
|
||||
{
|
||||
while (1)
|
||||
{
|
||||
struct dirent const *dp = readdir (dirp);
|
||||
if (dp == NULL || ! DOT_OR_DOTDOT (dp->d_name))
|
||||
return dp;
|
||||
}
|
||||
}
|
||||
|
||||
#if SETVBUF_REVERSED
|
||||
# define SETVBUF(Stream, Buffer, Type, Size) \
|
||||
setvbuf (Stream, Type, Buffer, Size)
|
||||
#else
|
||||
# define SETVBUF(Stream, Buffer, Type, Size) \
|
||||
setvbuf (Stream, Buffer, Type, Size)
|
||||
#endif
|
||||
|
||||
/* Factor out some of the common --help and --version processing code. */
|
||||
|
||||
/* These enum values cannot possibly conflict with the option values
|
||||
ordinarily used by commands, including CHAR_MAX + 1, etc. Avoid
|
||||
CHAR_MIN - 1, as it may equal -1, the getopt end-of-options value. */
|
||||
enum
|
||||
{
|
||||
GETOPT_HELP_CHAR = (CHAR_MIN - 2),
|
||||
GETOPT_VERSION_CHAR = (CHAR_MIN - 3)
|
||||
};
|
||||
|
||||
#define GETOPT_HELP_OPTION_DECL \
|
||||
"help", no_argument, 0, GETOPT_HELP_CHAR
|
||||
#define GETOPT_VERSION_OPTION_DECL \
|
||||
"version", no_argument, 0, GETOPT_VERSION_CHAR
|
||||
|
||||
#define case_GETOPT_HELP_CHAR \
|
||||
case GETOPT_HELP_CHAR: \
|
||||
usage (EXIT_SUCCESS); \
|
||||
break;
|
||||
|
||||
#define HELP_OPTION_DESCRIPTION \
|
||||
_(" --help display this help and exit\n")
|
||||
#define VERSION_OPTION_DESCRIPTION \
|
||||
_(" --version output version information and exit\n")
|
||||
|
||||
#include "closeout.h"
|
||||
#include "version-etc.h"
|
||||
|
||||
#define case_GETOPT_VERSION_CHAR(Program_name, Authors) \
|
||||
case GETOPT_VERSION_CHAR: \
|
||||
version_etc (stdout, Program_name, GNU_PACKAGE, VERSION, Authors, \
|
||||
(char *) NULL); \
|
||||
exit (EXIT_SUCCESS); \
|
||||
break;
|
||||
|
||||
#ifndef MAX
|
||||
# define MAX(a, b) ((a) > (b) ? (a) : (b))
|
||||
#endif
|
||||
|
||||
#ifndef MIN
|
||||
# define MIN(a,b) (((a) < (b)) ? (a) : (b))
|
||||
#endif
|
||||
|
||||
/* The extra casts work around common compiler bugs. */
|
||||
#define TYPE_SIGNED(t) (! ((t) 0 < (t) -1))
|
||||
/* The outer cast is needed to work around a bug in Cray C 5.0.3.0.
|
||||
It is necessary at least when t == time_t. */
|
||||
#define TYPE_MINIMUM(t) ((t) (TYPE_SIGNED (t) \
|
||||
? ~ (t) 0 << (sizeof (t) * CHAR_BIT - 1) : (t) 0))
|
||||
#define TYPE_MAXIMUM(t) ((t) (~ (t) 0 - TYPE_MINIMUM (t)))
|
||||
|
||||
/* Upper bound on the string length of an integer converted to string.
|
||||
302 / 1000 is ceil (log10 (2.0)). Subtract 1 for the sign bit;
|
||||
add 1 for integer division truncation; add 1 more for a minus sign. */
|
||||
#define INT_STRLEN_BOUND(t) ((sizeof (t) * CHAR_BIT - 1) * 302 / 1000 + 2)
|
||||
|
||||
#ifndef CHAR_MIN
|
||||
# define CHAR_MIN TYPE_MINIMUM (char)
|
||||
#endif
|
||||
|
||||
#ifndef CHAR_MAX
|
||||
# define CHAR_MAX TYPE_MAXIMUM (char)
|
||||
#endif
|
||||
|
||||
#ifndef SCHAR_MIN
|
||||
# define SCHAR_MIN (-1 - SCHAR_MAX)
|
||||
#endif
|
||||
|
||||
#ifndef SCHAR_MAX
|
||||
# define SCHAR_MAX (CHAR_MAX == UCHAR_MAX ? CHAR_MAX / 2 : CHAR_MAX)
|
||||
#endif
|
||||
|
||||
#ifndef UCHAR_MAX
|
||||
# define UCHAR_MAX TYPE_MAXIMUM (unsigned char)
|
||||
#endif
|
||||
|
||||
#ifndef SHRT_MIN
|
||||
# define SHRT_MIN TYPE_MINIMUM (short int)
|
||||
#endif
|
||||
|
||||
#ifndef SHRT_MAX
|
||||
# define SHRT_MAX TYPE_MAXIMUM (short int)
|
||||
#endif
|
||||
|
||||
#ifndef INT_MAX
|
||||
# define INT_MAX TYPE_MAXIMUM (int)
|
||||
#endif
|
||||
|
||||
#ifndef INT_MIN
|
||||
# define INT_MIN TYPE_MINIMUM (int)
|
||||
#endif
|
||||
|
||||
#ifndef INTMAX_MAX
|
||||
# define INTMAX_MAX TYPE_MAXIMUM (intmax_t)
|
||||
#endif
|
||||
|
||||
#ifndef INTMAX_MIN
|
||||
# define INTMAX_MIN TYPE_MINIMUM (intmax_t)
|
||||
#endif
|
||||
|
||||
#ifndef UINT_MAX
|
||||
# define UINT_MAX TYPE_MAXIMUM (unsigned int)
|
||||
#endif
|
||||
|
||||
#ifndef LONG_MAX
|
||||
# define LONG_MAX TYPE_MAXIMUM (long int)
|
||||
#endif
|
||||
|
||||
#ifndef ULONG_MAX
|
||||
# define ULONG_MAX TYPE_MAXIMUM (unsigned long int)
|
||||
#endif
|
||||
|
||||
#ifndef SIZE_MAX
|
||||
# define SIZE_MAX TYPE_MAXIMUM (size_t)
|
||||
#endif
|
||||
|
||||
#ifndef SSIZE_MAX
|
||||
# define SSIZE_MAX TYPE_MAXIMUM (ssize_t)
|
||||
#endif
|
||||
|
||||
#ifndef UINTMAX_MAX
|
||||
# define UINTMAX_MAX TYPE_MAXIMUM (uintmax_t)
|
||||
#endif
|
||||
|
||||
#ifndef OFF_T_MIN
|
||||
# define OFF_T_MIN TYPE_MINIMUM (off_t)
|
||||
#endif
|
||||
|
||||
#ifndef OFF_T_MAX
|
||||
# define OFF_T_MAX TYPE_MAXIMUM (off_t)
|
||||
#endif
|
||||
|
||||
#ifndef UID_T_MAX
|
||||
# define UID_T_MAX TYPE_MAXIMUM (uid_t)
|
||||
#endif
|
||||
|
||||
#ifndef GID_T_MAX
|
||||
# define GID_T_MAX TYPE_MAXIMUM (gid_t)
|
||||
#endif
|
||||
|
||||
#ifndef PID_T_MAX
|
||||
# define PID_T_MAX TYPE_MAXIMUM (pid_t)
|
||||
#endif
|
||||
|
||||
/* Use this to suppress gcc's `...may be used before initialized' warnings. */
|
||||
#ifdef lint
|
||||
# define IF_LINT(Code) Code
|
||||
#else
|
||||
# define IF_LINT(Code) /* empty */
|
||||
#endif
|
||||
|
||||
#ifndef __attribute__
|
||||
# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 8) || __STRICT_ANSI__
|
||||
# define __attribute__(x)
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef ATTRIBUTE_NORETURN
|
||||
# define ATTRIBUTE_NORETURN __attribute__ ((__noreturn__))
|
||||
#endif
|
||||
|
||||
#ifndef ATTRIBUTE_UNUSED
|
||||
# define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
|
||||
#endif
|
||||
|
||||
#if defined strdupa
|
||||
# define ASSIGN_STRDUPA(DEST, S) \
|
||||
do { DEST = strdupa (S); } while (0)
|
||||
#else
|
||||
# define ASSIGN_STRDUPA(DEST, S) \
|
||||
do \
|
||||
{ \
|
||||
const char *s_ = (S); \
|
||||
size_t len_ = strlen (s_) + 1; \
|
||||
char *tmp_dest_ = alloca (len_); \
|
||||
DEST = memcpy (tmp_dest_, (s_), len_); \
|
||||
} \
|
||||
while (0)
|
||||
#endif
|
||||
|
||||
#ifndef EOVERFLOW
|
||||
# define EOVERFLOW EINVAL
|
||||
#endif
|
||||
|
||||
#if ! HAVE_FSEEKO && ! defined fseeko
|
||||
# define fseeko(s, o, w) ((o) == (long int) (o) \
|
||||
? fseek (s, o, w) \
|
||||
: (errno = EOVERFLOW, -1))
|
||||
#endif
|
||||
|
||||
/* Compute the greatest common divisor of U and V using Euclid's
|
||||
algorithm. U and V must be nonzero. */
|
||||
|
||||
static inline size_t
|
||||
gcd (size_t u, size_t v)
|
||||
{
|
||||
do
|
||||
{
|
||||
size_t t = u % v;
|
||||
u = v;
|
||||
v = t;
|
||||
}
|
||||
while (v);
|
||||
|
||||
return u;
|
||||
}
|
||||
|
||||
/* Compute the least common multiple of U and V. U and V must be
|
||||
nonzero. There is no overflow checking, so callers should not
|
||||
specify outlandish sizes. */
|
||||
|
||||
static inline size_t
|
||||
lcm (size_t u, size_t v)
|
||||
{
|
||||
return u * (v / gcd (u, v));
|
||||
}
|
||||
|
||||
/* Return PTR, aligned upward to the next multiple of ALIGNMENT.
|
||||
ALIGNMENT must be nonzero. The caller must arrange for ((char *)
|
||||
PTR) through ((char *) PTR + ALIGNMENT - 1) to be addressable
|
||||
locations. */
|
||||
|
||||
static inline void *
|
||||
ptr_align (void *ptr, size_t alignment)
|
||||
{
|
||||
char *p0 = ptr;
|
||||
char *p1 = p0 + alignment - 1;
|
||||
return p1 - (size_t) p1 % alignment;
|
||||
}
|
||||
|
|
@ -1,230 +0,0 @@
|
|||
#
|
||||
# OpenSSL/crypto/Makefile
|
||||
#
|
||||
|
||||
DIR= fips
|
||||
TOP= ..
|
||||
CC= cc
|
||||
INCLUDE= -I. -I$(TOP) -I../include
|
||||
# INCLUDES targets sudbirs!
|
||||
INCLUDES= -I.. -I../.. -I../../include
|
||||
CFLAG= -g
|
||||
MAKEDEPPROG= makedepend
|
||||
MAKEDEPEND= $(TOP)/util/domd $(TOP) -MD $(MAKEDEPPROG)
|
||||
MAKEFILE= Makefile
|
||||
RM= rm -f
|
||||
AR= ar r
|
||||
ARD= ar d
|
||||
TEST= fips_test_suite.c
|
||||
FIPS_TVDIR= testvectors
|
||||
FIPS_TVOK= $$HOME/fips/tv.ok
|
||||
|
||||
FIPSCANLOC= $(FIPSLIBDIR)fipscanister.o
|
||||
|
||||
RECURSIVE_MAKE= [ -n "$(FDIRS)" ] && for i in $(FDIRS) ; do \
|
||||
(cd $$i && echo "making $$target in $(DIR)/$$i..." && \
|
||||
$(MAKE) -e TOP=../.. DIR=$$i INCLUDES='${INCLUDES}' $$target ) || exit 1; \
|
||||
done;
|
||||
|
||||
PEX_LIBS=
|
||||
EX_LIBS=
|
||||
|
||||
CFLAGS= $(INCLUDE) $(CFLAG) -DHMAC_EXT=\"$${HMAC_EXT:-sha1}\"
|
||||
ASFLAGS= $(INCLUDE) $(ASFLAG)
|
||||
AFLAGS=$(ASFLAGS)
|
||||
|
||||
LIBS=
|
||||
|
||||
FDIRS=sha rand des aes dsa rsa dh hmac
|
||||
|
||||
GENERAL=Makefile README fips-lib.com install.com
|
||||
|
||||
LIB= $(TOP)/libcrypto.a
|
||||
SHARED_LIB= $(FIPSCANLIB)$(SHLIB_EXT)
|
||||
LIBSRC=fips.c
|
||||
LIBOBJ=fips.o
|
||||
|
||||
FIPS_OBJ_LISTS=sha/lib hmac/lib rand/lib des/lib aes/lib dsa/lib rsa/lib dh/lib
|
||||
|
||||
SRC= $(LIBSRC)
|
||||
|
||||
EXHEADER=fips.h
|
||||
HEADER=$(EXHEADER) fips_utl.h fips_locl.h
|
||||
EXE=fipsld
|
||||
|
||||
ALL= $(GENERAL) $(SRC) $(HEADER)
|
||||
|
||||
top:
|
||||
@(cd ..; $(MAKE) DIRS=$(DIR) all)
|
||||
|
||||
testapps:
|
||||
@if [ -z "$(THIS)" ]; then $(MAKE) -f $(TOP)/Makefile reflect THIS=$@; fi
|
||||
|
||||
all:
|
||||
@if [ -z "$(FIPSLIBDIR)" ]; then \
|
||||
$(MAKE) -e subdirs lib fips_premain_dso$(EXE_EXT); \
|
||||
else \
|
||||
$(MAKE) -e lib fips_premain_dso$(EXE_EXT) fips_standalone_sha1$(EXE_EXT); \
|
||||
fi
|
||||
|
||||
# Idea behind fipscanister.o is to "seize" the sequestered code between
|
||||
# known symbols for fingerprinting purposes, which would be commonly
|
||||
# done with ld -r start.o ... end.o. The latter however presents a minor
|
||||
# challenge on multi-ABI platforms. As just implied, we'd rather use ld,
|
||||
# but the trouble is that we don't generally know how ABI-selection
|
||||
# compiler flag is translated to corresponding linker flag. All compiler
|
||||
# drivers seem to recognize -r flag and pass it down to linker, but some
|
||||
# of them, including gcc, erroneously add -lc, as well as run-time
|
||||
# components, such as crt1.o and alike. Fortunately among those vendor
|
||||
# compilers which were observed to misinterpret -r flag multi-ABI ones
|
||||
# are equipped with smart linkers, which don't require any ABI-selection
|
||||
# flag and simply assume that all objects are of the same type as first
|
||||
# one in command line. So the idea is to identify gcc and deficient
|
||||
# vendor compiler drivers...
|
||||
|
||||
fipscanister.o: fips_start.o $(LIBOBJ) $(FIPS_OBJ_LISTS) fips_end.o
|
||||
FIPS_ASM=""; \
|
||||
list="$(BN_ASM)"; for i in $$list; do FIPS_ASM="$$FIPS_ASM ../crypto/bn/$$i" ; done; \
|
||||
list="$(AES_ASM_OBJ)"; for i in $$list; do FIPS_ASM="$$FIPS_ASM ../crypto/aes/$$i" ; done; \
|
||||
list="$(DES_ENC)"; for i in $$list; do FIPS_ASM="$$FIPS_ASM ../crypto/des/$$i" ; done; \
|
||||
list="$(SHA1_ASM_OBJ)"; for i in $$list; do FIPS_ASM="$$FIPS_ASM ../crypto/sha/$$i" ; done; \
|
||||
if [ -n "$(CPUID_OBJ)" ]; then \
|
||||
CPUID=../crypto/$(CPUID_OBJ) ; \
|
||||
else \
|
||||
CPUID="" ; \
|
||||
fi ; \
|
||||
objs="fips_start.o $(LIBOBJ) $(FIPS_EX_OBJ) $$CPUID $$FIPS_ASM"; \
|
||||
for i in $(FIPS_OBJ_LISTS); do \
|
||||
dir=`dirname $$i`; script="s|^|$$dir/|;s| | $$dir/|g"; \
|
||||
objs="$$objs `sed "$$script" $$i`"; \
|
||||
done; \
|
||||
objs="$$objs fips_end.o" ; \
|
||||
os="`(uname -s) 2>/dev/null`"; cflags="$(CFLAGS)"; \
|
||||
[ "$$os" = "AIX" ] && cflags="$$cflags -Wl,-bnoobjreorder"; \
|
||||
if [ -n "${FIPS_SITE_LD}" ]; then \
|
||||
set -x; ${FIPS_SITE_LD} -r -o $@ $$objs; \
|
||||
elif $(CC) -dumpversion >/dev/null 2>&1; then \
|
||||
set -x; $(CC) $$cflags -r -nostdlib -o $@ $$objs ; \
|
||||
else case "$$os" in \
|
||||
HP-UX|OSF1|SunOS) set -x; /usr/ccs/bin/ld -r -o $@ $$objs ;; \
|
||||
*) set -x; $(CC) $$cflags -r -o $@ $$objs ;; \
|
||||
esac fi
|
||||
./fips_standalone_sha1$(EXE_EXT) fipscanister.o > fipscanister.o.sha1
|
||||
|
||||
# If another exception is immediately required, assign approprite
|
||||
# site-specific ld command to FIPS_SITE_LD environment variable.
|
||||
|
||||
fips_start.o: fips_canister.c
|
||||
$(CC) $(CFLAGS) -DFIPS_START -c -o $@ fips_canister.c
|
||||
fips_end.o: fips_canister.c
|
||||
$(CC) $(CFLAGS) -DFIPS_END -c -o $@ fips_canister.c
|
||||
fips_premain_dso$(EXE_EXT): fips_premain.c
|
||||
$(CC) $(CFLAGS) -DFINGERPRINT_PREMAIN_DSO_LOAD -o $@ fips_premain.c \
|
||||
$(FIPSLIBDIR)fipscanister.o ../libcrypto.a $(EX_LIBS)
|
||||
# this is executed only when linking with external fipscanister.o
|
||||
fips_standalone_sha1$(EXE_EXT): sha/fips_standalone_sha1.c
|
||||
if [ -z "$(HOSTCC)" ] ; then \
|
||||
$(CC) $(CFLAGS) -DFIPSCANISTER_O -o $@ sha/fips_standalone_sha1.c $(FIPSLIBDIR)fipscanister.o $(EX_LIBS) ; \
|
||||
else \
|
||||
$(HOSTCC) $(HOSTCFLAGS) -o $ $@ -I../include -I../crypto sha/fips_standalone_sha1.c ../crypto/sha/sha1dgst.c ; \
|
||||
fi
|
||||
|
||||
subdirs:
|
||||
@target=all; $(RECURSIVE_MAKE)
|
||||
|
||||
files:
|
||||
$(PERL) $(TOP)/util/files.pl Makefile >> $(TOP)/MINFO
|
||||
@target=files; $(RECURSIVE_MAKE)
|
||||
|
||||
links:
|
||||
@$(PERL) $(TOP)/util/mklink.pl ../include/openssl $(EXHEADER)
|
||||
@$(PERL) $(TOP)/util/mklink.pl ../test $(TEST)
|
||||
@target=links; $(RECURSIVE_MAKE)
|
||||
|
||||
# lib: and $(LIB): are splitted to avoid end-less loop
|
||||
lib: $(LIB)
|
||||
if [ "$(FIPSCANISTERINTERNAL)" = "n" -a -n "$(FIPSCANLOC)" ]; then $(AR) ../$(FIPSCANLIB).a $(FIPSCANLOC); fi
|
||||
@touch lib
|
||||
|
||||
$(LIB): $(FIPSLIBDIR)fipscanister.o
|
||||
$(AR) $(LIB) $(FIPSLIBDIR)fipscanister.o
|
||||
$(RANLIB) $(LIB) || echo Never mind.
|
||||
|
||||
$(FIPSCANLIB): $(FIPSCANLOC)
|
||||
$(AR) ../$(FIPSCANLIB).a $(FIPSCANLOC)
|
||||
if [ "$(FIPSCANLIB)" = "libfips" ]; then \
|
||||
$(AR) $(LIB) $(FIPSCANLOC) ; \
|
||||
$(RANLIB) $(LIB) || echo Never Mind. ; \
|
||||
fi
|
||||
$(RANLIB) ../$(FIPSCANLIB).a || echo Never mind.
|
||||
@touch lib
|
||||
|
||||
shared: lib subdirs fips_premain_dso$(EXE_EXT)
|
||||
|
||||
libs:
|
||||
@target=lib; $(RECURSIVE_MAKE)
|
||||
|
||||
fips_test: top
|
||||
@target=fips_test; $(RECURSIVE_MAKE)
|
||||
|
||||
fips_test_diff:
|
||||
@if diff -b -B -I '^\#' -cr -X fips-nodiff.txt $(FIPS_TVDIR) $(FIPS_TVOK) ; then \
|
||||
echo "FIPS diff OK" ; \
|
||||
else \
|
||||
echo "***FIPS DIFF ERROR***" ; exit 1 ; \
|
||||
fi
|
||||
|
||||
|
||||
install:
|
||||
@[ -n "$(INSTALLTOP)" ] # should be set by top Makefile...
|
||||
@headerlist="$(EXHEADER)"; for i in $$headerlist ;\
|
||||
do \
|
||||
(cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
|
||||
chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
|
||||
done;
|
||||
@target=install; $(RECURSIVE_MAKE)
|
||||
for i in $(EXE) ; \
|
||||
do \
|
||||
echo "installing $$i"; \
|
||||
cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/bin/$$i.new; \
|
||||
chmod 755 $(INSTALL_PREFIX)$(INSTALLTOP)/bin/$$i.new; \
|
||||
mv -f $(INSTALL_PREFIX)$(INSTALLTOP)/bin/$$i.new $(INSTALL_PREFIX)$(INSTALLTOP)/bin/$$i; \
|
||||
done
|
||||
cp -p -f $(FIPSLIBDIR)fipscanister.o $(FIPSLIBDIR)fipscanister.o.sha1 \
|
||||
$(FIPSLIBDIR)fips_premain.c $(FIPSLIBDIR)fips_premain.c.sha1 \
|
||||
$(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/; \
|
||||
chmod 0444 $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/fips*
|
||||
|
||||
lint:
|
||||
@target=lint; $(RECURSIVE_MAKE)
|
||||
|
||||
depend:
|
||||
@[ -z "$(THIS)" ] || $(MAKEDEPEND) -- $(CFLAG) $(INCLUDE) $(DEPFLAG) -- $(PROGS) $(LIBSRC)
|
||||
@[ -z "$(THIS)" ] || (set -e; target=depend; $(RECURSIVE_MAKE) )
|
||||
@if [ -z "$(THIS)" ]; then $(MAKE) -f $(TOP)/Makefile reflect THIS=$@; fi
|
||||
|
||||
clean:
|
||||
rm -f fipscanister.o.sha1 fips_premain_dso$(EXE_EXT) fips_standalone_sha1$(EXE_EXT) \
|
||||
*.s *.o */*.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
|
||||
@target=clean; $(RECURSIVE_MAKE)
|
||||
|
||||
dclean:
|
||||
$(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
|
||||
mv -f Makefile.new $(MAKEFILE)
|
||||
@target=dclean; $(RECURSIVE_MAKE)
|
||||
|
||||
# DO NOT DELETE THIS LINE -- make depend depends on it.
|
||||
|
||||
fips.o: ../include/openssl/asn1.h ../include/openssl/bio.h
|
||||
fips.o: ../include/openssl/crypto.h ../include/openssl/des.h
|
||||
fips.o: ../include/openssl/des_old.h ../include/openssl/e_os2.h
|
||||
fips.o: ../include/openssl/err.h ../include/openssl/evp.h
|
||||
fips.o: ../include/openssl/fips.h ../include/openssl/fips_rand.h
|
||||
fips.o: ../include/openssl/hmac.h ../include/openssl/lhash.h
|
||||
fips.o: ../include/openssl/obj_mac.h ../include/openssl/objects.h
|
||||
fips.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
|
||||
fips.o: ../include/openssl/ossl_typ.h ../include/openssl/rand.h
|
||||
fips.o: ../include/openssl/rsa.h ../include/openssl/safestack.h
|
||||
fips.o: ../include/openssl/stack.h ../include/openssl/symhacks.h
|
||||
fips.o: ../include/openssl/ui.h ../include/openssl/ui_compat.h fips.c
|
||||
fips.o: fips_locl.h
|
||||
|
|
@ -1,111 +0,0 @@
|
|||
#
|
||||
# OpenSSL/fips/aes/Makefile
|
||||
#
|
||||
|
||||
DIR= aes
|
||||
TOP= ../..
|
||||
CC= cc
|
||||
INCLUDES=
|
||||
CFLAG=-g
|
||||
INSTALL_PREFIX=
|
||||
OPENSSLDIR= /usr/local/ssl
|
||||
INSTALLTOP=/usr/local/ssl
|
||||
MAKEDEPPROG= makedepend
|
||||
MAKEDEPEND= $(TOP)/util/domd $(TOP) -MD $(MAKEDEPPROG)
|
||||
MAKEFILE= Makefile
|
||||
AR= ar r
|
||||
|
||||
ASFLAGS= $(INCLUDES) $(ASFLAG)
|
||||
AFLAGS= $(ASFLAGS)
|
||||
|
||||
CFLAGS= $(INCLUDES) $(CFLAG)
|
||||
|
||||
GENERAL=Makefile
|
||||
TEST=fips_aesavs.c
|
||||
APPS=
|
||||
|
||||
LIB=$(TOP)/libcrypto.a
|
||||
LIBSRC=fips_aes_selftest.c
|
||||
LIBOBJ=fips_aes_selftest.o
|
||||
|
||||
SRC= $(LIBSRC)
|
||||
|
||||
EXHEADER=
|
||||
HEADER=
|
||||
|
||||
ALL= $(GENERAL) $(SRC) $(HEADER)
|
||||
|
||||
top:
|
||||
(cd $(TOP); $(MAKE) DIRS=fips FDIRS=$(DIR) sub_all)
|
||||
|
||||
all: lib
|
||||
|
||||
lib: $(LIBOBJ)
|
||||
@echo $(LIBOBJ) > lib
|
||||
|
||||
files:
|
||||
$(PERL) $(TOP)/util/files.pl Makefile >> $(TOP)/MINFO
|
||||
|
||||
links:
|
||||
@$(PERL) $(TOP)/util/mklink.pl $(TOP)/include/openssl $(EXHEADER)
|
||||
@$(PERL) $(TOP)/util/mklink.pl $(TOP)/test $(TEST)
|
||||
@$(PERL) $(TOP)/util/mklink.pl $(TOP)/apps $(APPS)
|
||||
|
||||
install:
|
||||
@headerlist="$(EXHEADER)"; for i in $$headerlist; \
|
||||
do \
|
||||
(cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
|
||||
chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
|
||||
done
|
||||
|
||||
tags:
|
||||
ctags $(SRC)
|
||||
|
||||
tests:
|
||||
|
||||
fips_test:
|
||||
-find ../testvectors/aes/req -name '*.req' > testlist
|
||||
-rm -rf ../testvectors/aes/rsp
|
||||
mkdir ../testvectors/aes/rsp
|
||||
if [ -s testlist ]; then $(TOP)/util/shlib_wrap.sh $(TOP)/test/fips_aesavs -d testlist; fi
|
||||
|
||||
lint:
|
||||
lint -DLINT $(INCLUDES) $(SRC)>fluff
|
||||
|
||||
depend:
|
||||
$(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) \
|
||||
$(SRC) $(TEST)
|
||||
|
||||
dclean:
|
||||
$(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
|
||||
mv -f Makefile.new $(MAKEFILE)
|
||||
|
||||
clean:
|
||||
rm -f *.o asm/*.o *.obj lib tags core .pure .nfs* *.old *.bak fluff testlist
|
||||
# DO NOT DELETE THIS LINE -- make depend depends on it.
|
||||
|
||||
fips_aes_selftest.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
|
||||
fips_aes_selftest.o: ../../include/openssl/crypto.h
|
||||
fips_aes_selftest.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
|
||||
fips_aes_selftest.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
|
||||
fips_aes_selftest.o: ../../include/openssl/lhash.h
|
||||
fips_aes_selftest.o: ../../include/openssl/obj_mac.h
|
||||
fips_aes_selftest.o: ../../include/openssl/objects.h
|
||||
fips_aes_selftest.o: ../../include/openssl/opensslconf.h
|
||||
fips_aes_selftest.o: ../../include/openssl/opensslv.h
|
||||
fips_aes_selftest.o: ../../include/openssl/ossl_typ.h
|
||||
fips_aes_selftest.o: ../../include/openssl/safestack.h
|
||||
fips_aes_selftest.o: ../../include/openssl/stack.h
|
||||
fips_aes_selftest.o: ../../include/openssl/symhacks.h fips_aes_selftest.c
|
||||
fips_aesavs.o: ../../e_os.h ../../include/openssl/aes.h
|
||||
fips_aesavs.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
|
||||
fips_aesavs.o: ../../include/openssl/bn.h ../../include/openssl/crypto.h
|
||||
fips_aesavs.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
|
||||
fips_aesavs.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
|
||||
fips_aesavs.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
|
||||
fips_aesavs.o: ../../include/openssl/objects.h
|
||||
fips_aesavs.o: ../../include/openssl/opensslconf.h
|
||||
fips_aesavs.o: ../../include/openssl/opensslv.h
|
||||
fips_aesavs.o: ../../include/openssl/ossl_typ.h
|
||||
fips_aesavs.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
|
||||
fips_aesavs.o: ../../include/openssl/symhacks.h ../fips_utl.h fips_aesavs.c
|
||||
|
|
@ -1,101 +0,0 @@
|
|||
/* ====================================================================
|
||||
* Copyright (c) 2003 The OpenSSL Project. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* 3. All advertising materials mentioning features or use of this
|
||||
* software must display the following acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
|
||||
*
|
||||
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission. For written permission, please contact
|
||||
* openssl-core@openssl.org.
|
||||
*
|
||||
* 5. Products derived from this software may not be called "OpenSSL"
|
||||
* nor may "OpenSSL" appear in their names without prior written
|
||||
* permission of the OpenSSL Project.
|
||||
*
|
||||
* 6. Redistributions of any form whatsoever must retain the following
|
||||
* acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit (http://www.openssl.org/)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
|
||||
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
|
||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/fips.h>
|
||||
#include <openssl/evp.h>
|
||||
|
||||
#ifdef OPENSSL_FIPS
|
||||
static struct
|
||||
{
|
||||
unsigned char key[16];
|
||||
unsigned char plaintext[16];
|
||||
unsigned char ciphertext[16];
|
||||
} tests[]=
|
||||
{
|
||||
{
|
||||
{ 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,
|
||||
0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F },
|
||||
{ 0x00,0x11,0x22,0x33,0x44,0x55,0x66,0x77,
|
||||
0x88,0x99,0xAA,0xBB,0xCC,0xDD,0xEE,0xFF },
|
||||
{ 0x69,0xC4,0xE0,0xD8,0x6A,0x7B,0x04,0x30,
|
||||
0xD8,0xCD,0xB7,0x80,0x70,0xB4,0xC5,0x5A },
|
||||
},
|
||||
};
|
||||
|
||||
void FIPS_corrupt_aes()
|
||||
{
|
||||
tests[0].key[0]++;
|
||||
}
|
||||
|
||||
int FIPS_selftest_aes()
|
||||
{
|
||||
int n;
|
||||
int ret = 0;
|
||||
EVP_CIPHER_CTX ctx;
|
||||
EVP_CIPHER_CTX_init(&ctx);
|
||||
|
||||
for(n=0 ; n < 1 ; ++n)
|
||||
{
|
||||
if (fips_cipher_test(&ctx, EVP_aes_128_ecb(),
|
||||
tests[n].key, NULL,
|
||||
tests[n].plaintext,
|
||||
tests[n].ciphertext,
|
||||
16) <= 0)
|
||||
goto err;
|
||||
}
|
||||
ret = 1;
|
||||
err:
|
||||
EVP_CIPHER_CTX_cleanup(&ctx);
|
||||
if (ret == 0)
|
||||
FIPSerr(FIPS_F_FIPS_SELFTEST_AES,FIPS_R_SELFTEST_FAILED);
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
|
@ -1,939 +0,0 @@
|
|||
/* ====================================================================
|
||||
* Copyright (c) 2004 The OpenSSL Project. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* 3. All advertising materials mentioning features or use of this
|
||||
* software must display the following acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
|
||||
*
|
||||
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission. For written permission, please contact
|
||||
* openssl-core@openssl.org.
|
||||
*
|
||||
* 5. Products derived from this software may not be called "OpenSSL"
|
||||
* nor may "OpenSSL" appear in their names without prior written
|
||||
* permission of the OpenSSL Project.
|
||||
*
|
||||
* 6. Redistributions of any form whatsoever must retain the following
|
||||
* acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit (http://www.openssl.org/)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
|
||||
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
|
||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
/*---------------------------------------------
|
||||
NIST AES Algorithm Validation Suite
|
||||
Test Program
|
||||
|
||||
Donated to OpenSSL by:
|
||||
V-ONE Corporation
|
||||
20250 Century Blvd, Suite 300
|
||||
Germantown, MD 20874
|
||||
U.S.A.
|
||||
----------------------------------------------*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <assert.h>
|
||||
#include <ctype.h>
|
||||
#include <openssl/aes.h>
|
||||
#include <openssl/evp.h>
|
||||
#include <openssl/bn.h>
|
||||
|
||||
#include <openssl/err.h>
|
||||
#include "e_os.h"
|
||||
|
||||
#ifndef OPENSSL_FIPS
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
printf("No FIPS AES support\n");
|
||||
return(0);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
#include <openssl/fips.h>
|
||||
#include "fips_utl.h"
|
||||
|
||||
#define AES_BLOCK_SIZE 16
|
||||
|
||||
#define VERBOSE 0
|
||||
|
||||
/*-----------------------------------------------*/
|
||||
|
||||
static int AESTest(EVP_CIPHER_CTX *ctx,
|
||||
char *amode, int akeysz, unsigned char *aKey,
|
||||
unsigned char *iVec,
|
||||
int dir, /* 0 = decrypt, 1 = encrypt */
|
||||
unsigned char *plaintext, unsigned char *ciphertext, int len)
|
||||
{
|
||||
const EVP_CIPHER *cipher = NULL;
|
||||
|
||||
if (strcasecmp(amode, "CBC") == 0)
|
||||
{
|
||||
switch (akeysz)
|
||||
{
|
||||
case 128:
|
||||
cipher = EVP_aes_128_cbc();
|
||||
break;
|
||||
|
||||
case 192:
|
||||
cipher = EVP_aes_192_cbc();
|
||||
break;
|
||||
|
||||
case 256:
|
||||
cipher = EVP_aes_256_cbc();
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
else if (strcasecmp(amode, "ECB") == 0)
|
||||
{
|
||||
switch (akeysz)
|
||||
{
|
||||
case 128:
|
||||
cipher = EVP_aes_128_ecb();
|
||||
break;
|
||||
|
||||
case 192:
|
||||
cipher = EVP_aes_192_ecb();
|
||||
break;
|
||||
|
||||
case 256:
|
||||
cipher = EVP_aes_256_ecb();
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (strcasecmp(amode, "CFB128") == 0)
|
||||
{
|
||||
switch (akeysz)
|
||||
{
|
||||
case 128:
|
||||
cipher = EVP_aes_128_cfb128();
|
||||
break;
|
||||
|
||||
case 192:
|
||||
cipher = EVP_aes_192_cfb128();
|
||||
break;
|
||||
|
||||
case 256:
|
||||
cipher = EVP_aes_256_cfb128();
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
else if (strncasecmp(amode, "OFB", 3) == 0)
|
||||
{
|
||||
switch (akeysz)
|
||||
{
|
||||
case 128:
|
||||
cipher = EVP_aes_128_ofb();
|
||||
break;
|
||||
|
||||
case 192:
|
||||
cipher = EVP_aes_192_ofb();
|
||||
break;
|
||||
|
||||
case 256:
|
||||
cipher = EVP_aes_256_ofb();
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if(!strcasecmp(amode,"CFB1"))
|
||||
{
|
||||
switch (akeysz)
|
||||
{
|
||||
case 128:
|
||||
cipher = EVP_aes_128_cfb1();
|
||||
break;
|
||||
|
||||
case 192:
|
||||
cipher = EVP_aes_192_cfb1();
|
||||
break;
|
||||
|
||||
case 256:
|
||||
cipher = EVP_aes_256_cfb1();
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if(!strcasecmp(amode,"CFB8"))
|
||||
{
|
||||
switch (akeysz)
|
||||
{
|
||||
case 128:
|
||||
cipher = EVP_aes_128_cfb8();
|
||||
break;
|
||||
|
||||
case 192:
|
||||
cipher = EVP_aes_192_cfb8();
|
||||
break;
|
||||
|
||||
case 256:
|
||||
cipher = EVP_aes_256_cfb8();
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Unknown mode: %s\n", amode);
|
||||
return 0;
|
||||
}
|
||||
if (!cipher)
|
||||
{
|
||||
printf("Invalid key size: %d\n", akeysz);
|
||||
return 0;
|
||||
}
|
||||
if (EVP_CipherInit_ex(ctx, cipher, NULL, aKey, iVec, dir) <= 0)
|
||||
return 0;
|
||||
if(!strcasecmp(amode,"CFB1"))
|
||||
M_EVP_CIPHER_CTX_set_flags(ctx, EVP_CIPH_FLAG_LENGTH_BITS);
|
||||
if (dir)
|
||||
EVP_Cipher(ctx, ciphertext, plaintext, len);
|
||||
else
|
||||
EVP_Cipher(ctx, plaintext, ciphertext, len);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------*/
|
||||
char *t_tag[2] = {"PLAINTEXT", "CIPHERTEXT"};
|
||||
char *t_mode[6] = {"CBC","ECB","OFB","CFB1","CFB8","CFB128"};
|
||||
enum Mode {CBC, ECB, OFB, CFB1, CFB8, CFB128};
|
||||
enum XCrypt {XDECRYPT, XENCRYPT};
|
||||
|
||||
/*=============================*/
|
||||
/* Monte Carlo Tests */
|
||||
/*-----------------------------*/
|
||||
|
||||
/*#define gb(a,b) (((a)[(b)/8] >> ((b)%8))&1)*/
|
||||
/*#define sb(a,b,v) ((a)[(b)/8]=((a)[(b)/8]&~(1 << ((b)%8)))|(!!(v) << ((b)%8)))*/
|
||||
|
||||
#define gb(a,b) (((a)[(b)/8] >> (7-(b)%8))&1)
|
||||
#define sb(a,b,v) ((a)[(b)/8]=((a)[(b)/8]&~(1 << (7-(b)%8)))|(!!(v) << (7-(b)%8)))
|
||||
|
||||
static int do_mct(char *amode,
|
||||
int akeysz, unsigned char *aKey,unsigned char *iVec,
|
||||
int dir, unsigned char *text, int len,
|
||||
FILE *rfp)
|
||||
{
|
||||
int ret = 0;
|
||||
unsigned char key[101][32];
|
||||
unsigned char iv[101][AES_BLOCK_SIZE];
|
||||
unsigned char ptext[1001][32];
|
||||
unsigned char ctext[1001][32];
|
||||
unsigned char ciphertext[64+4];
|
||||
int i, j, n, n1, n2;
|
||||
int imode = 0, nkeysz = akeysz/8;
|
||||
EVP_CIPHER_CTX ctx;
|
||||
EVP_CIPHER_CTX_init(&ctx);
|
||||
|
||||
if (len > 32)
|
||||
{
|
||||
printf("\n>>>> Length exceeds 32 for %s %d <<<<\n\n",
|
||||
amode, akeysz);
|
||||
return -1;
|
||||
}
|
||||
for (imode = 0; imode < 6; ++imode)
|
||||
if (strcmp(amode, t_mode[imode]) == 0)
|
||||
break;
|
||||
if (imode == 6)
|
||||
{
|
||||
printf("Unrecognized mode: %s\n", amode);
|
||||
return -1;
|
||||
}
|
||||
|
||||
memcpy(key[0], aKey, nkeysz);
|
||||
if (iVec)
|
||||
memcpy(iv[0], iVec, AES_BLOCK_SIZE);
|
||||
if (dir == XENCRYPT)
|
||||
memcpy(ptext[0], text, len);
|
||||
else
|
||||
memcpy(ctext[0], text, len);
|
||||
for (i = 0; i < 100; ++i)
|
||||
{
|
||||
/* printf("Iteration %d\n", i); */
|
||||
if (i > 0)
|
||||
{
|
||||
fprintf(rfp,"COUNT = %d\n",i);
|
||||
OutputValue("KEY",key[i],nkeysz,rfp,0);
|
||||
if (imode != ECB) /* ECB */
|
||||
OutputValue("IV",iv[i],AES_BLOCK_SIZE,rfp,0);
|
||||
/* Output Ciphertext | Plaintext */
|
||||
OutputValue(t_tag[dir^1],dir ? ptext[0] : ctext[0],len,rfp,
|
||||
imode == CFB1);
|
||||
}
|
||||
for (j = 0; j < 1000; ++j)
|
||||
{
|
||||
switch (imode)
|
||||
{
|
||||
case ECB:
|
||||
if (j == 0)
|
||||
{ /* set up encryption */
|
||||
ret = AESTest(&ctx, amode, akeysz, key[i], NULL,
|
||||
dir, /* 0 = decrypt, 1 = encrypt */
|
||||
ptext[j], ctext[j], len);
|
||||
if (dir == XENCRYPT)
|
||||
memcpy(ptext[j+1], ctext[j], len);
|
||||
else
|
||||
memcpy(ctext[j+1], ptext[j], len);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (dir == XENCRYPT)
|
||||
{
|
||||
EVP_Cipher(&ctx, ctext[j], ptext[j], len);
|
||||
memcpy(ptext[j+1], ctext[j], len);
|
||||
}
|
||||
else
|
||||
{
|
||||
EVP_Cipher(&ctx, ptext[j], ctext[j], len);
|
||||
memcpy(ctext[j+1], ptext[j], len);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case CBC:
|
||||
case OFB:
|
||||
case CFB128:
|
||||
if (j == 0)
|
||||
{
|
||||
ret = AESTest(&ctx, amode, akeysz, key[i], iv[i],
|
||||
dir, /* 0 = decrypt, 1 = encrypt */
|
||||
ptext[j], ctext[j], len);
|
||||
if (dir == XENCRYPT)
|
||||
memcpy(ptext[j+1], iv[i], len);
|
||||
else
|
||||
memcpy(ctext[j+1], iv[i], len);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (dir == XENCRYPT)
|
||||
{
|
||||
EVP_Cipher(&ctx, ctext[j], ptext[j], len);
|
||||
memcpy(ptext[j+1], ctext[j-1], len);
|
||||
}
|
||||
else
|
||||
{
|
||||
EVP_Cipher(&ctx, ptext[j], ctext[j], len);
|
||||
memcpy(ctext[j+1], ptext[j-1], len);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case CFB8:
|
||||
if (j == 0)
|
||||
{
|
||||
ret = AESTest(&ctx, amode, akeysz, key[i], iv[i],
|
||||
dir, /* 0 = decrypt, 1 = encrypt */
|
||||
ptext[j], ctext[j], len);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (dir == XENCRYPT)
|
||||
EVP_Cipher(&ctx, ctext[j], ptext[j], len);
|
||||
else
|
||||
EVP_Cipher(&ctx, ptext[j], ctext[j], len);
|
||||
}
|
||||
if (dir == XENCRYPT)
|
||||
{
|
||||
if (j < 16)
|
||||
memcpy(ptext[j+1], &iv[i][j], len);
|
||||
else
|
||||
memcpy(ptext[j+1], ctext[j-16], len);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (j < 16)
|
||||
memcpy(ctext[j+1], &iv[i][j], len);
|
||||
else
|
||||
memcpy(ctext[j+1], ptext[j-16], len);
|
||||
}
|
||||
break;
|
||||
|
||||
case CFB1:
|
||||
if(j == 0)
|
||||
{
|
||||
#if 0
|
||||
/* compensate for wrong endianness of input file */
|
||||
if(i == 0)
|
||||
ptext[0][0]<<=7;
|
||||
#endif
|
||||
ret = AESTest(&ctx,amode,akeysz,key[i],iv[i],dir,
|
||||
ptext[j], ctext[j], len);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (dir == XENCRYPT)
|
||||
EVP_Cipher(&ctx, ctext[j], ptext[j], len);
|
||||
else
|
||||
EVP_Cipher(&ctx, ptext[j], ctext[j], len);
|
||||
|
||||
}
|
||||
if(dir == XENCRYPT)
|
||||
{
|
||||
if(j < 128)
|
||||
sb(ptext[j+1],0,gb(iv[i],j));
|
||||
else
|
||||
sb(ptext[j+1],0,gb(ctext[j-128],0));
|
||||
}
|
||||
else
|
||||
{
|
||||
if(j < 128)
|
||||
sb(ctext[j+1],0,gb(iv[i],j));
|
||||
else
|
||||
sb(ctext[j+1],0,gb(ptext[j-128],0));
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
--j; /* reset to last of range */
|
||||
/* Output Ciphertext | Plaintext */
|
||||
OutputValue(t_tag[dir],dir ? ctext[j] : ptext[j],len,rfp,
|
||||
imode == CFB1);
|
||||
fprintf(rfp, "\n"); /* add separator */
|
||||
|
||||
/* Compute next KEY */
|
||||
if (dir == XENCRYPT)
|
||||
{
|
||||
if (imode == CFB8)
|
||||
{ /* ct = CT[j-15] || CT[j-14] || ... || CT[j] */
|
||||
for (n1 = 0, n2 = nkeysz-1; n1 < nkeysz; ++n1, --n2)
|
||||
ciphertext[n1] = ctext[j-n2][0];
|
||||
}
|
||||
else if(imode == CFB1)
|
||||
{
|
||||
for(n1=0,n2=akeysz-1 ; n1 < akeysz ; ++n1,--n2)
|
||||
sb(ciphertext,n1,gb(ctext[j-n2],0));
|
||||
}
|
||||
else
|
||||
switch (akeysz)
|
||||
{
|
||||
case 128:
|
||||
memcpy(ciphertext, ctext[j], 16);
|
||||
break;
|
||||
case 192:
|
||||
memcpy(ciphertext, ctext[j-1]+8, 8);
|
||||
memcpy(ciphertext+8, ctext[j], 16);
|
||||
break;
|
||||
case 256:
|
||||
memcpy(ciphertext, ctext[j-1], 16);
|
||||
memcpy(ciphertext+16, ctext[j], 16);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (imode == CFB8)
|
||||
{ /* ct = CT[j-15] || CT[j-14] || ... || CT[j] */
|
||||
for (n1 = 0, n2 = nkeysz-1; n1 < nkeysz; ++n1, --n2)
|
||||
ciphertext[n1] = ptext[j-n2][0];
|
||||
}
|
||||
else if(imode == CFB1)
|
||||
{
|
||||
for(n1=0,n2=akeysz-1 ; n1 < akeysz ; ++n1,--n2)
|
||||
sb(ciphertext,n1,gb(ptext[j-n2],0));
|
||||
}
|
||||
else
|
||||
switch (akeysz)
|
||||
{
|
||||
case 128:
|
||||
memcpy(ciphertext, ptext[j], 16);
|
||||
break;
|
||||
case 192:
|
||||
memcpy(ciphertext, ptext[j-1]+8, 8);
|
||||
memcpy(ciphertext+8, ptext[j], 16);
|
||||
break;
|
||||
case 256:
|
||||
memcpy(ciphertext, ptext[j-1], 16);
|
||||
memcpy(ciphertext+16, ptext[j], 16);
|
||||
break;
|
||||
}
|
||||
}
|
||||
/* Compute next key: Key[i+1] = Key[i] xor ct */
|
||||
for (n = 0; n < nkeysz; ++n)
|
||||
key[i+1][n] = key[i][n] ^ ciphertext[n];
|
||||
|
||||
/* Compute next IV and text */
|
||||
if (dir == XENCRYPT)
|
||||
{
|
||||
switch (imode)
|
||||
{
|
||||
case ECB:
|
||||
memcpy(ptext[0], ctext[j], AES_BLOCK_SIZE);
|
||||
break;
|
||||
case CBC:
|
||||
case OFB:
|
||||
case CFB128:
|
||||
memcpy(iv[i+1], ctext[j], AES_BLOCK_SIZE);
|
||||
memcpy(ptext[0], ctext[j-1], AES_BLOCK_SIZE);
|
||||
break;
|
||||
case CFB8:
|
||||
/* IV[i+1] = ct */
|
||||
for (n1 = 0, n2 = 15; n1 < 16; ++n1, --n2)
|
||||
iv[i+1][n1] = ctext[j-n2][0];
|
||||
ptext[0][0] = ctext[j-16][0];
|
||||
break;
|
||||
case CFB1:
|
||||
for(n1=0,n2=127 ; n1 < 128 ; ++n1,--n2)
|
||||
sb(iv[i+1],n1,gb(ctext[j-n2],0));
|
||||
ptext[0][0]=ctext[j-128][0]&0x80;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (imode)
|
||||
{
|
||||
case ECB:
|
||||
memcpy(ctext[0], ptext[j], AES_BLOCK_SIZE);
|
||||
break;
|
||||
case CBC:
|
||||
case OFB:
|
||||
case CFB128:
|
||||
memcpy(iv[i+1], ptext[j], AES_BLOCK_SIZE);
|
||||
memcpy(ctext[0], ptext[j-1], AES_BLOCK_SIZE);
|
||||
break;
|
||||
case CFB8:
|
||||
for (n1 = 0, n2 = 15; n1 < 16; ++n1, --n2)
|
||||
iv[i+1][n1] = ptext[j-n2][0];
|
||||
ctext[0][0] = ptext[j-16][0];
|
||||
break;
|
||||
case CFB1:
|
||||
for(n1=0,n2=127 ; n1 < 128 ; ++n1,--n2)
|
||||
sb(iv[i+1],n1,gb(ptext[j-n2],0));
|
||||
ctext[0][0]=ptext[j-128][0]&0x80;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*================================================*/
|
||||
/*----------------------------
|
||||
# Config info for v-one
|
||||
# AESVS MMT test data for ECB
|
||||
# State : Encrypt and Decrypt
|
||||
# Key Length : 256
|
||||
# Fri Aug 30 04:07:22 PM
|
||||
----------------------------*/
|
||||
|
||||
static int proc_file(char *rqfile, char *rspfile)
|
||||
{
|
||||
char afn[256], rfn[256];
|
||||
FILE *afp = NULL, *rfp = NULL;
|
||||
char ibuf[2048];
|
||||
char tbuf[2048];
|
||||
int ilen, len, ret = 0;
|
||||
char algo[8] = "";
|
||||
char amode[8] = "";
|
||||
char atest[8] = "";
|
||||
int akeysz = 0;
|
||||
unsigned char iVec[20], aKey[40];
|
||||
int dir = -1, err = 0, step = 0;
|
||||
unsigned char plaintext[2048];
|
||||
unsigned char ciphertext[2048];
|
||||
char *rp;
|
||||
EVP_CIPHER_CTX ctx;
|
||||
EVP_CIPHER_CTX_init(&ctx);
|
||||
|
||||
if (!rqfile || !(*rqfile))
|
||||
{
|
||||
printf("No req file\n");
|
||||
return -1;
|
||||
}
|
||||
strcpy(afn, rqfile);
|
||||
|
||||
if ((afp = fopen(afn, "r")) == NULL)
|
||||
{
|
||||
printf("Cannot open file: %s, %s\n",
|
||||
afn, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
if (!rspfile)
|
||||
{
|
||||
strcpy(rfn,afn);
|
||||
rp=strstr(rfn,"req/");
|
||||
#ifdef OPENSSL_SYS_WIN32
|
||||
if (!rp)
|
||||
rp=strstr(rfn,"req\\");
|
||||
#endif
|
||||
assert(rp);
|
||||
memcpy(rp,"rsp",3);
|
||||
rp = strstr(rfn, ".req");
|
||||
memcpy(rp, ".rsp", 4);
|
||||
rspfile = rfn;
|
||||
}
|
||||
if ((rfp = fopen(rspfile, "w")) == NULL)
|
||||
{
|
||||
printf("Cannot open file: %s, %s\n",
|
||||
rfn, strerror(errno));
|
||||
fclose(afp);
|
||||
afp = NULL;
|
||||
return -1;
|
||||
}
|
||||
while (!err && (fgets(ibuf, sizeof(ibuf), afp)) != NULL)
|
||||
{
|
||||
tidy_line(tbuf, ibuf);
|
||||
ilen = strlen(ibuf);
|
||||
/* printf("step=%d ibuf=%s",step,ibuf); */
|
||||
switch (step)
|
||||
{
|
||||
case 0: /* read preamble */
|
||||
if (ibuf[0] == '\n')
|
||||
{ /* end of preamble */
|
||||
if ((*algo == '\0') ||
|
||||
(*amode == '\0') ||
|
||||
(akeysz == 0))
|
||||
{
|
||||
printf("Missing Algorithm, Mode or KeySize (%s/%s/%d)\n",
|
||||
algo,amode,akeysz);
|
||||
err = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
fputs(ibuf, rfp);
|
||||
++ step;
|
||||
}
|
||||
}
|
||||
else if (ibuf[0] != '#')
|
||||
{
|
||||
printf("Invalid preamble item: %s\n", ibuf);
|
||||
err = 1;
|
||||
}
|
||||
else
|
||||
{ /* process preamble */
|
||||
char *xp, *pp = ibuf+2;
|
||||
int n;
|
||||
if (akeysz)
|
||||
{ /* insert current time & date */
|
||||
time_t rtim = time(0);
|
||||
fprintf(rfp, "# %s", ctime(&rtim));
|
||||
}
|
||||
else
|
||||
{
|
||||
fputs(ibuf, rfp);
|
||||
if (strncmp(pp, "AESVS ", 6) == 0)
|
||||
{
|
||||
strcpy(algo, "AES");
|
||||
/* get test type */
|
||||
pp += 6;
|
||||
xp = strchr(pp, ' ');
|
||||
n = xp-pp;
|
||||
strncpy(atest, pp, n);
|
||||
atest[n] = '\0';
|
||||
/* get mode */
|
||||
xp = strrchr(pp, ' '); /* get mode" */
|
||||
n = strlen(xp+1)-1;
|
||||
strncpy(amode, xp+1, n);
|
||||
amode[n] = '\0';
|
||||
/* amode[3] = '\0'; */
|
||||
if (VERBOSE)
|
||||
printf("Test = %s, Mode = %s\n", atest, amode);
|
||||
}
|
||||
else if (strncasecmp(pp, "Key Length : ", 13) == 0)
|
||||
{
|
||||
akeysz = atoi(pp+13);
|
||||
if (VERBOSE)
|
||||
printf("Key size = %d\n", akeysz);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 1: /* [ENCRYPT] | [DECRYPT] */
|
||||
if (ibuf[0] == '[')
|
||||
{
|
||||
fputs(ibuf, rfp);
|
||||
++step;
|
||||
if (strncasecmp(ibuf, "[ENCRYPT]", 9) == 0)
|
||||
dir = 1;
|
||||
else if (strncasecmp(ibuf, "[DECRYPT]", 9) == 0)
|
||||
dir = 0;
|
||||
else
|
||||
{
|
||||
printf("Invalid keyword: %s\n", ibuf);
|
||||
err = 1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
else if (dir == -1)
|
||||
{
|
||||
err = 1;
|
||||
printf("Missing ENCRYPT/DECRYPT keyword\n");
|
||||
break;
|
||||
}
|
||||
else
|
||||
step = 2;
|
||||
|
||||
case 2: /* KEY = xxxx */
|
||||
fputs(ibuf, rfp);
|
||||
if(*ibuf == '\n')
|
||||
break;
|
||||
if(!strncasecmp(ibuf,"COUNT = ",8))
|
||||
break;
|
||||
|
||||
if (strncasecmp(ibuf, "KEY = ", 6) != 0)
|
||||
{
|
||||
printf("Missing KEY\n");
|
||||
err = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
len = hex2bin((char*)ibuf+6, aKey);
|
||||
if (len < 0)
|
||||
{
|
||||
printf("Invalid KEY\n");
|
||||
err =1;
|
||||
break;
|
||||
}
|
||||
PrintValue("KEY", aKey, len);
|
||||
if (strcmp(amode, "ECB") == 0)
|
||||
{
|
||||
memset(iVec, 0, sizeof(iVec));
|
||||
step = (dir)? 4: 5; /* no ivec for ECB */
|
||||
}
|
||||
else
|
||||
++step;
|
||||
}
|
||||
break;
|
||||
|
||||
case 3: /* IV = xxxx */
|
||||
fputs(ibuf, rfp);
|
||||
if (strncasecmp(ibuf, "IV = ", 5) != 0)
|
||||
{
|
||||
printf("Missing IV\n");
|
||||
err = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
len = hex2bin((char*)ibuf+5, iVec);
|
||||
if (len < 0)
|
||||
{
|
||||
printf("Invalid IV\n");
|
||||
err =1;
|
||||
break;
|
||||
}
|
||||
PrintValue("IV", iVec, len);
|
||||
step = (dir)? 4: 5;
|
||||
}
|
||||
break;
|
||||
|
||||
case 4: /* PLAINTEXT = xxxx */
|
||||
fputs(ibuf, rfp);
|
||||
if (strncasecmp(ibuf, "PLAINTEXT = ", 12) != 0)
|
||||
{
|
||||
printf("Missing PLAINTEXT\n");
|
||||
err = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
int nn = strlen(ibuf+12);
|
||||
if(!strcmp(amode,"CFB1"))
|
||||
len=bint2bin(ibuf+12,nn-1,plaintext);
|
||||
else
|
||||
len=hex2bin(ibuf+12, plaintext);
|
||||
if (len < 0)
|
||||
{
|
||||
printf("Invalid PLAINTEXT: %s", ibuf+12);
|
||||
err =1;
|
||||
break;
|
||||
}
|
||||
if (len >= (int)sizeof(plaintext))
|
||||
{
|
||||
printf("Buffer overflow\n");
|
||||
}
|
||||
PrintValue("PLAINTEXT", (unsigned char*)plaintext, len);
|
||||
if (strcmp(atest, "MCT") == 0) /* Monte Carlo Test */
|
||||
{
|
||||
if(do_mct(amode, akeysz, aKey, iVec,
|
||||
dir, (unsigned char*)plaintext, len,
|
||||
rfp) < 0)
|
||||
EXIT(1);
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = AESTest(&ctx, amode, akeysz, aKey, iVec,
|
||||
dir, /* 0 = decrypt, 1 = encrypt */
|
||||
plaintext, ciphertext, len);
|
||||
OutputValue("CIPHERTEXT",ciphertext,len,rfp,
|
||||
!strcmp(amode,"CFB1"));
|
||||
}
|
||||
step = 6;
|
||||
}
|
||||
break;
|
||||
|
||||
case 5: /* CIPHERTEXT = xxxx */
|
||||
fputs(ibuf, rfp);
|
||||
if (strncasecmp(ibuf, "CIPHERTEXT = ", 13) != 0)
|
||||
{
|
||||
printf("Missing KEY\n");
|
||||
err = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!strcmp(amode,"CFB1"))
|
||||
len=bint2bin(ibuf+13,strlen(ibuf+13)-1,ciphertext);
|
||||
else
|
||||
len = hex2bin(ibuf+13,ciphertext);
|
||||
if (len < 0)
|
||||
{
|
||||
printf("Invalid CIPHERTEXT\n");
|
||||
err =1;
|
||||
break;
|
||||
}
|
||||
|
||||
PrintValue("CIPHERTEXT", ciphertext, len);
|
||||
if (strcmp(atest, "MCT") == 0) /* Monte Carlo Test */
|
||||
{
|
||||
do_mct(amode, akeysz, aKey, iVec,
|
||||
dir, ciphertext, len, rfp);
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = AESTest(&ctx, amode, akeysz, aKey, iVec,
|
||||
dir, /* 0 = decrypt, 1 = encrypt */
|
||||
plaintext, ciphertext, len);
|
||||
OutputValue("PLAINTEXT",(unsigned char *)plaintext,len,rfp,
|
||||
!strcmp(amode,"CFB1"));
|
||||
}
|
||||
step = 6;
|
||||
}
|
||||
break;
|
||||
|
||||
case 6:
|
||||
if (ibuf[0] != '\n')
|
||||
{
|
||||
err = 1;
|
||||
printf("Missing terminator\n");
|
||||
}
|
||||
else if (strcmp(atest, "MCT") != 0)
|
||||
{ /* MCT already added terminating nl */
|
||||
fputs(ibuf, rfp);
|
||||
}
|
||||
step = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (rfp)
|
||||
fclose(rfp);
|
||||
if (afp)
|
||||
fclose(afp);
|
||||
return err;
|
||||
}
|
||||
|
||||
/*--------------------------------------------------
|
||||
Processes either a single file or
|
||||
a set of files whose names are passed in a file.
|
||||
A single file is specified as:
|
||||
aes_test -f xxx.req
|
||||
A set of files is specified as:
|
||||
aes_test -d xxxxx.xxx
|
||||
The default is: -d req.txt
|
||||
--------------------------------------------------*/
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
char *rqlist = "req.txt", *rspfile = NULL;
|
||||
FILE *fp = NULL;
|
||||
char fn[250] = "", rfn[256] = "";
|
||||
int f_opt = 0, d_opt = 1;
|
||||
|
||||
#ifdef OPENSSL_FIPS
|
||||
if(!FIPS_mode_set(1))
|
||||
{
|
||||
do_print_errors();
|
||||
EXIT(1);
|
||||
}
|
||||
#endif
|
||||
if (argc > 1)
|
||||
{
|
||||
if (strcasecmp(argv[1], "-d") == 0)
|
||||
{
|
||||
d_opt = 1;
|
||||
}
|
||||
else if (strcasecmp(argv[1], "-f") == 0)
|
||||
{
|
||||
f_opt = 1;
|
||||
d_opt = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Invalid parameter: %s\n", argv[1]);
|
||||
return 0;
|
||||
}
|
||||
if (argc < 3)
|
||||
{
|
||||
printf("Missing parameter\n");
|
||||
return 0;
|
||||
}
|
||||
if (d_opt)
|
||||
rqlist = argv[2];
|
||||
else
|
||||
{
|
||||
strcpy(fn, argv[2]);
|
||||
rspfile = argv[3];
|
||||
}
|
||||
}
|
||||
if (d_opt)
|
||||
{ /* list of files (directory) */
|
||||
if (!(fp = fopen(rqlist, "r")))
|
||||
{
|
||||
printf("Cannot open req list file\n");
|
||||
return -1;
|
||||
}
|
||||
while (fgets(fn, sizeof(fn), fp))
|
||||
{
|
||||
strtok(fn, "\r\n");
|
||||
strcpy(rfn, fn);
|
||||
if (VERBOSE)
|
||||
printf("Processing: %s\n", rfn);
|
||||
if (proc_file(rfn, rspfile))
|
||||
{
|
||||
printf(">>> Processing failed for: %s <<<\n", rfn);
|
||||
EXIT(1);
|
||||
}
|
||||
}
|
||||
fclose(fp);
|
||||
}
|
||||
else /* single file */
|
||||
{
|
||||
if (VERBOSE)
|
||||
printf("Processing: %s\n", fn);
|
||||
if (proc_file(fn, rspfile))
|
||||
{
|
||||
printf(">>> Processing failed for: %s <<<\n", fn);
|
||||
}
|
||||
}
|
||||
EXIT(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -1,111 +0,0 @@
|
|||
#
|
||||
# OpenSSL/fips/des/Makefile
|
||||
#
|
||||
|
||||
DIR= des
|
||||
TOP= ../..
|
||||
CC= cc
|
||||
INCLUDES=
|
||||
CFLAG=-g
|
||||
INSTALL_PREFIX=
|
||||
OPENSSLDIR= /usr/local/ssl
|
||||
INSTALLTOP=/usr/local/ssl
|
||||
MAKEDEPPROG= makedepend
|
||||
MAKEDEPEND= $(TOP)/util/domd $(TOP) -MD $(MAKEDEPPROG)
|
||||
MAKEFILE= Makefile
|
||||
AR= ar r
|
||||
|
||||
ASFLAGS= $(INCLUDES) $(ASFLAG)
|
||||
AFLAGS= $(ASFLAGS)
|
||||
|
||||
CFLAGS= $(INCLUDES) $(CFLAG)
|
||||
|
||||
GENERAL=Makefile
|
||||
TEST= fips_desmovs.c
|
||||
APPS=
|
||||
|
||||
LIB=$(TOP)/libcrypto.a
|
||||
LIBSRC=fips_des_selftest.c
|
||||
LIBOBJ=fips_des_selftest.o
|
||||
|
||||
SRC= $(LIBSRC)
|
||||
|
||||
EXHEADER=
|
||||
HEADER=
|
||||
|
||||
ALL= $(GENERAL) $(SRC) $(HEADER)
|
||||
|
||||
top:
|
||||
(cd $(TOP); $(MAKE) DIRS=fips FDIRS=$(DIR) sub_all)
|
||||
|
||||
all: lib
|
||||
|
||||
lib: $(LIBOBJ)
|
||||
@echo $(LIBOBJ) > lib
|
||||
|
||||
files:
|
||||
$(PERL) $(TOP)/util/files.pl Makefile >> $(TOP)/MINFO
|
||||
|
||||
links:
|
||||
@$(PERL) $(TOP)/util/mklink.pl $(TOP)/include/openssl $(EXHEADER)
|
||||
@$(PERL) $(TOP)/util/mklink.pl $(TOP)/test $(TEST)
|
||||
@$(PERL) $(TOP)/util/mklink.pl $(TOP)/apps $(APPS)
|
||||
|
||||
install:
|
||||
@headerlist="$(EXHEADER)"; for i in $$headerlist; \
|
||||
do \
|
||||
(cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
|
||||
chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
|
||||
done
|
||||
|
||||
tags:
|
||||
ctags $(SRC)
|
||||
|
||||
tests:
|
||||
|
||||
fips_test:
|
||||
-find ../testvectors/tdes/req -name '*.req' > testlist
|
||||
-rm -rf ../testvectors/tdes/rsp
|
||||
mkdir ../testvectors/tdes/rsp
|
||||
if [ -s testlist ]; then $(TOP)/util/shlib_wrap.sh $(TOP)/test/fips_desmovs -d testlist; fi
|
||||
|
||||
lint:
|
||||
lint -DLINT $(INCLUDES) $(SRC)>fluff
|
||||
|
||||
depend:
|
||||
$(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) \
|
||||
$(SRC) $(TEST)
|
||||
dclean:
|
||||
$(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
|
||||
mv -f Makefile.new $(MAKEFILE)
|
||||
|
||||
clean:
|
||||
rm -f *.o asm/*.o *.obj lib tags core .pure .nfs* *.old *.bak fluff testlist
|
||||
# DO NOT DELETE THIS LINE -- make depend depends on it.
|
||||
|
||||
fips_des_selftest.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
|
||||
fips_des_selftest.o: ../../include/openssl/crypto.h
|
||||
fips_des_selftest.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
|
||||
fips_des_selftest.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
|
||||
fips_des_selftest.o: ../../include/openssl/lhash.h
|
||||
fips_des_selftest.o: ../../include/openssl/obj_mac.h
|
||||
fips_des_selftest.o: ../../include/openssl/objects.h
|
||||
fips_des_selftest.o: ../../include/openssl/opensslconf.h
|
||||
fips_des_selftest.o: ../../include/openssl/opensslv.h
|
||||
fips_des_selftest.o: ../../include/openssl/ossl_typ.h
|
||||
fips_des_selftest.o: ../../include/openssl/safestack.h
|
||||
fips_des_selftest.o: ../../include/openssl/stack.h
|
||||
fips_des_selftest.o: ../../include/openssl/symhacks.h fips_des_selftest.c
|
||||
fips_desmovs.o: ../../e_os.h ../../include/openssl/asn1.h
|
||||
fips_desmovs.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
|
||||
fips_desmovs.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
|
||||
fips_desmovs.o: ../../include/openssl/des_old.h ../../include/openssl/e_os2.h
|
||||
fips_desmovs.o: ../../include/openssl/err.h ../../include/openssl/evp.h
|
||||
fips_desmovs.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
|
||||
fips_desmovs.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
|
||||
fips_desmovs.o: ../../include/openssl/opensslconf.h
|
||||
fips_desmovs.o: ../../include/openssl/opensslv.h
|
||||
fips_desmovs.o: ../../include/openssl/ossl_typ.h
|
||||
fips_desmovs.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
|
||||
fips_desmovs.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
|
||||
fips_desmovs.o: ../../include/openssl/ui_compat.h ../fips_utl.h fips_desmovs.c
|
||||
|
|
@ -1,137 +0,0 @@
|
|||
/* ====================================================================
|
||||
* Copyright (c) 2003 The OpenSSL Project. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* 3. All advertising materials mentioning features or use of this
|
||||
* software must display the following acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
|
||||
*
|
||||
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission. For written permission, please contact
|
||||
* openssl-core@openssl.org.
|
||||
*
|
||||
* 5. Products derived from this software may not be called "OpenSSL"
|
||||
* nor may "OpenSSL" appear in their names without prior written
|
||||
* permission of the OpenSSL Project.
|
||||
*
|
||||
* 6. Redistributions of any form whatsoever must retain the following
|
||||
* acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit (http://www.openssl.org/)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
|
||||
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
|
||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/fips.h>
|
||||
#include <openssl/evp.h>
|
||||
#include <openssl/opensslconf.h>
|
||||
|
||||
#ifdef OPENSSL_FIPS
|
||||
|
||||
static struct
|
||||
{
|
||||
unsigned char key[16];
|
||||
unsigned char plaintext[8];
|
||||
unsigned char ciphertext[8];
|
||||
} tests2[]=
|
||||
{
|
||||
{
|
||||
{ 0x7c,0x4f,0x6e,0xf7,0xa2,0x04,0x16,0xec,
|
||||
0x0b,0x6b,0x7c,0x9e,0x5e,0x19,0xa7,0xc4 },
|
||||
{ 0x06,0xa7,0xd8,0x79,0xaa,0xce,0x69,0xef },
|
||||
{ 0x4c,0x11,0x17,0x55,0xbf,0xc4,0x4e,0xfd }
|
||||
},
|
||||
{
|
||||
{ 0x5d,0x9e,0x01,0xd3,0x25,0xc7,0x3e,0x34,
|
||||
0x01,0x16,0x7c,0x85,0x23,0xdf,0xe0,0x68 },
|
||||
{ 0x9c,0x50,0x09,0x0f,0x5e,0x7d,0x69,0x7e },
|
||||
{ 0xd2,0x0b,0x18,0xdf,0xd9,0x0d,0x9e,0xff },
|
||||
}
|
||||
};
|
||||
|
||||
static struct
|
||||
{
|
||||
unsigned char key[24];
|
||||
unsigned char plaintext[8];
|
||||
unsigned char ciphertext[8];
|
||||
} tests3[]=
|
||||
{
|
||||
{
|
||||
{ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0xFE,0xDC,0xBA,0x98,0x76,0x54,0x32,0x10,
|
||||
0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0 },
|
||||
{ 0x8f,0x8f,0xbf,0x9b,0x5d,0x48,0xb4,0x1c },
|
||||
{ 0x59,0x8c,0xe5,0xd3,0x6c,0xa2,0xea,0x1b },
|
||||
},
|
||||
{
|
||||
{ 0xDC,0xBA,0x98,0x76,0x54,0x32,0x10,0xFE,
|
||||
0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF,
|
||||
0xED,0x39,0xD9,0x50,0xFA,0x74,0xBC,0xC4 },
|
||||
{ 0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF },
|
||||
{ 0x11,0x25,0xb0,0x35,0xbe,0xa0,0x82,0x86 },
|
||||
},
|
||||
};
|
||||
|
||||
void FIPS_corrupt_des()
|
||||
{
|
||||
tests2[0].plaintext[0]++;
|
||||
}
|
||||
|
||||
int FIPS_selftest_des()
|
||||
{
|
||||
int n, ret = 0;
|
||||
EVP_CIPHER_CTX ctx;
|
||||
EVP_CIPHER_CTX_init(&ctx);
|
||||
/* Encrypt/decrypt with 2-key 3DES and compare to known answers */
|
||||
for(n=0 ; n < 2 ; ++n)
|
||||
{
|
||||
if (!fips_cipher_test(&ctx, EVP_des_ede_ecb(),
|
||||
tests2[n].key, NULL,
|
||||
tests2[n].plaintext, tests2[n].ciphertext, 8))
|
||||
goto err;
|
||||
}
|
||||
|
||||
/* Encrypt/decrypt with 3DES and compare to known answers */
|
||||
for(n=0 ; n < 2 ; ++n)
|
||||
{
|
||||
if (!fips_cipher_test(&ctx, EVP_des_ede3_ecb(),
|
||||
tests3[n].key, NULL,
|
||||
tests3[n].plaintext, tests3[n].ciphertext, 8))
|
||||
goto err;
|
||||
}
|
||||
ret = 1;
|
||||
err:
|
||||
EVP_CIPHER_CTX_cleanup(&ctx);
|
||||
if (ret == 0)
|
||||
FIPSerr(FIPS_F_FIPS_SELFTEST_DES,FIPS_R_SELFTEST_FAILED);
|
||||
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
|
@ -1,702 +0,0 @@
|
|||
/* ====================================================================
|
||||
* Copyright (c) 2004 The OpenSSL Project. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* 3. All advertising materials mentioning features or use of this
|
||||
* software must display the following acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
|
||||
*
|
||||
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission. For written permission, please contact
|
||||
* openssl-core@openssl.org.
|
||||
*
|
||||
* 5. Products derived from this software may not be called "OpenSSL"
|
||||
* nor may "OpenSSL" appear in their names without prior written
|
||||
* permission of the OpenSSL Project.
|
||||
*
|
||||
* 6. Redistributions of any form whatsoever must retain the following
|
||||
* acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit (http://www.openssl.org/)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
|
||||
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
|
||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
/*---------------------------------------------
|
||||
NIST DES Modes of Operation Validation System
|
||||
Test Program
|
||||
|
||||
Based on the AES Validation Suite, which was:
|
||||
Donated to OpenSSL by:
|
||||
V-ONE Corporation
|
||||
20250 Century Blvd, Suite 300
|
||||
Germantown, MD 20874
|
||||
U.S.A.
|
||||
----------------------------------------------*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <assert.h>
|
||||
#include <ctype.h>
|
||||
#include <openssl/des.h>
|
||||
#include <openssl/evp.h>
|
||||
#include <openssl/bn.h>
|
||||
|
||||
#include <openssl/err.h>
|
||||
#include "e_os.h"
|
||||
|
||||
#ifndef OPENSSL_FIPS
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
printf("No FIPS DES support\n");
|
||||
return(0);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
#include <openssl/fips.h>
|
||||
#include "fips_utl.h"
|
||||
|
||||
#define DES_BLOCK_SIZE 8
|
||||
|
||||
#define VERBOSE 0
|
||||
|
||||
static int DESTest(EVP_CIPHER_CTX *ctx,
|
||||
char *amode, int akeysz, unsigned char *aKey,
|
||||
unsigned char *iVec,
|
||||
int dir, /* 0 = decrypt, 1 = encrypt */
|
||||
unsigned char *out, unsigned char *in, int len)
|
||||
{
|
||||
const EVP_CIPHER *cipher = NULL;
|
||||
|
||||
if (akeysz != 192)
|
||||
{
|
||||
printf("Invalid key size: %d\n", akeysz);
|
||||
EXIT(1);
|
||||
}
|
||||
|
||||
if (strcasecmp(amode, "CBC") == 0)
|
||||
cipher = EVP_des_ede3_cbc();
|
||||
else if (strcasecmp(amode, "ECB") == 0)
|
||||
cipher = EVP_des_ede3_ecb();
|
||||
else if (strcasecmp(amode, "CFB64") == 0)
|
||||
cipher = EVP_des_ede3_cfb64();
|
||||
else if (strncasecmp(amode, "OFB", 3) == 0)
|
||||
cipher = EVP_des_ede3_ofb();
|
||||
else if(!strcasecmp(amode,"CFB8"))
|
||||
cipher = EVP_des_ede3_cfb8();
|
||||
else if(!strcasecmp(amode,"CFB1"))
|
||||
cipher = EVP_des_ede3_cfb1();
|
||||
else
|
||||
{
|
||||
printf("Unknown mode: %s\n", amode);
|
||||
EXIT(1);
|
||||
}
|
||||
|
||||
if (EVP_CipherInit_ex(ctx, cipher, NULL, aKey, iVec, dir) <= 0)
|
||||
return 0;
|
||||
if(!strcasecmp(amode,"CFB1"))
|
||||
M_EVP_CIPHER_CTX_set_flags(ctx, EVP_CIPH_FLAG_LENGTH_BITS);
|
||||
EVP_Cipher(ctx, out, in, len);
|
||||
|
||||
return 1;
|
||||
}
|
||||
#if 0
|
||||
static void DebugValue(char *tag, unsigned char *val, int len)
|
||||
{
|
||||
char obuf[2048];
|
||||
int olen;
|
||||
olen = bin2hex(val, len, obuf);
|
||||
printf("%s = %.*s\n", tag, olen, obuf);
|
||||
}
|
||||
#endif
|
||||
static void shiftin(unsigned char *dst,unsigned char *src,int nbits)
|
||||
{
|
||||
int n;
|
||||
|
||||
/* move the bytes... */
|
||||
memmove(dst,dst+nbits/8,3*8-nbits/8);
|
||||
/* append new data */
|
||||
memcpy(dst+3*8-nbits/8,src,(nbits+7)/8);
|
||||
/* left shift the bits */
|
||||
if(nbits%8)
|
||||
for(n=0 ; n < 3*8 ; ++n)
|
||||
dst[n]=(dst[n] << (nbits%8))|(dst[n+1] >> (8-nbits%8));
|
||||
}
|
||||
|
||||
/*-----------------------------------------------*/
|
||||
char *t_tag[2] = {"PLAINTEXT", "CIPHERTEXT"};
|
||||
char *t_mode[6] = {"CBC","ECB","OFB","CFB1","CFB8","CFB64"};
|
||||
enum Mode {CBC, ECB, OFB, CFB1, CFB8, CFB64};
|
||||
int Sizes[6]={64,64,64,1,8,64};
|
||||
|
||||
static void do_mct(char *amode,
|
||||
int akeysz, int numkeys, unsigned char *akey,unsigned char *ivec,
|
||||
int dir, unsigned char *text, int len,
|
||||
FILE *rfp)
|
||||
{
|
||||
int i,imode;
|
||||
unsigned char nk[4*8]; /* longest key+8 */
|
||||
unsigned char text0[8];
|
||||
|
||||
for (imode=0 ; imode < 6 ; ++imode)
|
||||
if(!strcmp(amode,t_mode[imode]))
|
||||
break;
|
||||
if (imode == 6)
|
||||
{
|
||||
printf("Unrecognized mode: %s\n", amode);
|
||||
EXIT(1);
|
||||
}
|
||||
|
||||
for(i=0 ; i < 400 ; ++i)
|
||||
{
|
||||
int j;
|
||||
int n;
|
||||
int kp=akeysz/64;
|
||||
unsigned char old_iv[8];
|
||||
EVP_CIPHER_CTX ctx;
|
||||
EVP_CIPHER_CTX_init(&ctx);
|
||||
|
||||
fprintf(rfp,"\nCOUNT = %d\n",i);
|
||||
if(kp == 1)
|
||||
OutputValue("KEY",akey,8,rfp,0);
|
||||
else
|
||||
for(n=0 ; n < kp ; ++n)
|
||||
{
|
||||
fprintf(rfp,"KEY%d",n+1);
|
||||
OutputValue("",akey+n*8,8,rfp,0);
|
||||
}
|
||||
|
||||
if(imode != ECB)
|
||||
OutputValue("IV",ivec,8,rfp,0);
|
||||
OutputValue(t_tag[dir^1],text,len,rfp,imode == CFB1);
|
||||
#if 0
|
||||
/* compensate for endianness */
|
||||
if(imode == CFB1)
|
||||
text[0]<<=7;
|
||||
#endif
|
||||
memcpy(text0,text,8);
|
||||
|
||||
for(j=0 ; j < 10000 ; ++j)
|
||||
{
|
||||
unsigned char old_text[8];
|
||||
|
||||
memcpy(old_text,text,8);
|
||||
if(j == 0)
|
||||
{
|
||||
memcpy(old_iv,ivec,8);
|
||||
DESTest(&ctx,amode,akeysz,akey,ivec,dir,text,text,len);
|
||||
}
|
||||
else
|
||||
{
|
||||
memcpy(old_iv,ctx.iv,8);
|
||||
EVP_Cipher(&ctx,text,text,len);
|
||||
}
|
||||
if(j == 9999)
|
||||
{
|
||||
OutputValue(t_tag[dir],text,len,rfp,imode == CFB1);
|
||||
/* memcpy(ivec,text,8); */
|
||||
}
|
||||
/* DebugValue("iv",ctx.iv,8); */
|
||||
/* accumulate material for the next key */
|
||||
shiftin(nk,text,Sizes[imode]);
|
||||
/* DebugValue("nk",nk,24);*/
|
||||
if((dir && (imode == CFB1 || imode == CFB8 || imode == CFB64
|
||||
|| imode == CBC)) || imode == OFB)
|
||||
memcpy(text,old_iv,8);
|
||||
|
||||
if(!dir && (imode == CFB1 || imode == CFB8 || imode == CFB64))
|
||||
{
|
||||
/* the test specifies using the output of the raw DES operation
|
||||
which we don't have, so reconstruct it... */
|
||||
for(n=0 ; n < 8 ; ++n)
|
||||
text[n]^=old_text[n];
|
||||
}
|
||||
}
|
||||
for(n=0 ; n < 8 ; ++n)
|
||||
akey[n]^=nk[16+n];
|
||||
for(n=0 ; n < 8 ; ++n)
|
||||
akey[8+n]^=nk[8+n];
|
||||
for(n=0 ; n < 8 ; ++n)
|
||||
akey[16+n]^=nk[n];
|
||||
if(numkeys < 3)
|
||||
memcpy(&akey[2*8],akey,8);
|
||||
if(numkeys < 2)
|
||||
memcpy(&akey[8],akey,8);
|
||||
DES_set_odd_parity((DES_cblock *)akey);
|
||||
DES_set_odd_parity((DES_cblock *)(akey+8));
|
||||
DES_set_odd_parity((DES_cblock *)(akey+16));
|
||||
memcpy(ivec,ctx.iv,8);
|
||||
|
||||
/* pointless exercise - the final text doesn't depend on the
|
||||
initial text in OFB mode, so who cares what it is? (Who
|
||||
designed these tests?) */
|
||||
if(imode == OFB)
|
||||
for(n=0 ; n < 8 ; ++n)
|
||||
text[n]=text0[n]^old_iv[n];
|
||||
}
|
||||
}
|
||||
|
||||
static int proc_file(char *rqfile, char *rspfile)
|
||||
{
|
||||
char afn[256], rfn[256];
|
||||
FILE *afp = NULL, *rfp = NULL;
|
||||
char ibuf[2048], tbuf[2048];
|
||||
int ilen, len, ret = 0;
|
||||
char amode[8] = "";
|
||||
char atest[100] = "";
|
||||
int akeysz=0;
|
||||
unsigned char iVec[20], aKey[40];
|
||||
int dir = -1, err = 0, step = 0;
|
||||
unsigned char plaintext[2048];
|
||||
unsigned char ciphertext[2048];
|
||||
char *rp;
|
||||
EVP_CIPHER_CTX ctx;
|
||||
int numkeys=1;
|
||||
EVP_CIPHER_CTX_init(&ctx);
|
||||
|
||||
if (!rqfile || !(*rqfile))
|
||||
{
|
||||
printf("No req file\n");
|
||||
return -1;
|
||||
}
|
||||
strcpy(afn, rqfile);
|
||||
|
||||
if ((afp = fopen(afn, "r")) == NULL)
|
||||
{
|
||||
printf("Cannot open file: %s, %s\n",
|
||||
afn, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
if (!rspfile)
|
||||
{
|
||||
strcpy(rfn,afn);
|
||||
rp=strstr(rfn,"req/");
|
||||
#ifdef OPENSSL_SYS_WIN32
|
||||
if (!rp)
|
||||
rp=strstr(rfn,"req\\");
|
||||
#endif
|
||||
assert(rp);
|
||||
memcpy(rp,"rsp",3);
|
||||
rp = strstr(rfn, ".req");
|
||||
memcpy(rp, ".rsp", 4);
|
||||
rspfile = rfn;
|
||||
}
|
||||
if ((rfp = fopen(rspfile, "w")) == NULL)
|
||||
{
|
||||
printf("Cannot open file: %s, %s\n",
|
||||
rfn, strerror(errno));
|
||||
fclose(afp);
|
||||
afp = NULL;
|
||||
return -1;
|
||||
}
|
||||
while (!err && (fgets(ibuf, sizeof(ibuf), afp)) != NULL)
|
||||
{
|
||||
tidy_line(tbuf, ibuf);
|
||||
ilen = strlen(ibuf);
|
||||
/* printf("step=%d ibuf=%s",step,ibuf);*/
|
||||
if(step == 3 && !strcmp(amode,"ECB"))
|
||||
{
|
||||
memset(iVec, 0, sizeof(iVec));
|
||||
step = (dir)? 4: 5; /* no ivec for ECB */
|
||||
}
|
||||
switch (step)
|
||||
{
|
||||
case 0: /* read preamble */
|
||||
if (ibuf[0] == '\n')
|
||||
{ /* end of preamble */
|
||||
if (*amode == '\0')
|
||||
{
|
||||
printf("Missing Mode\n");
|
||||
err = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
fputs(ibuf, rfp);
|
||||
++ step;
|
||||
}
|
||||
}
|
||||
else if (ibuf[0] != '#')
|
||||
{
|
||||
printf("Invalid preamble item: %s\n", ibuf);
|
||||
err = 1;
|
||||
}
|
||||
else
|
||||
{ /* process preamble */
|
||||
char *xp, *pp = ibuf+2;
|
||||
int n;
|
||||
if(*amode)
|
||||
{ /* insert current time & date */
|
||||
time_t rtim = time(0);
|
||||
fprintf(rfp, "# %s", ctime(&rtim));
|
||||
}
|
||||
else
|
||||
{
|
||||
fputs(ibuf, rfp);
|
||||
if(!strncmp(pp,"INVERSE ",8) || !strncmp(pp,"DES ",4)
|
||||
|| !strncmp(pp,"TDES ",5)
|
||||
|| !strncmp(pp,"PERMUTATION ",12)
|
||||
|| !strncmp(pp,"SUBSTITUTION ",13)
|
||||
|| !strncmp(pp,"VARIABLE ",9))
|
||||
{
|
||||
/* get test type */
|
||||
if(!strncmp(pp,"DES ",4))
|
||||
pp+=4;
|
||||
else if(!strncmp(pp,"TDES ",5))
|
||||
pp+=5;
|
||||
xp = strchr(pp, ' ');
|
||||
n = xp-pp;
|
||||
strncpy(atest, pp, n);
|
||||
atest[n] = '\0';
|
||||
/* get mode */
|
||||
xp = strrchr(pp, ' '); /* get mode" */
|
||||
n = strlen(xp+1)-1;
|
||||
strncpy(amode, xp+1, n);
|
||||
amode[n] = '\0';
|
||||
/* amode[3] = '\0'; */
|
||||
if (VERBOSE)
|
||||
printf("Test=%s, Mode=%s\n",atest,amode);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 1: /* [ENCRYPT] | [DECRYPT] */
|
||||
if(ibuf[0] == '\n')
|
||||
break;
|
||||
if (ibuf[0] == '[')
|
||||
{
|
||||
fputs(ibuf, rfp);
|
||||
++step;
|
||||
if (strncasecmp(ibuf, "[ENCRYPT]", 9) == 0)
|
||||
dir = 1;
|
||||
else if (strncasecmp(ibuf, "[DECRYPT]", 9) == 0)
|
||||
dir = 0;
|
||||
else
|
||||
{
|
||||
printf("Invalid keyword: %s\n", ibuf);
|
||||
err = 1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
else if (dir == -1)
|
||||
{
|
||||
err = 1;
|
||||
printf("Missing ENCRYPT/DECRYPT keyword\n");
|
||||
break;
|
||||
}
|
||||
else
|
||||
step = 2;
|
||||
|
||||
case 2: /* KEY = xxxx */
|
||||
if(*ibuf == '\n')
|
||||
{
|
||||
fputs(ibuf, rfp);
|
||||
break;
|
||||
}
|
||||
if(!strncasecmp(ibuf,"COUNT = ",8))
|
||||
{
|
||||
fputs(ibuf, rfp);
|
||||
break;
|
||||
}
|
||||
if(!strncasecmp(ibuf,"COUNT=",6))
|
||||
{
|
||||
fputs(ibuf, rfp);
|
||||
break;
|
||||
}
|
||||
if(!strncasecmp(ibuf,"NumKeys = ",10))
|
||||
{
|
||||
numkeys=atoi(ibuf+10);
|
||||
break;
|
||||
}
|
||||
|
||||
fputs(ibuf, rfp);
|
||||
if(!strncasecmp(ibuf,"KEY = ",6))
|
||||
{
|
||||
akeysz=64;
|
||||
len = hex2bin((char*)ibuf+6, aKey);
|
||||
if (len < 0)
|
||||
{
|
||||
printf("Invalid KEY\n");
|
||||
err=1;
|
||||
break;
|
||||
}
|
||||
PrintValue("KEY", aKey, len);
|
||||
++step;
|
||||
}
|
||||
else if(!strncasecmp(ibuf,"KEYs = ",7))
|
||||
{
|
||||
akeysz=64*3;
|
||||
len=hex2bin(ibuf+7,aKey);
|
||||
if(len != 8)
|
||||
{
|
||||
printf("Invalid KEY\n");
|
||||
err=1;
|
||||
break;
|
||||
}
|
||||
memcpy(aKey+8,aKey,8);
|
||||
memcpy(aKey+16,aKey,8);
|
||||
ibuf[4]='\0';
|
||||
PrintValue("KEYs",aKey,len);
|
||||
++step;
|
||||
}
|
||||
else if(!strncasecmp(ibuf,"KEY",3))
|
||||
{
|
||||
int n=ibuf[3]-'1';
|
||||
|
||||
akeysz=64*3;
|
||||
len=hex2bin(ibuf+7,aKey+n*8);
|
||||
if(len != 8)
|
||||
{
|
||||
printf("Invalid KEY\n");
|
||||
err=1;
|
||||
break;
|
||||
}
|
||||
ibuf[4]='\0';
|
||||
PrintValue(ibuf,aKey,len);
|
||||
if(n == 2)
|
||||
++step;
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Missing KEY\n");
|
||||
err = 1;
|
||||
}
|
||||
break;
|
||||
|
||||
case 3: /* IV = xxxx */
|
||||
fputs(ibuf, rfp);
|
||||
if (strncasecmp(ibuf, "IV = ", 5) != 0)
|
||||
{
|
||||
printf("Missing IV\n");
|
||||
err = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
len = hex2bin((char*)ibuf+5, iVec);
|
||||
if (len < 0)
|
||||
{
|
||||
printf("Invalid IV\n");
|
||||
err =1;
|
||||
break;
|
||||
}
|
||||
PrintValue("IV", iVec, len);
|
||||
step = (dir)? 4: 5;
|
||||
}
|
||||
break;
|
||||
|
||||
case 4: /* PLAINTEXT = xxxx */
|
||||
fputs(ibuf, rfp);
|
||||
if (strncasecmp(ibuf, "PLAINTEXT = ", 12) != 0)
|
||||
{
|
||||
printf("Missing PLAINTEXT\n");
|
||||
err = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
int nn = strlen(ibuf+12);
|
||||
if(!strcmp(amode,"CFB1"))
|
||||
len=bint2bin(ibuf+12,nn-1,plaintext);
|
||||
else
|
||||
len=hex2bin(ibuf+12, plaintext);
|
||||
if (len < 0)
|
||||
{
|
||||
printf("Invalid PLAINTEXT: %s", ibuf+12);
|
||||
err =1;
|
||||
break;
|
||||
}
|
||||
if (len >= (int)sizeof(plaintext))
|
||||
{
|
||||
printf("Buffer overflow\n");
|
||||
}
|
||||
PrintValue("PLAINTEXT", (unsigned char*)plaintext, len);
|
||||
if (strcmp(atest, "Monte") == 0) /* Monte Carlo Test */
|
||||
{
|
||||
do_mct(amode,akeysz,numkeys,aKey,iVec,dir,plaintext,len,rfp);
|
||||
}
|
||||
else
|
||||
{
|
||||
assert(dir == 1);
|
||||
ret = DESTest(&ctx, amode, akeysz, aKey, iVec,
|
||||
dir, /* 0 = decrypt, 1 = encrypt */
|
||||
ciphertext, plaintext, len);
|
||||
OutputValue("CIPHERTEXT",ciphertext,len,rfp,
|
||||
!strcmp(amode,"CFB1"));
|
||||
}
|
||||
step = 6;
|
||||
}
|
||||
break;
|
||||
|
||||
case 5: /* CIPHERTEXT = xxxx */
|
||||
fputs(ibuf, rfp);
|
||||
if (strncasecmp(ibuf, "CIPHERTEXT = ", 13) != 0)
|
||||
{
|
||||
printf("Missing KEY\n");
|
||||
err = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!strcmp(amode,"CFB1"))
|
||||
len=bint2bin(ibuf+13,strlen(ibuf+13)-1,ciphertext);
|
||||
else
|
||||
len = hex2bin(ibuf+13,ciphertext);
|
||||
if (len < 0)
|
||||
{
|
||||
printf("Invalid CIPHERTEXT\n");
|
||||
err =1;
|
||||
break;
|
||||
}
|
||||
|
||||
PrintValue("CIPHERTEXT", ciphertext, len);
|
||||
if (strcmp(atest, "Monte") == 0) /* Monte Carlo Test */
|
||||
{
|
||||
do_mct(amode, akeysz, numkeys, aKey, iVec,
|
||||
dir, ciphertext, len, rfp);
|
||||
}
|
||||
else
|
||||
{
|
||||
assert(dir == 0);
|
||||
ret = DESTest(&ctx, amode, akeysz, aKey, iVec,
|
||||
dir, /* 0 = decrypt, 1 = encrypt */
|
||||
plaintext, ciphertext, len);
|
||||
OutputValue("PLAINTEXT",(unsigned char *)plaintext,len,rfp,
|
||||
!strcmp(amode,"CFB1"));
|
||||
}
|
||||
step = 6;
|
||||
}
|
||||
break;
|
||||
|
||||
case 6:
|
||||
if (ibuf[0] != '\n')
|
||||
{
|
||||
err = 1;
|
||||
printf("Missing terminator\n");
|
||||
}
|
||||
else if (strcmp(atest, "MCT") != 0)
|
||||
{ /* MCT already added terminating nl */
|
||||
fputs(ibuf, rfp);
|
||||
}
|
||||
step = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (rfp)
|
||||
fclose(rfp);
|
||||
if (afp)
|
||||
fclose(afp);
|
||||
return err;
|
||||
}
|
||||
|
||||
/*--------------------------------------------------
|
||||
Processes either a single file or
|
||||
a set of files whose names are passed in a file.
|
||||
A single file is specified as:
|
||||
aes_test -f xxx.req
|
||||
A set of files is specified as:
|
||||
aes_test -d xxxxx.xxx
|
||||
The default is: -d req.txt
|
||||
--------------------------------------------------*/
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
char *rqlist = "req.txt", *rspfile = NULL;
|
||||
FILE *fp = NULL;
|
||||
char fn[250] = "", rfn[256] = "";
|
||||
int f_opt = 0, d_opt = 1;
|
||||
|
||||
#ifdef OPENSSL_FIPS
|
||||
if(!FIPS_mode_set(1))
|
||||
{
|
||||
do_print_errors();
|
||||
EXIT(1);
|
||||
}
|
||||
#endif
|
||||
if (argc > 1)
|
||||
{
|
||||
if (strcasecmp(argv[1], "-d") == 0)
|
||||
{
|
||||
d_opt = 1;
|
||||
}
|
||||
else if (strcasecmp(argv[1], "-f") == 0)
|
||||
{
|
||||
f_opt = 1;
|
||||
d_opt = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Invalid parameter: %s\n", argv[1]);
|
||||
return 0;
|
||||
}
|
||||
if (argc < 3)
|
||||
{
|
||||
printf("Missing parameter\n");
|
||||
return 0;
|
||||
}
|
||||
if (d_opt)
|
||||
rqlist = argv[2];
|
||||
else
|
||||
{
|
||||
strcpy(fn, argv[2]);
|
||||
rspfile = argv[3];
|
||||
}
|
||||
}
|
||||
if (d_opt)
|
||||
{ /* list of files (directory) */
|
||||
if (!(fp = fopen(rqlist, "r")))
|
||||
{
|
||||
printf("Cannot open req list file\n");
|
||||
return -1;
|
||||
}
|
||||
while (fgets(fn, sizeof(fn), fp))
|
||||
{
|
||||
strtok(fn, "\r\n");
|
||||
strcpy(rfn, fn);
|
||||
printf("Processing: %s\n", rfn);
|
||||
if (proc_file(rfn, rspfile))
|
||||
{
|
||||
printf(">>> Processing failed for: %s <<<\n", rfn);
|
||||
EXIT(1);
|
||||
}
|
||||
}
|
||||
fclose(fp);
|
||||
}
|
||||
else /* single file */
|
||||
{
|
||||
if (VERBOSE)
|
||||
printf("Processing: %s\n", fn);
|
||||
if (proc_file(fn, rspfile))
|
||||
{
|
||||
printf(">>> Processing failed for: %s <<<\n", fn);
|
||||
}
|
||||
}
|
||||
EXIT(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -1,115 +0,0 @@
|
|||
#
|
||||
# OpenSSL/fips/dh/Makefile
|
||||
#
|
||||
|
||||
DIR= dh
|
||||
TOP= ../..
|
||||
CC= cc
|
||||
INCLUDES=
|
||||
CFLAG=-g
|
||||
INSTALL_PREFIX=
|
||||
OPENSSLDIR= /usr/local/ssl
|
||||
INSTALLTOP=/usr/local/ssl
|
||||
MAKEDEPPROG= makedepend
|
||||
MAKEDEPEND= $(TOP)/util/domd $(TOP) -MD $(MAKEDEPPROG)
|
||||
MAKEFILE= Makefile
|
||||
AR= ar r
|
||||
|
||||
CFLAGS= $(INCLUDES) $(CFLAG)
|
||||
|
||||
GENERAL=Makefile
|
||||
TEST=
|
||||
APPS=
|
||||
|
||||
LIB=$(TOP)/libcrypto.a
|
||||
LIBSRC=fips_dh_check.c fips_dh_gen.c fips_dh_key.c fips_dh_lib.c
|
||||
LIBOBJ=fips_dh_check.o fips_dh_gen.o fips_dh_key.o fips_dh_lib.o
|
||||
|
||||
SRC= $(LIBSRC)
|
||||
|
||||
EXHEADER=
|
||||
HEADER= $(EXHEADER)
|
||||
|
||||
ALL= $(GENERAL) $(SRC) $(HEADER)
|
||||
|
||||
top:
|
||||
(cd $(TOP); $(MAKE) DIRS=fips FDIRS=$(DIR) sub_all)
|
||||
|
||||
all: lib
|
||||
|
||||
lib: $(LIBOBJ)
|
||||
@echo $(LIBOBJ) > lib
|
||||
|
||||
files:
|
||||
$(PERL) $(TOP)/util/files.pl Makefile >> $(TOP)/MINFO
|
||||
|
||||
links:
|
||||
@$(PERL) $(TOP)/util/mklink.pl $(TOP)/include/openssl $(EXHEADER)
|
||||
@$(PERL) $(TOP)/util/mklink.pl $(TOP)/test $(TEST)
|
||||
@$(PERL) $(TOP)/util/mklink.pl $(TOP)/apps $(APPS)
|
||||
|
||||
install:
|
||||
@headerlist="$(EXHEADER)"; for i in $$headerlist; \
|
||||
do \
|
||||
(cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
|
||||
chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
|
||||
done
|
||||
|
||||
tags:
|
||||
ctags $(SRC)
|
||||
|
||||
tests:
|
||||
|
||||
fips_test:
|
||||
|
||||
lint:
|
||||
lint -DLINT $(INCLUDES) $(SRC)>fluff
|
||||
|
||||
depend:
|
||||
$(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(SRC) $(TEST)
|
||||
|
||||
dclean:
|
||||
$(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
|
||||
mv -f Makefile.new $(MAKEFILE)
|
||||
|
||||
clean:
|
||||
rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
|
||||
|
||||
# DO NOT DELETE THIS LINE -- make depend depends on it.
|
||||
|
||||
fips_dh_check.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
|
||||
fips_dh_check.o: ../../include/openssl/crypto.h ../../include/openssl/dh.h
|
||||
fips_dh_check.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
|
||||
fips_dh_check.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
|
||||
fips_dh_check.o: ../../include/openssl/opensslconf.h
|
||||
fips_dh_check.o: ../../include/openssl/opensslv.h
|
||||
fips_dh_check.o: ../../include/openssl/ossl_typ.h
|
||||
fips_dh_check.o: ../../include/openssl/safestack.h
|
||||
fips_dh_check.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
|
||||
fips_dh_check.o: fips_dh_check.c
|
||||
fips_dh_gen.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
|
||||
fips_dh_gen.o: ../../include/openssl/crypto.h ../../include/openssl/dh.h
|
||||
fips_dh_gen.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
|
||||
fips_dh_gen.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
|
||||
fips_dh_gen.o: ../../include/openssl/opensslconf.h
|
||||
fips_dh_gen.o: ../../include/openssl/opensslv.h
|
||||
fips_dh_gen.o: ../../include/openssl/ossl_typ.h
|
||||
fips_dh_gen.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
|
||||
fips_dh_gen.o: ../../include/openssl/symhacks.h fips_dh_gen.c
|
||||
fips_dh_key.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
|
||||
fips_dh_key.o: ../../include/openssl/crypto.h ../../include/openssl/dh.h
|
||||
fips_dh_key.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
|
||||
fips_dh_key.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
|
||||
fips_dh_key.o: ../../include/openssl/opensslconf.h
|
||||
fips_dh_key.o: ../../include/openssl/opensslv.h
|
||||
fips_dh_key.o: ../../include/openssl/ossl_typ.h ../../include/openssl/rand.h
|
||||
fips_dh_key.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
|
||||
fips_dh_key.o: ../../include/openssl/symhacks.h fips_dh_key.c
|
||||
fips_dh_lib.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
|
||||
fips_dh_lib.o: ../../include/openssl/crypto.h ../../include/openssl/dh.h
|
||||
fips_dh_lib.o: ../../include/openssl/e_os2.h
|
||||
fips_dh_lib.o: ../../include/openssl/opensslconf.h
|
||||
fips_dh_lib.o: ../../include/openssl/opensslv.h
|
||||
fips_dh_lib.o: ../../include/openssl/ossl_typ.h
|
||||
fips_dh_lib.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
|
||||
fips_dh_lib.o: ../../include/openssl/symhacks.h fips_dh_lib.c
|
||||
|
|
@ -1,179 +0,0 @@
|
|||
/* crypto/dh/dh_gen.c */
|
||||
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
|
||||
* All rights reserved.
|
||||
*
|
||||
* This package is an SSL implementation written
|
||||
* by Eric Young (eay@cryptsoft.com).
|
||||
* The implementation was written so as to conform with Netscapes SSL.
|
||||
*
|
||||
* This library is free for commercial and non-commercial use as long as
|
||||
* the following conditions are aheared to. The following conditions
|
||||
* apply to all code found in this distribution, be it the RC4, RSA,
|
||||
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
|
||||
* included with this distribution is covered by the same copyright terms
|
||||
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
* Copyright remains Eric Young's, and as such any Copyright notices in
|
||||
* the code are not to be removed.
|
||||
* If this package is used in a product, Eric Young should be given attribution
|
||||
* as the author of the parts of the library used.
|
||||
* This can be in the form of a textual message at program startup or
|
||||
* in documentation (online or textual) provided with the package.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* "This product includes cryptographic software written by
|
||||
* Eric Young (eay@cryptsoft.com)"
|
||||
* The word 'cryptographic' can be left out if the rouines from the library
|
||||
* being used are not cryptographic related :-).
|
||||
* 4. If you include any Windows specific code (or a derivative thereof) from
|
||||
* the apps directory (application code) you must include an acknowledgement:
|
||||
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* The licence and distribution terms for any publically available version or
|
||||
* derivative of this code cannot be changed. i.e. this code cannot simply be
|
||||
* copied and put under another distribution licence
|
||||
* [including the GNU Public Licence.]
|
||||
*/
|
||||
|
||||
/* NB: These functions have been upgraded - the previous prototypes are in
|
||||
* dh_depr.c as wrappers to these ones.
|
||||
* - Geoff
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "cryptlib.h"
|
||||
#include <openssl/bn.h>
|
||||
#include <openssl/dh.h>
|
||||
|
||||
#ifndef OPENSSL_FIPS
|
||||
|
||||
static int dh_builtin_genparams(DH *ret, int prime_len, int generator, BN_GENCB *cb);
|
||||
|
||||
int DH_generate_parameters_ex(DH *ret, int prime_len, int generator, BN_GENCB *cb)
|
||||
{
|
||||
if(ret->meth->generate_params)
|
||||
return ret->meth->generate_params(ret, prime_len, generator, cb);
|
||||
return dh_builtin_genparams(ret, prime_len, generator, cb);
|
||||
}
|
||||
|
||||
/* We generate DH parameters as follows
|
||||
* find a prime q which is prime_len/2 bits long.
|
||||
* p=(2*q)+1 or (p-1)/2 = q
|
||||
* For this case, g is a generator if
|
||||
* g^((p-1)/q) mod p != 1 for values of q which are the factors of p-1.
|
||||
* Since the factors of p-1 are q and 2, we just need to check
|
||||
* g^2 mod p != 1 and g^q mod p != 1.
|
||||
*
|
||||
* Having said all that,
|
||||
* there is another special case method for the generators 2, 3 and 5.
|
||||
* for 2, p mod 24 == 11
|
||||
* for 3, p mod 12 == 5 <<<<< does not work for safe primes.
|
||||
* for 5, p mod 10 == 3 or 7
|
||||
*
|
||||
* Thanks to Phil Karn <karn@qualcomm.com> for the pointers about the
|
||||
* special generators and for answering some of my questions.
|
||||
*
|
||||
* I've implemented the second simple method :-).
|
||||
* Since DH should be using a safe prime (both p and q are prime),
|
||||
* this generator function can take a very very long time to run.
|
||||
*/
|
||||
/* Actually there is no reason to insist that 'generator' be a generator.
|
||||
* It's just as OK (and in some sense better) to use a generator of the
|
||||
* order-q subgroup.
|
||||
*/
|
||||
static int dh_builtin_genparams(DH *ret, int prime_len, int generator, BN_GENCB *cb)
|
||||
{
|
||||
BIGNUM *t1,*t2;
|
||||
int g,ok= -1;
|
||||
BN_CTX *ctx=NULL;
|
||||
|
||||
ctx=BN_CTX_new();
|
||||
if (ctx == NULL) goto err;
|
||||
BN_CTX_start(ctx);
|
||||
t1 = BN_CTX_get(ctx);
|
||||
t2 = BN_CTX_get(ctx);
|
||||
if (t1 == NULL || t2 == NULL) goto err;
|
||||
|
||||
/* Make sure 'ret' has the necessary elements */
|
||||
if(!ret->p && ((ret->p = BN_new()) == NULL)) goto err;
|
||||
if(!ret->g && ((ret->g = BN_new()) == NULL)) goto err;
|
||||
|
||||
if (generator <= 1)
|
||||
{
|
||||
DHerr(DH_F_DH_BUILTIN_GENPARAMS, DH_R_BAD_GENERATOR);
|
||||
goto err;
|
||||
}
|
||||
if (generator == DH_GENERATOR_2)
|
||||
{
|
||||
if (!BN_set_word(t1,24)) goto err;
|
||||
if (!BN_set_word(t2,11)) goto err;
|
||||
g=2;
|
||||
}
|
||||
#if 0 /* does not work for safe primes */
|
||||
else if (generator == DH_GENERATOR_3)
|
||||
{
|
||||
if (!BN_set_word(t1,12)) goto err;
|
||||
if (!BN_set_word(t2,5)) goto err;
|
||||
g=3;
|
||||
}
|
||||
#endif
|
||||
else if (generator == DH_GENERATOR_5)
|
||||
{
|
||||
if (!BN_set_word(t1,10)) goto err;
|
||||
if (!BN_set_word(t2,3)) goto err;
|
||||
/* BN_set_word(t3,7); just have to miss
|
||||
* out on these ones :-( */
|
||||
g=5;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* in the general case, don't worry if 'generator' is a
|
||||
* generator or not: since we are using safe primes,
|
||||
* it will generate either an order-q or an order-2q group,
|
||||
* which both is OK */
|
||||
if (!BN_set_word(t1,2)) goto err;
|
||||
if (!BN_set_word(t2,1)) goto err;
|
||||
g=generator;
|
||||
}
|
||||
|
||||
if(!BN_generate_prime_ex(ret->p,prime_len,1,t1,t2,cb)) goto err;
|
||||
if(!BN_GENCB_call(cb, 3, 0)) goto err;
|
||||
if (!BN_set_word(ret->g,g)) goto err;
|
||||
ok=1;
|
||||
err:
|
||||
if (ok == -1)
|
||||
{
|
||||
DHerr(DH_F_DH_BUILTIN_GENPARAMS,ERR_R_BN_LIB);
|
||||
ok=0;
|
||||
}
|
||||
|
||||
if (ctx != NULL)
|
||||
{
|
||||
BN_CTX_end(ctx);
|
||||
BN_CTX_free(ctx);
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -1,147 +0,0 @@
|
|||
/* crypto/dh/dh_check.c */
|
||||
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
|
||||
* All rights reserved.
|
||||
*
|
||||
* This package is an SSL implementation written
|
||||
* by Eric Young (eay@cryptsoft.com).
|
||||
* The implementation was written so as to conform with Netscapes SSL.
|
||||
*
|
||||
* This library is free for commercial and non-commercial use as long as
|
||||
* the following conditions are aheared to. The following conditions
|
||||
* apply to all code found in this distribution, be it the RC4, RSA,
|
||||
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
|
||||
* included with this distribution is covered by the same copyright terms
|
||||
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
* Copyright remains Eric Young's, and as such any Copyright notices in
|
||||
* the code are not to be removed.
|
||||
* If this package is used in a product, Eric Young should be given attribution
|
||||
* as the author of the parts of the library used.
|
||||
* This can be in the form of a textual message at program startup or
|
||||
* in documentation (online or textual) provided with the package.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* "This product includes cryptographic software written by
|
||||
* Eric Young (eay@cryptsoft.com)"
|
||||
* The word 'cryptographic' can be left out if the rouines from the library
|
||||
* being used are not cryptographic related :-).
|
||||
* 4. If you include any Windows specific code (or a derivative thereof) from
|
||||
* the apps directory (application code) you must include an acknowledgement:
|
||||
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* The licence and distribution terms for any publically available version or
|
||||
* derivative of this code cannot be changed. i.e. this code cannot simply be
|
||||
* copied and put under another distribution licence
|
||||
* [including the GNU Public Licence.]
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <openssl/bn.h>
|
||||
#include <openssl/dh.h>
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/fips.h>
|
||||
|
||||
/* Check that p is a safe prime and
|
||||
* if g is 2, 3 or 5, check that is is a suitable generator
|
||||
* where
|
||||
* for 2, p mod 24 == 11
|
||||
* for 3, p mod 12 == 5
|
||||
* for 5, p mod 10 == 3 or 7
|
||||
* should hold.
|
||||
*/
|
||||
|
||||
#ifdef OPENSSL_FIPS
|
||||
|
||||
int DH_check(const DH *dh, int *ret)
|
||||
{
|
||||
int ok=0;
|
||||
BN_CTX *ctx=NULL;
|
||||
BN_ULONG l;
|
||||
BIGNUM *q=NULL;
|
||||
|
||||
*ret=0;
|
||||
ctx=BN_CTX_new();
|
||||
if (ctx == NULL) goto err;
|
||||
q=BN_new();
|
||||
if (q == NULL) goto err;
|
||||
|
||||
if (BN_is_word(dh->g,DH_GENERATOR_2))
|
||||
{
|
||||
l=BN_mod_word(dh->p,24);
|
||||
if (l != 11) *ret|=DH_NOT_SUITABLE_GENERATOR;
|
||||
}
|
||||
#if 0
|
||||
else if (BN_is_word(dh->g,DH_GENERATOR_3))
|
||||
{
|
||||
l=BN_mod_word(dh->p,12);
|
||||
if (l != 5) *ret|=DH_NOT_SUITABLE_GENERATOR;
|
||||
}
|
||||
#endif
|
||||
else if (BN_is_word(dh->g,DH_GENERATOR_5))
|
||||
{
|
||||
l=BN_mod_word(dh->p,10);
|
||||
if ((l != 3) && (l != 7))
|
||||
*ret|=DH_NOT_SUITABLE_GENERATOR;
|
||||
}
|
||||
else
|
||||
*ret|=DH_UNABLE_TO_CHECK_GENERATOR;
|
||||
|
||||
if (!BN_is_prime_ex(dh->p,BN_prime_checks,ctx,NULL))
|
||||
*ret|=DH_CHECK_P_NOT_PRIME;
|
||||
else
|
||||
{
|
||||
if (!BN_rshift1(q,dh->p)) goto err;
|
||||
if (!BN_is_prime_ex(q,BN_prime_checks,ctx,NULL))
|
||||
*ret|=DH_CHECK_P_NOT_SAFE_PRIME;
|
||||
}
|
||||
ok=1;
|
||||
err:
|
||||
if (ctx != NULL) BN_CTX_free(ctx);
|
||||
if (q != NULL) BN_free(q);
|
||||
return(ok);
|
||||
}
|
||||
|
||||
int DH_check_pub_key(const DH *dh, const BIGNUM *pub_key, int *ret)
|
||||
{
|
||||
int ok=0;
|
||||
BIGNUM *q=NULL;
|
||||
|
||||
*ret=0;
|
||||
q=BN_new();
|
||||
if (q == NULL) goto err;
|
||||
BN_set_word(q,1);
|
||||
if (BN_cmp(pub_key,q) <= 0)
|
||||
*ret|=DH_CHECK_PUBKEY_TOO_SMALL;
|
||||
BN_copy(q,dh->p);
|
||||
BN_sub_word(q,1);
|
||||
if (BN_cmp(pub_key,q) >= 0)
|
||||
*ret|=DH_CHECK_PUBKEY_TOO_LARGE;
|
||||
|
||||
ok = 1;
|
||||
err:
|
||||
if (q != NULL) BN_free(q);
|
||||
return(ok);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -1,192 +0,0 @@
|
|||
/* crypto/dh/dh_gen.c */
|
||||
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
|
||||
* All rights reserved.
|
||||
*
|
||||
* This package is an SSL implementation written
|
||||
* by Eric Young (eay@cryptsoft.com).
|
||||
* The implementation was written so as to conform with Netscapes SSL.
|
||||
*
|
||||
* This library is free for commercial and non-commercial use as long as
|
||||
* the following conditions are aheared to. The following conditions
|
||||
* apply to all code found in this distribution, be it the RC4, RSA,
|
||||
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
|
||||
* included with this distribution is covered by the same copyright terms
|
||||
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
* Copyright remains Eric Young's, and as such any Copyright notices in
|
||||
* the code are not to be removed.
|
||||
* If this package is used in a product, Eric Young should be given attribution
|
||||
* as the author of the parts of the library used.
|
||||
* This can be in the form of a textual message at program startup or
|
||||
* in documentation (online or textual) provided with the package.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* "This product includes cryptographic software written by
|
||||
* Eric Young (eay@cryptsoft.com)"
|
||||
* The word 'cryptographic' can be left out if the rouines from the library
|
||||
* being used are not cryptographic related :-).
|
||||
* 4. If you include any Windows specific code (or a derivative thereof) from
|
||||
* the apps directory (application code) you must include an acknowledgement:
|
||||
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* The licence and distribution terms for any publically available version or
|
||||
* derivative of this code cannot be changed. i.e. this code cannot simply be
|
||||
* copied and put under another distribution licence
|
||||
* [including the GNU Public Licence.]
|
||||
*/
|
||||
|
||||
/* NB: These functions have been upgraded - the previous prototypes are in
|
||||
* dh_depr.c as wrappers to these ones.
|
||||
* - Geoff
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <openssl/bn.h>
|
||||
#include <openssl/dh.h>
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/fips.h>
|
||||
|
||||
#ifdef OPENSSL_FIPS
|
||||
|
||||
static int dh_builtin_genparams(DH *ret, int prime_len, int generator, BN_GENCB *cb);
|
||||
|
||||
int DH_generate_parameters_ex(DH *ret, int prime_len, int generator, BN_GENCB *cb)
|
||||
{
|
||||
if(ret->meth->generate_params)
|
||||
return ret->meth->generate_params(ret, prime_len, generator, cb);
|
||||
return dh_builtin_genparams(ret, prime_len, generator, cb);
|
||||
}
|
||||
|
||||
/* We generate DH parameters as follows
|
||||
* find a prime q which is prime_len/2 bits long.
|
||||
* p=(2*q)+1 or (p-1)/2 = q
|
||||
* For this case, g is a generator if
|
||||
* g^((p-1)/q) mod p != 1 for values of q which are the factors of p-1.
|
||||
* Since the factors of p-1 are q and 2, we just need to check
|
||||
* g^2 mod p != 1 and g^q mod p != 1.
|
||||
*
|
||||
* Having said all that,
|
||||
* there is another special case method for the generators 2, 3 and 5.
|
||||
* for 2, p mod 24 == 11
|
||||
* for 3, p mod 12 == 5 <<<<< does not work for safe primes.
|
||||
* for 5, p mod 10 == 3 or 7
|
||||
*
|
||||
* Thanks to Phil Karn <karn@qualcomm.com> for the pointers about the
|
||||
* special generators and for answering some of my questions.
|
||||
*
|
||||
* I've implemented the second simple method :-).
|
||||
* Since DH should be using a safe prime (both p and q are prime),
|
||||
* this generator function can take a very very long time to run.
|
||||
*/
|
||||
/* Actually there is no reason to insist that 'generator' be a generator.
|
||||
* It's just as OK (and in some sense better) to use a generator of the
|
||||
* order-q subgroup.
|
||||
*/
|
||||
static int dh_builtin_genparams(DH *ret, int prime_len, int generator, BN_GENCB *cb)
|
||||
{
|
||||
BIGNUM *t1,*t2;
|
||||
int g,ok= -1;
|
||||
BN_CTX *ctx=NULL;
|
||||
|
||||
if(FIPS_selftest_failed())
|
||||
{
|
||||
FIPSerr(FIPS_F_DH_BUILTIN_GENPARAMS,FIPS_R_FIPS_SELFTEST_FAILED);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (FIPS_mode() && (prime_len < OPENSSL_DH_FIPS_MIN_MODULUS_BITS))
|
||||
{
|
||||
DHerr(DH_F_DH_BUILTIN_GENPARAMS, DH_R_KEY_SIZE_TOO_SMALL);
|
||||
goto err;
|
||||
}
|
||||
|
||||
ctx=BN_CTX_new();
|
||||
if (ctx == NULL) goto err;
|
||||
BN_CTX_start(ctx);
|
||||
t1 = BN_CTX_get(ctx);
|
||||
t2 = BN_CTX_get(ctx);
|
||||
if (t1 == NULL || t2 == NULL) goto err;
|
||||
|
||||
/* Make sure 'ret' has the necessary elements */
|
||||
if(!ret->p && ((ret->p = BN_new()) == NULL)) goto err;
|
||||
if(!ret->g && ((ret->g = BN_new()) == NULL)) goto err;
|
||||
|
||||
if (generator <= 1)
|
||||
{
|
||||
DHerr(DH_F_DH_BUILTIN_GENPARAMS, DH_R_BAD_GENERATOR);
|
||||
goto err;
|
||||
}
|
||||
if (generator == DH_GENERATOR_2)
|
||||
{
|
||||
if (!BN_set_word(t1,24)) goto err;
|
||||
if (!BN_set_word(t2,11)) goto err;
|
||||
g=2;
|
||||
}
|
||||
#if 0 /* does not work for safe primes */
|
||||
else if (generator == DH_GENERATOR_3)
|
||||
{
|
||||
if (!BN_set_word(t1,12)) goto err;
|
||||
if (!BN_set_word(t2,5)) goto err;
|
||||
g=3;
|
||||
}
|
||||
#endif
|
||||
else if (generator == DH_GENERATOR_5)
|
||||
{
|
||||
if (!BN_set_word(t1,10)) goto err;
|
||||
if (!BN_set_word(t2,3)) goto err;
|
||||
/* BN_set_word(t3,7); just have to miss
|
||||
* out on these ones :-( */
|
||||
g=5;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* in the general case, don't worry if 'generator' is a
|
||||
* generator or not: since we are using safe primes,
|
||||
* it will generate either an order-q or an order-2q group,
|
||||
* which both is OK */
|
||||
if (!BN_set_word(t1,2)) goto err;
|
||||
if (!BN_set_word(t2,1)) goto err;
|
||||
g=generator;
|
||||
}
|
||||
|
||||
if(!BN_generate_prime_ex(ret->p,prime_len,1,t1,t2,cb)) goto err;
|
||||
if(!BN_GENCB_call(cb, 3, 0)) goto err;
|
||||
if (!BN_set_word(ret->g,g)) goto err;
|
||||
ok=1;
|
||||
err:
|
||||
if (ok == -1)
|
||||
{
|
||||
DHerr(DH_F_DH_BUILTIN_GENPARAMS,ERR_R_BN_LIB);
|
||||
ok=0;
|
||||
}
|
||||
|
||||
if (ctx != NULL)
|
||||
{
|
||||
BN_CTX_end(ctx);
|
||||
BN_CTX_free(ctx);
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -1,276 +0,0 @@
|
|||
/* crypto/dh/dh_key.c */
|
||||
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
|
||||
* All rights reserved.
|
||||
*
|
||||
* This package is an SSL implementation written
|
||||
* by Eric Young (eay@cryptsoft.com).
|
||||
* The implementation was written so as to conform with Netscapes SSL.
|
||||
*
|
||||
* This library is free for commercial and non-commercial use as long as
|
||||
* the following conditions are aheared to. The following conditions
|
||||
* apply to all code found in this distribution, be it the RC4, RSA,
|
||||
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
|
||||
* included with this distribution is covered by the same copyright terms
|
||||
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
* Copyright remains Eric Young's, and as such any Copyright notices in
|
||||
* the code are not to be removed.
|
||||
* If this package is used in a product, Eric Young should be given attribution
|
||||
* as the author of the parts of the library used.
|
||||
* This can be in the form of a textual message at program startup or
|
||||
* in documentation (online or textual) provided with the package.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* "This product includes cryptographic software written by
|
||||
* Eric Young (eay@cryptsoft.com)"
|
||||
* The word 'cryptographic' can be left out if the rouines from the library
|
||||
* being used are not cryptographic related :-).
|
||||
* 4. If you include any Windows specific code (or a derivative thereof) from
|
||||
* the apps directory (application code) you must include an acknowledgement:
|
||||
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* The licence and distribution terms for any publically available version or
|
||||
* derivative of this code cannot be changed. i.e. this code cannot simply be
|
||||
* copied and put under another distribution licence
|
||||
* [including the GNU Public Licence.]
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/bn.h>
|
||||
#ifndef OPENSSL_NO_RAND
|
||||
#include <openssl/rand.h>
|
||||
#endif
|
||||
#ifndef OPENSSL_NO_DH
|
||||
#include <openssl/dh.h>
|
||||
#include <openssl/fips.h>
|
||||
|
||||
#ifdef OPENSSL_FIPS
|
||||
|
||||
static int generate_key(DH *dh);
|
||||
static int compute_key(unsigned char *key, const BIGNUM *pub_key, DH *dh);
|
||||
static int dh_bn_mod_exp(const DH *dh, BIGNUM *r,
|
||||
const BIGNUM *a, const BIGNUM *p,
|
||||
const BIGNUM *m, BN_CTX *ctx,
|
||||
BN_MONT_CTX *m_ctx);
|
||||
static int dh_init(DH *dh);
|
||||
static int dh_finish(DH *dh);
|
||||
|
||||
int DH_generate_key(DH *dh)
|
||||
{
|
||||
return dh->meth->generate_key(dh);
|
||||
}
|
||||
|
||||
int DH_compute_key(unsigned char *key, const BIGNUM *pub_key, DH *dh)
|
||||
{
|
||||
return dh->meth->compute_key(key, pub_key, dh);
|
||||
}
|
||||
|
||||
static const DH_METHOD dh_ossl = {
|
||||
"OpenSSL DH Method",
|
||||
generate_key,
|
||||
compute_key,
|
||||
dh_bn_mod_exp,
|
||||
dh_init,
|
||||
dh_finish,
|
||||
0,
|
||||
NULL
|
||||
};
|
||||
|
||||
const DH_METHOD *DH_OpenSSL(void)
|
||||
{
|
||||
return &dh_ossl;
|
||||
}
|
||||
|
||||
static int generate_key(DH *dh)
|
||||
{
|
||||
int ok=0;
|
||||
int generate_new_key=0;
|
||||
unsigned l;
|
||||
BN_CTX *ctx;
|
||||
BN_MONT_CTX *mont=NULL;
|
||||
BIGNUM *pub_key=NULL,*priv_key=NULL;
|
||||
|
||||
if (FIPS_mode() && (BN_num_bits(dh->p) < OPENSSL_DH_FIPS_MIN_MODULUS_BITS))
|
||||
{
|
||||
DHerr(DH_F_GENERATE_KEY, DH_R_KEY_SIZE_TOO_SMALL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
ctx = BN_CTX_new();
|
||||
if (ctx == NULL) goto err;
|
||||
|
||||
if (dh->priv_key == NULL)
|
||||
{
|
||||
priv_key=BN_new();
|
||||
if (priv_key == NULL) goto err;
|
||||
generate_new_key=1;
|
||||
}
|
||||
else
|
||||
priv_key=dh->priv_key;
|
||||
|
||||
if (dh->pub_key == NULL)
|
||||
{
|
||||
pub_key=BN_new();
|
||||
if (pub_key == NULL) goto err;
|
||||
}
|
||||
else
|
||||
pub_key=dh->pub_key;
|
||||
|
||||
if (dh->flags & DH_FLAG_CACHE_MONT_P)
|
||||
{
|
||||
mont = BN_MONT_CTX_set_locked(
|
||||
(BN_MONT_CTX **)&dh->method_mont_p,
|
||||
CRYPTO_LOCK_DH, dh->p, ctx);
|
||||
if (!mont)
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (generate_new_key)
|
||||
{
|
||||
l = dh->length ? dh->length : BN_num_bits(dh->p)-1; /* secret exponent length */
|
||||
if (!BN_rand(priv_key, l, 0, 0)) goto err;
|
||||
}
|
||||
|
||||
{
|
||||
BIGNUM local_prk;
|
||||
BIGNUM *prk;
|
||||
|
||||
if ((dh->flags & DH_FLAG_NO_EXP_CONSTTIME) == 0)
|
||||
{
|
||||
BN_init(&local_prk);
|
||||
prk = &local_prk;
|
||||
BN_with_flags(prk, priv_key, BN_FLG_CONSTTIME);
|
||||
}
|
||||
else
|
||||
prk = priv_key;
|
||||
|
||||
if (!dh->meth->bn_mod_exp(dh, pub_key, dh->g, prk, dh->p, ctx, mont))
|
||||
goto err;
|
||||
}
|
||||
|
||||
dh->pub_key=pub_key;
|
||||
dh->priv_key=priv_key;
|
||||
ok=1;
|
||||
err:
|
||||
if (ok != 1)
|
||||
DHerr(DH_F_GENERATE_KEY,ERR_R_BN_LIB);
|
||||
|
||||
if ((pub_key != NULL) && (dh->pub_key == NULL)) BN_free(pub_key);
|
||||
if ((priv_key != NULL) && (dh->priv_key == NULL)) BN_free(priv_key);
|
||||
BN_CTX_free(ctx);
|
||||
return(ok);
|
||||
}
|
||||
|
||||
static int compute_key(unsigned char *key, const BIGNUM *pub_key, DH *dh)
|
||||
{
|
||||
BN_CTX *ctx;
|
||||
BN_MONT_CTX *mont=NULL;
|
||||
BIGNUM *tmp;
|
||||
int ret= -1;
|
||||
|
||||
ctx = BN_CTX_new();
|
||||
if (ctx == NULL) goto err;
|
||||
BN_CTX_start(ctx);
|
||||
tmp = BN_CTX_get(ctx);
|
||||
|
||||
if (BN_num_bits(dh->p) > OPENSSL_DH_MAX_MODULUS_BITS)
|
||||
{
|
||||
DHerr(DH_F_COMPUTE_KEY,DH_R_MODULUS_TOO_LARGE);
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (FIPS_mode() && (BN_num_bits(dh->p) < OPENSSL_DH_FIPS_MIN_MODULUS_BITS))
|
||||
{
|
||||
DHerr(DH_F_COMPUTE_KEY, DH_R_KEY_SIZE_TOO_SMALL);
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (dh->priv_key == NULL)
|
||||
{
|
||||
DHerr(DH_F_COMPUTE_KEY,DH_R_NO_PRIVATE_VALUE);
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (dh->flags & DH_FLAG_CACHE_MONT_P)
|
||||
{
|
||||
mont = BN_MONT_CTX_set_locked(
|
||||
(BN_MONT_CTX **)&dh->method_mont_p,
|
||||
CRYPTO_LOCK_DH, dh->p, ctx);
|
||||
if ((dh->flags & DH_FLAG_NO_EXP_CONSTTIME) == 0)
|
||||
{
|
||||
/* XXX */
|
||||
BN_set_flags(dh->priv_key, BN_FLG_CONSTTIME);
|
||||
}
|
||||
if (!mont)
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (!dh->meth->bn_mod_exp(dh, tmp, pub_key, dh->priv_key,dh->p,ctx,mont))
|
||||
{
|
||||
DHerr(DH_F_COMPUTE_KEY,ERR_R_BN_LIB);
|
||||
goto err;
|
||||
}
|
||||
|
||||
ret=BN_bn2bin(tmp,key);
|
||||
err:
|
||||
BN_CTX_end(ctx);
|
||||
BN_CTX_free(ctx);
|
||||
return(ret);
|
||||
}
|
||||
|
||||
static int dh_bn_mod_exp(const DH *dh, BIGNUM *r,
|
||||
const BIGNUM *a, const BIGNUM *p,
|
||||
const BIGNUM *m, BN_CTX *ctx,
|
||||
BN_MONT_CTX *m_ctx)
|
||||
{
|
||||
/* If a is only one word long and constant time is false, use the faster
|
||||
* exponenentiation function.
|
||||
*/
|
||||
if (a->top == 1 && ((dh->flags & DH_FLAG_NO_EXP_CONSTTIME) != 0))
|
||||
{
|
||||
BN_ULONG A = a->d[0];
|
||||
return BN_mod_exp_mont_word(r,A,p,m,ctx,m_ctx);
|
||||
}
|
||||
else
|
||||
return BN_mod_exp_mont(r,a,p,m,ctx,m_ctx);
|
||||
}
|
||||
|
||||
|
||||
static int dh_init(DH *dh)
|
||||
{
|
||||
FIPS_selftest_check();
|
||||
dh->flags |= DH_FLAG_CACHE_MONT_P;
|
||||
return(1);
|
||||
}
|
||||
|
||||
static int dh_finish(DH *dh)
|
||||
{
|
||||
if(dh->method_mont_p)
|
||||
BN_MONT_CTX_free((BN_MONT_CTX *)dh->method_mont_p);
|
||||
return(1);
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
|
@ -1,95 +0,0 @@
|
|||
/* fips_dh_lib.c */
|
||||
/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
|
||||
* project 2007.
|
||||
*/
|
||||
/* ====================================================================
|
||||
* Copyright (c) 2007 The OpenSSL Project. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* 3. All advertising materials mentioning features or use of this
|
||||
* software must display the following acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
|
||||
*
|
||||
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission. For written permission, please contact
|
||||
* licensing@OpenSSL.org.
|
||||
*
|
||||
* 5. Products derived from this software may not be called "OpenSSL"
|
||||
* nor may "OpenSSL" appear in their names without prior written
|
||||
* permission of the OpenSSL Project.
|
||||
*
|
||||
* 6. Redistributions of any form whatsoever must retain the following
|
||||
* acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
|
||||
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
|
||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ====================================================================
|
||||
*
|
||||
* This product includes cryptographic software written by Eric Young
|
||||
* (eay@cryptsoft.com). This product includes software written by Tim
|
||||
* Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <openssl/bn.h>
|
||||
#include <openssl/dh.h>
|
||||
|
||||
/* Minimal FIPS versions of FIPS_dh_new() and FIPS_dh_free(): to
|
||||
* reduce external dependencies.
|
||||
*/
|
||||
|
||||
DH *FIPS_dh_new(void)
|
||||
{
|
||||
DH *ret;
|
||||
ret = OPENSSL_malloc(sizeof(DH));
|
||||
if (!ret)
|
||||
return NULL;
|
||||
memset(ret, 0, sizeof(DH));
|
||||
ret->meth = DH_OpenSSL();
|
||||
if (ret->meth->init)
|
||||
ret->meth->init(ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void FIPS_dh_free(DH *r)
|
||||
{
|
||||
if (!r)
|
||||
return;
|
||||
if (r->meth->finish)
|
||||
r->meth->finish(r);
|
||||
if (r->p != NULL) BN_clear_free(r->p);
|
||||
if (r->g != NULL) BN_clear_free(r->g);
|
||||
if (r->q != NULL) BN_clear_free(r->q);
|
||||
if (r->j != NULL) BN_clear_free(r->j);
|
||||
if (r->seed) OPENSSL_free(r->seed);
|
||||
if (r->counter != NULL) BN_clear_free(r->counter);
|
||||
if (r->pub_key != NULL) BN_clear_free(r->pub_key);
|
||||
if (r->priv_key != NULL) BN_clear_free(r->priv_key);
|
||||
OPENSSL_free(r);
|
||||
}
|
||||
|
|
@ -1,191 +0,0 @@
|
|||
#
|
||||
# OpenSSL/fips/dsa/Makefile
|
||||
#
|
||||
|
||||
DIR= dsa
|
||||
TOP= ../..
|
||||
CC= cc
|
||||
INCLUDES=
|
||||
CFLAG=-g
|
||||
INSTALL_PREFIX=
|
||||
OPENSSLDIR= /usr/local/ssl
|
||||
INSTALLTOP=/usr/local/ssl
|
||||
MAKEDEPPROG= makedepend
|
||||
MAKEDEPEND= $(TOP)/util/domd $(TOP) -MD $(MAKEDEPPROG)
|
||||
MAKEFILE= Makefile
|
||||
AR= ar r
|
||||
|
||||
CFLAGS= $(INCLUDES) $(CFLAG)
|
||||
|
||||
GENERAL=Makefile
|
||||
TEST=fips_dsatest.c fips_dssvs.c
|
||||
APPS=
|
||||
|
||||
LIB=$(TOP)/libcrypto.a
|
||||
LIBSRC=fips_dsa_ossl.c fips_dsa_gen.c fips_dsa_selftest.c fips_dsa_key.c \
|
||||
fips_dsa_lib.c fips_dsa_sign.c
|
||||
LIBOBJ=fips_dsa_ossl.o fips_dsa_gen.o fips_dsa_selftest.o fips_dsa_key.o \
|
||||
fips_dsa_lib.o fips_dsa_sign.o
|
||||
|
||||
SRC= $(LIBSRC)
|
||||
|
||||
EXHEADER=
|
||||
HEADER= $(EXHEADER)
|
||||
|
||||
ALL= $(GENERAL) $(SRC) $(HEADER)
|
||||
|
||||
top:
|
||||
(cd $(TOP); $(MAKE) DIRS=fips FDIRS=$(DIR) sub_all)
|
||||
|
||||
all: lib
|
||||
|
||||
lib: $(LIBOBJ)
|
||||
@echo $(LIBOBJ) > lib
|
||||
|
||||
files:
|
||||
$(PERL) $(TOP)/util/files.pl Makefile >> $(TOP)/MINFO
|
||||
|
||||
links:
|
||||
@$(PERL) $(TOP)/util/mklink.pl $(TOP)/include/openssl $(EXHEADER)
|
||||
@$(PERL) $(TOP)/util/mklink.pl $(TOP)/test $(TEST)
|
||||
@$(PERL) $(TOP)/util/mklink.pl $(TOP)/apps $(APPS)
|
||||
|
||||
install:
|
||||
@headerlist="$(EXHEADER)"; for i in $$headerlist; \
|
||||
do \
|
||||
(cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
|
||||
chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
|
||||
done
|
||||
|
||||
tags:
|
||||
ctags $(SRC)
|
||||
|
||||
tests:
|
||||
|
||||
Q=../testvectors/dsa/req
|
||||
A=../testvectors/dsa/rsp
|
||||
|
||||
fips_test:
|
||||
-rm -rf $A
|
||||
mkdir $A
|
||||
if [ -f $(Q)/PQGGen.req ]; then $(TOP)/util/shlib_wrap.sh $(TOP)/test/fips_dssvs pqg < $(Q)/PQGGen.req > $(A)/PQGGen.rsp; fi
|
||||
if [ -f $(Q)/KeyPair.req ]; then $(TOP)/util/shlib_wrap.sh $(TOP)/test/fips_dssvs keypair < $(Q)/KeyPair.req > $(A)/KeyPair.rsp; fi
|
||||
if [ -f $(Q)/SigGen.req ]; then $(TOP)/util/shlib_wrap.sh $(TOP)/test/fips_dssvs siggen < $(Q)/SigGen.req > $(A)/SigGen.rsp; fi
|
||||
if [ -f $(Q)/SigVer.req ]; then $(TOP)/util/shlib_wrap.sh $(TOP)/test/fips_dssvs sigver < $Q/SigVer.req > $A/SigVer.rsp; fi
|
||||
|
||||
lint:
|
||||
lint -DLINT $(INCLUDES) $(SRC)>fluff
|
||||
|
||||
depend:
|
||||
$(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(SRC) $(TEST)
|
||||
|
||||
dclean:
|
||||
$(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
|
||||
mv -f Makefile.new $(MAKEFILE)
|
||||
|
||||
clean:
|
||||
rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
|
||||
# DO NOT DELETE THIS LINE -- make depend depends on it.
|
||||
|
||||
fips_dsa_gen.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
|
||||
fips_dsa_gen.o: ../../include/openssl/bn.h ../../include/openssl/crypto.h
|
||||
fips_dsa_gen.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
|
||||
fips_dsa_gen.o: ../../include/openssl/err.h ../../include/openssl/evp.h
|
||||
fips_dsa_gen.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
|
||||
fips_dsa_gen.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
|
||||
fips_dsa_gen.o: ../../include/openssl/opensslconf.h
|
||||
fips_dsa_gen.o: ../../include/openssl/opensslv.h
|
||||
fips_dsa_gen.o: ../../include/openssl/ossl_typ.h ../../include/openssl/rand.h
|
||||
fips_dsa_gen.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
|
||||
fips_dsa_gen.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
|
||||
fips_dsa_gen.o: fips_dsa_gen.c
|
||||
fips_dsa_key.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
|
||||
fips_dsa_key.o: ../../include/openssl/bn.h ../../include/openssl/crypto.h
|
||||
fips_dsa_key.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
|
||||
fips_dsa_key.o: ../../include/openssl/err.h ../../include/openssl/evp.h
|
||||
fips_dsa_key.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
|
||||
fips_dsa_key.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
|
||||
fips_dsa_key.o: ../../include/openssl/opensslconf.h
|
||||
fips_dsa_key.o: ../../include/openssl/opensslv.h
|
||||
fips_dsa_key.o: ../../include/openssl/ossl_typ.h ../../include/openssl/rand.h
|
||||
fips_dsa_key.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
|
||||
fips_dsa_key.o: ../../include/openssl/symhacks.h ../fips_locl.h fips_dsa_key.c
|
||||
fips_dsa_lib.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
|
||||
fips_dsa_lib.o: ../../include/openssl/crypto.h ../../include/openssl/dsa.h
|
||||
fips_dsa_lib.o: ../../include/openssl/e_os2.h
|
||||
fips_dsa_lib.o: ../../include/openssl/opensslconf.h
|
||||
fips_dsa_lib.o: ../../include/openssl/opensslv.h
|
||||
fips_dsa_lib.o: ../../include/openssl/ossl_typ.h
|
||||
fips_dsa_lib.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
|
||||
fips_dsa_lib.o: ../../include/openssl/symhacks.h fips_dsa_lib.c
|
||||
fips_dsa_ossl.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
|
||||
fips_dsa_ossl.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
|
||||
fips_dsa_ossl.o: ../../include/openssl/crypto.h ../../include/openssl/dsa.h
|
||||
fips_dsa_ossl.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
|
||||
fips_dsa_ossl.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
|
||||
fips_dsa_ossl.o: ../../include/openssl/engine.h ../../include/openssl/err.h
|
||||
fips_dsa_ossl.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
|
||||
fips_dsa_ossl.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
|
||||
fips_dsa_ossl.o: ../../include/openssl/objects.h
|
||||
fips_dsa_ossl.o: ../../include/openssl/opensslconf.h
|
||||
fips_dsa_ossl.o: ../../include/openssl/opensslv.h
|
||||
fips_dsa_ossl.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
|
||||
fips_dsa_ossl.o: ../../include/openssl/rand.h ../../include/openssl/safestack.h
|
||||
fips_dsa_ossl.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
|
||||
fips_dsa_ossl.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
|
||||
fips_dsa_ossl.o: ../../include/openssl/x509_vfy.h fips_dsa_ossl.c
|
||||
fips_dsa_selftest.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
|
||||
fips_dsa_selftest.o: ../../include/openssl/bn.h ../../include/openssl/crypto.h
|
||||
fips_dsa_selftest.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
|
||||
fips_dsa_selftest.o: ../../include/openssl/err.h ../../include/openssl/evp.h
|
||||
fips_dsa_selftest.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
|
||||
fips_dsa_selftest.o: ../../include/openssl/obj_mac.h
|
||||
fips_dsa_selftest.o: ../../include/openssl/objects.h
|
||||
fips_dsa_selftest.o: ../../include/openssl/opensslconf.h
|
||||
fips_dsa_selftest.o: ../../include/openssl/opensslv.h
|
||||
fips_dsa_selftest.o: ../../include/openssl/ossl_typ.h
|
||||
fips_dsa_selftest.o: ../../include/openssl/safestack.h
|
||||
fips_dsa_selftest.o: ../../include/openssl/stack.h
|
||||
fips_dsa_selftest.o: ../../include/openssl/symhacks.h fips_dsa_selftest.c
|
||||
fips_dsa_sign.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
|
||||
fips_dsa_sign.o: ../../include/openssl/bn.h ../../include/openssl/crypto.h
|
||||
fips_dsa_sign.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
|
||||
fips_dsa_sign.o: ../../include/openssl/err.h ../../include/openssl/evp.h
|
||||
fips_dsa_sign.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
|
||||
fips_dsa_sign.o: ../../include/openssl/obj_mac.h
|
||||
fips_dsa_sign.o: ../../include/openssl/objects.h
|
||||
fips_dsa_sign.o: ../../include/openssl/opensslconf.h
|
||||
fips_dsa_sign.o: ../../include/openssl/opensslv.h
|
||||
fips_dsa_sign.o: ../../include/openssl/ossl_typ.h
|
||||
fips_dsa_sign.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
|
||||
fips_dsa_sign.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
|
||||
fips_dsa_sign.o: fips_dsa_sign.c
|
||||
fips_dsatest.o: ../../e_os.h ../../include/openssl/asn1.h
|
||||
fips_dsatest.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
|
||||
fips_dsatest.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
|
||||
fips_dsatest.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
|
||||
fips_dsatest.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
|
||||
fips_dsatest.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
|
||||
fips_dsatest.o: ../../include/openssl/ecdsa.h ../../include/openssl/engine.h
|
||||
fips_dsatest.o: ../../include/openssl/err.h ../../include/openssl/evp.h
|
||||
fips_dsatest.o: ../../include/openssl/fips.h ../../include/openssl/fips_rand.h
|
||||
fips_dsatest.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
|
||||
fips_dsatest.o: ../../include/openssl/objects.h
|
||||
fips_dsatest.o: ../../include/openssl/opensslconf.h
|
||||
fips_dsatest.o: ../../include/openssl/opensslv.h
|
||||
fips_dsatest.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
|
||||
fips_dsatest.o: ../../include/openssl/rand.h ../../include/openssl/safestack.h
|
||||
fips_dsatest.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
|
||||
fips_dsatest.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
|
||||
fips_dsatest.o: ../../include/openssl/ui_compat.h ../../include/openssl/x509.h
|
||||
fips_dsatest.o: ../../include/openssl/x509_vfy.h ../fips_utl.h fips_dsatest.c
|
||||
fips_dssvs.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
|
||||
fips_dssvs.o: ../../include/openssl/bn.h ../../include/openssl/crypto.h
|
||||
fips_dssvs.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
|
||||
fips_dssvs.o: ../../include/openssl/err.h ../../include/openssl/evp.h
|
||||
fips_dssvs.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
|
||||
fips_dssvs.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
|
||||
fips_dssvs.o: ../../include/openssl/opensslconf.h
|
||||
fips_dssvs.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
|
||||
fips_dssvs.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
|
||||
fips_dssvs.o: ../../include/openssl/symhacks.h ../fips_utl.h fips_dssvs.c
|
||||
|
|
@ -1,339 +0,0 @@
|
|||
/* crypto/dsa/dsa_gen.c */
|
||||
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
|
||||
* All rights reserved.
|
||||
*
|
||||
* This package is an SSL implementation written
|
||||
* by Eric Young (eay@cryptsoft.com).
|
||||
* The implementation was written so as to conform with Netscapes SSL.
|
||||
*
|
||||
* This library is free for commercial and non-commercial use as long as
|
||||
* the following conditions are aheared to. The following conditions
|
||||
* apply to all code found in this distribution, be it the RC4, RSA,
|
||||
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
|
||||
* included with this distribution is covered by the same copyright terms
|
||||
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
* Copyright remains Eric Young's, and as such any Copyright notices in
|
||||
* the code are not to be removed.
|
||||
* If this package is used in a product, Eric Young should be given attribution
|
||||
* as the author of the parts of the library used.
|
||||
* This can be in the form of a textual message at program startup or
|
||||
* in documentation (online or textual) provided with the package.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* "This product includes cryptographic software written by
|
||||
* Eric Young (eay@cryptsoft.com)"
|
||||
* The word 'cryptographic' can be left out if the rouines from the library
|
||||
* being used are not cryptographic related :-).
|
||||
* 4. If you include any Windows specific code (or a derivative thereof) from
|
||||
* the apps directory (application code) you must include an acknowledgement:
|
||||
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* The licence and distribution terms for any publically available version or
|
||||
* derivative of this code cannot be changed. i.e. this code cannot simply be
|
||||
* copied and put under another distribution licence
|
||||
* [including the GNU Public Licence.]
|
||||
*/
|
||||
|
||||
#undef GENUINE_DSA
|
||||
|
||||
#ifdef GENUINE_DSA
|
||||
/* Parameter generation follows the original release of FIPS PUB 186,
|
||||
* Appendix 2.2 (i.e. use SHA as defined in FIPS PUB 180) */
|
||||
#define HASH EVP_sha()
|
||||
#else
|
||||
/* Parameter generation follows the updated Appendix 2.2 for FIPS PUB 186,
|
||||
* also Appendix 2.2 of FIPS PUB 186-1 (i.e. use SHA as defined in
|
||||
* FIPS PUB 180-1) */
|
||||
#define HASH EVP_sha1()
|
||||
#endif
|
||||
|
||||
#include <openssl/opensslconf.h> /* To see if OPENSSL_NO_SHA is defined */
|
||||
|
||||
#ifndef OPENSSL_NO_SHA
|
||||
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#include <string.h>
|
||||
#include <openssl/evp.h>
|
||||
#include <openssl/bn.h>
|
||||
#include <openssl/dsa.h>
|
||||
#include <openssl/rand.h>
|
||||
#include <openssl/sha.h>
|
||||
#include <openssl/err.h>
|
||||
|
||||
#ifdef OPENSSL_FIPS
|
||||
|
||||
static int dsa_builtin_paramgen(DSA *ret, int bits,
|
||||
unsigned char *seed_in, int seed_len,
|
||||
int *counter_ret, unsigned long *h_ret, BN_GENCB *cb);
|
||||
|
||||
int DSA_generate_parameters_ex(DSA *ret, int bits,
|
||||
unsigned char *seed_in, int seed_len,
|
||||
int *counter_ret, unsigned long *h_ret, BN_GENCB *cb)
|
||||
{
|
||||
if(ret->meth->dsa_paramgen)
|
||||
return ret->meth->dsa_paramgen(ret, bits, seed_in, seed_len,
|
||||
counter_ret, h_ret, cb);
|
||||
return dsa_builtin_paramgen(ret, bits, seed_in, seed_len,
|
||||
counter_ret, h_ret, cb);
|
||||
}
|
||||
|
||||
static int dsa_builtin_paramgen(DSA *ret, int bits,
|
||||
unsigned char *seed_in, int seed_len,
|
||||
int *counter_ret, unsigned long *h_ret, BN_GENCB *cb)
|
||||
{
|
||||
int ok=0;
|
||||
unsigned char seed[SHA_DIGEST_LENGTH];
|
||||
unsigned char md[SHA_DIGEST_LENGTH];
|
||||
unsigned char buf[SHA_DIGEST_LENGTH],buf2[SHA_DIGEST_LENGTH];
|
||||
BIGNUM *r0,*W,*X,*c,*test;
|
||||
BIGNUM *g=NULL,*q=NULL,*p=NULL;
|
||||
BN_MONT_CTX *mont=NULL;
|
||||
int k,n=0,i,b,m=0;
|
||||
int counter=0;
|
||||
int r=0;
|
||||
BN_CTX *ctx=NULL;
|
||||
unsigned int h=2;
|
||||
|
||||
if(FIPS_selftest_failed())
|
||||
{
|
||||
FIPSerr(FIPS_F_DSA_BUILTIN_PARAMGEN,
|
||||
FIPS_R_FIPS_SELFTEST_FAILED);
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (FIPS_mode() && (bits < OPENSSL_DSA_FIPS_MIN_MODULUS_BITS))
|
||||
{
|
||||
DSAerr(DSA_F_DSA_BUILTIN_PARAMGEN, DSA_R_KEY_SIZE_TOO_SMALL);
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (bits < 512) bits=512;
|
||||
bits=(bits+63)/64*64;
|
||||
|
||||
/* NB: seed_len == 0 is special case: copy generated seed to
|
||||
* seed_in if it is not NULL.
|
||||
*/
|
||||
if (seed_len && (seed_len < 20))
|
||||
seed_in = NULL; /* seed buffer too small -- ignore */
|
||||
if (seed_len > 20)
|
||||
seed_len = 20; /* App. 2.2 of FIPS PUB 186 allows larger SEED,
|
||||
* but our internal buffers are restricted to 160 bits*/
|
||||
if ((seed_in != NULL) && (seed_len == 20))
|
||||
{
|
||||
memcpy(seed,seed_in,seed_len);
|
||||
/* set seed_in to NULL to avoid it being copied back */
|
||||
seed_in = NULL;
|
||||
}
|
||||
|
||||
if ((ctx=BN_CTX_new()) == NULL) goto err;
|
||||
|
||||
if ((mont=BN_MONT_CTX_new()) == NULL) goto err;
|
||||
|
||||
BN_CTX_start(ctx);
|
||||
r0 = BN_CTX_get(ctx);
|
||||
g = BN_CTX_get(ctx);
|
||||
W = BN_CTX_get(ctx);
|
||||
q = BN_CTX_get(ctx);
|
||||
X = BN_CTX_get(ctx);
|
||||
c = BN_CTX_get(ctx);
|
||||
p = BN_CTX_get(ctx);
|
||||
test = BN_CTX_get(ctx);
|
||||
|
||||
if (!BN_lshift(test,BN_value_one(),bits-1))
|
||||
goto err;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
for (;;) /* find q */
|
||||
{
|
||||
int seed_is_random;
|
||||
|
||||
/* step 1 */
|
||||
if(!BN_GENCB_call(cb, 0, m++))
|
||||
goto err;
|
||||
|
||||
if (!seed_len)
|
||||
{
|
||||
RAND_pseudo_bytes(seed,SHA_DIGEST_LENGTH);
|
||||
seed_is_random = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
seed_is_random = 0;
|
||||
seed_len=0; /* use random seed if 'seed_in' turns out to be bad*/
|
||||
}
|
||||
memcpy(buf,seed,SHA_DIGEST_LENGTH);
|
||||
memcpy(buf2,seed,SHA_DIGEST_LENGTH);
|
||||
/* precompute "SEED + 1" for step 7: */
|
||||
for (i=SHA_DIGEST_LENGTH-1; i >= 0; i--)
|
||||
{
|
||||
buf[i]++;
|
||||
if (buf[i] != 0) break;
|
||||
}
|
||||
|
||||
/* step 2 */
|
||||
EVP_Digest(seed,SHA_DIGEST_LENGTH,md,NULL,HASH, NULL);
|
||||
EVP_Digest(buf,SHA_DIGEST_LENGTH,buf2,NULL,HASH, NULL);
|
||||
for (i=0; i<SHA_DIGEST_LENGTH; i++)
|
||||
md[i]^=buf2[i];
|
||||
|
||||
/* step 3 */
|
||||
md[0]|=0x80;
|
||||
md[SHA_DIGEST_LENGTH-1]|=0x01;
|
||||
if (!BN_bin2bn(md,SHA_DIGEST_LENGTH,q)) goto err;
|
||||
|
||||
/* step 4 */
|
||||
r = BN_is_prime_fasttest_ex(q, DSS_prime_checks, ctx,
|
||||
seed_is_random, cb);
|
||||
if (r > 0)
|
||||
break;
|
||||
if (r != 0)
|
||||
goto err;
|
||||
|
||||
/* do a callback call */
|
||||
/* step 5 */
|
||||
}
|
||||
|
||||
if(!BN_GENCB_call(cb, 2, 0)) goto err;
|
||||
if(!BN_GENCB_call(cb, 3, 0)) goto err;
|
||||
|
||||
/* step 6 */
|
||||
counter=0;
|
||||
/* "offset = 2" */
|
||||
|
||||
n=(bits-1)/160;
|
||||
b=(bits-1)-n*160;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
if ((counter != 0) && !BN_GENCB_call(cb, 0, counter))
|
||||
goto err;
|
||||
|
||||
/* step 7 */
|
||||
BN_zero(W);
|
||||
/* now 'buf' contains "SEED + offset - 1" */
|
||||
for (k=0; k<=n; k++)
|
||||
{
|
||||
/* obtain "SEED + offset + k" by incrementing: */
|
||||
for (i=SHA_DIGEST_LENGTH-1; i >= 0; i--)
|
||||
{
|
||||
buf[i]++;
|
||||
if (buf[i] != 0) break;
|
||||
}
|
||||
|
||||
EVP_Digest(buf,SHA_DIGEST_LENGTH,md,NULL,HASH, NULL);
|
||||
|
||||
/* step 8 */
|
||||
if (!BN_bin2bn(md,SHA_DIGEST_LENGTH,r0))
|
||||
goto err;
|
||||
if (!BN_lshift(r0,r0,160*k)) goto err;
|
||||
if (!BN_add(W,W,r0)) goto err;
|
||||
}
|
||||
|
||||
/* more of step 8 */
|
||||
if (!BN_mask_bits(W,bits-1)) goto err;
|
||||
if (!BN_copy(X,W)) goto err;
|
||||
if (!BN_add(X,X,test)) goto err;
|
||||
|
||||
/* step 9 */
|
||||
if (!BN_lshift1(r0,q)) goto err;
|
||||
if (!BN_mod(c,X,r0,ctx)) goto err;
|
||||
if (!BN_sub(r0,c,BN_value_one())) goto err;
|
||||
if (!BN_sub(p,X,r0)) goto err;
|
||||
|
||||
/* step 10 */
|
||||
if (BN_cmp(p,test) >= 0)
|
||||
{
|
||||
/* step 11 */
|
||||
r = BN_is_prime_fasttest_ex(p, DSS_prime_checks,
|
||||
ctx, 1, cb);
|
||||
if (r > 0)
|
||||
goto end; /* found it */
|
||||
if (r != 0)
|
||||
goto err;
|
||||
}
|
||||
|
||||
/* step 13 */
|
||||
counter++;
|
||||
/* "offset = offset + n + 1" */
|
||||
|
||||
/* step 14 */
|
||||
if (counter >= 4096) break;
|
||||
}
|
||||
}
|
||||
end:
|
||||
if(!BN_GENCB_call(cb, 2, 1))
|
||||
goto err;
|
||||
|
||||
/* We now need to generate g */
|
||||
/* Set r0=(p-1)/q */
|
||||
if (!BN_sub(test,p,BN_value_one())) goto err;
|
||||
if (!BN_div(r0,NULL,test,q,ctx)) goto err;
|
||||
|
||||
if (!BN_set_word(test,h)) goto err;
|
||||
if (!BN_MONT_CTX_set(mont,p,ctx)) goto err;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
/* g=test^r0%p */
|
||||
if (!BN_mod_exp_mont(g,test,r0,p,ctx,mont)) goto err;
|
||||
if (!BN_is_one(g)) break;
|
||||
if (!BN_add(test,test,BN_value_one())) goto err;
|
||||
h++;
|
||||
}
|
||||
|
||||
if(!BN_GENCB_call(cb, 3, 1))
|
||||
goto err;
|
||||
|
||||
ok=1;
|
||||
err:
|
||||
if (ok)
|
||||
{
|
||||
if(ret->p) BN_free(ret->p);
|
||||
if(ret->q) BN_free(ret->q);
|
||||
if(ret->g) BN_free(ret->g);
|
||||
ret->p=BN_dup(p);
|
||||
ret->q=BN_dup(q);
|
||||
ret->g=BN_dup(g);
|
||||
if (ret->p == NULL || ret->q == NULL || ret->g == NULL)
|
||||
{
|
||||
ok=0;
|
||||
goto err;
|
||||
}
|
||||
if (seed_in != NULL) memcpy(seed_in,seed,20);
|
||||
if (counter_ret != NULL) *counter_ret=counter;
|
||||
if (h_ret != NULL) *h_ret=h;
|
||||
}
|
||||
if(ctx)
|
||||
{
|
||||
BN_CTX_end(ctx);
|
||||
BN_CTX_free(ctx);
|
||||
}
|
||||
if (mont != NULL) BN_MONT_CTX_free(mont);
|
||||
return ok;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
|
@ -1,169 +0,0 @@
|
|||
/* crypto/dsa/dsa_key.c */
|
||||
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
|
||||
* All rights reserved.
|
||||
*
|
||||
* This package is an SSL implementation written
|
||||
* by Eric Young (eay@cryptsoft.com).
|
||||
* The implementation was written so as to conform with Netscapes SSL.
|
||||
*
|
||||
* This library is free for commercial and non-commercial use as long as
|
||||
* the following conditions are aheared to. The following conditions
|
||||
* apply to all code found in this distribution, be it the RC4, RSA,
|
||||
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
|
||||
* included with this distribution is covered by the same copyright terms
|
||||
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
* Copyright remains Eric Young's, and as such any Copyright notices in
|
||||
* the code are not to be removed.
|
||||
* If this package is used in a product, Eric Young should be given attribution
|
||||
* as the author of the parts of the library used.
|
||||
* This can be in the form of a textual message at program startup or
|
||||
* in documentation (online or textual) provided with the package.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* "This product includes cryptographic software written by
|
||||
* Eric Young (eay@cryptsoft.com)"
|
||||
* The word 'cryptographic' can be left out if the rouines from the library
|
||||
* being used are not cryptographic related :-).
|
||||
* 4. If you include any Windows specific code (or a derivative thereof) from
|
||||
* the apps directory (application code) you must include an acknowledgement:
|
||||
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* The licence and distribution terms for any publically available version or
|
||||
* derivative of this code cannot be changed. i.e. this code cannot simply be
|
||||
* copied and put under another distribution licence
|
||||
* [including the GNU Public Licence.]
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#ifndef OPENSSL_NO_SHA
|
||||
#include <openssl/bn.h>
|
||||
#include <openssl/dsa.h>
|
||||
#include <openssl/rand.h>
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/evp.h>
|
||||
#include <openssl/fips.h>
|
||||
#include "fips_locl.h"
|
||||
|
||||
#ifdef OPENSSL_FIPS
|
||||
|
||||
static int fips_dsa_pairwise_fail = 0;
|
||||
|
||||
void FIPS_corrupt_dsa_keygen(void)
|
||||
{
|
||||
fips_dsa_pairwise_fail = 1;
|
||||
}
|
||||
|
||||
static int dsa_builtin_keygen(DSA *dsa);
|
||||
|
||||
static int fips_check_dsa(DSA *dsa)
|
||||
{
|
||||
EVP_PKEY pk;
|
||||
unsigned char tbs[] = "DSA Pairwise Check Data";
|
||||
pk.type = EVP_PKEY_DSA;
|
||||
pk.pkey.dsa = dsa;
|
||||
|
||||
if (!fips_pkey_signature_test(&pk, tbs, -1,
|
||||
NULL, 0, EVP_dss1(), 0, NULL))
|
||||
{
|
||||
FIPSerr(FIPS_F_FIPS_CHECK_DSA,FIPS_R_PAIRWISE_TEST_FAILED);
|
||||
fips_set_selftest_fail();
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int DSA_generate_key(DSA *dsa)
|
||||
{
|
||||
if(dsa->meth->dsa_keygen)
|
||||
return dsa->meth->dsa_keygen(dsa);
|
||||
return dsa_builtin_keygen(dsa);
|
||||
}
|
||||
|
||||
static int dsa_builtin_keygen(DSA *dsa)
|
||||
{
|
||||
int ok=0;
|
||||
BN_CTX *ctx=NULL;
|
||||
BIGNUM *pub_key=NULL,*priv_key=NULL;
|
||||
|
||||
if (FIPS_mode() && (BN_num_bits(dsa->p) < OPENSSL_DSA_FIPS_MIN_MODULUS_BITS))
|
||||
{
|
||||
DSAerr(DSA_F_DSA_BUILTIN_KEYGEN, DSA_R_KEY_SIZE_TOO_SMALL);
|
||||
goto err;
|
||||
}
|
||||
|
||||
if ((ctx=BN_CTX_new()) == NULL) goto err;
|
||||
|
||||
if (dsa->priv_key == NULL)
|
||||
{
|
||||
if ((priv_key=BN_new()) == NULL) goto err;
|
||||
}
|
||||
else
|
||||
priv_key=dsa->priv_key;
|
||||
|
||||
do
|
||||
if (!BN_rand_range(priv_key,dsa->q)) goto err;
|
||||
while (BN_is_zero(priv_key));
|
||||
|
||||
if (dsa->pub_key == NULL)
|
||||
{
|
||||
if ((pub_key=BN_new()) == NULL) goto err;
|
||||
}
|
||||
else
|
||||
pub_key=dsa->pub_key;
|
||||
|
||||
{
|
||||
BIGNUM local_prk;
|
||||
BIGNUM *prk;
|
||||
|
||||
if ((dsa->flags & DSA_FLAG_NO_EXP_CONSTTIME) == 0)
|
||||
{
|
||||
BN_init(&local_prk);
|
||||
prk = &local_prk;
|
||||
BN_with_flags(prk, priv_key, BN_FLG_CONSTTIME);
|
||||
}
|
||||
else
|
||||
prk = priv_key;
|
||||
|
||||
if (!BN_mod_exp(pub_key,dsa->g,prk,dsa->p,ctx)) goto err;
|
||||
}
|
||||
|
||||
dsa->priv_key=priv_key;
|
||||
dsa->pub_key=pub_key;
|
||||
if (fips_dsa_pairwise_fail)
|
||||
BN_add_word(dsa->pub_key, 1);
|
||||
if(!fips_check_dsa(dsa))
|
||||
goto err;
|
||||
ok=1;
|
||||
|
||||
err:
|
||||
if ((pub_key != NULL) && (dsa->pub_key == NULL)) BN_free(pub_key);
|
||||
if ((priv_key != NULL) && (dsa->priv_key == NULL)) BN_free(priv_key);
|
||||
if (ctx != NULL) BN_CTX_free(ctx);
|
||||
return(ok);
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
@ -1,95 +0,0 @@
|
|||
/* fips_dsa_lib.c */
|
||||
/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
|
||||
* project 2007.
|
||||
*/
|
||||
/* ====================================================================
|
||||
* Copyright (c) 2007 The OpenSSL Project. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* 3. All advertising materials mentioning features or use of this
|
||||
* software must display the following acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
|
||||
*
|
||||
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission. For written permission, please contact
|
||||
* licensing@OpenSSL.org.
|
||||
*
|
||||
* 5. Products derived from this software may not be called "OpenSSL"
|
||||
* nor may "OpenSSL" appear in their names without prior written
|
||||
* permission of the OpenSSL Project.
|
||||
*
|
||||
* 6. Redistributions of any form whatsoever must retain the following
|
||||
* acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
|
||||
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
|
||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ====================================================================
|
||||
*
|
||||
* This product includes cryptographic software written by Eric Young
|
||||
* (eay@cryptsoft.com). This product includes software written by Tim
|
||||
* Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <openssl/dsa.h>
|
||||
#include <openssl/bn.h>
|
||||
|
||||
/* Minimal FIPS versions of FIPS_dsa_new() and FIPS_dsa_free: to
|
||||
* reduce external dependencies.
|
||||
*/
|
||||
|
||||
DSA *FIPS_dsa_new(void)
|
||||
{
|
||||
DSA *ret;
|
||||
ret = OPENSSL_malloc(sizeof(DSA));
|
||||
if (!ret)
|
||||
return NULL;
|
||||
memset(ret, 0, sizeof(DSA));
|
||||
ret->meth = DSA_OpenSSL();
|
||||
if (ret->meth->init)
|
||||
ret->meth->init(ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void FIPS_dsa_free(DSA *r)
|
||||
{
|
||||
if (!r)
|
||||
return;
|
||||
if (r->meth->finish)
|
||||
r->meth->finish(r);
|
||||
if (r->p != NULL) BN_clear_free(r->p);
|
||||
if (r->q != NULL) BN_clear_free(r->q);
|
||||
if (r->g != NULL) BN_clear_free(r->g);
|
||||
if (r->pub_key != NULL) BN_clear_free(r->pub_key);
|
||||
if (r->priv_key != NULL) BN_clear_free(r->priv_key);
|
||||
if (r->kinv != NULL) BN_clear_free(r->kinv);
|
||||
if (r->r != NULL) BN_clear_free(r->r);
|
||||
OPENSSL_free(r);
|
||||
}
|
||||
|
||||
|
|
@ -1,435 +0,0 @@
|
|||
/* crypto/dsa/dsa_ossl.c */
|
||||
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
|
||||
* All rights reserved.
|
||||
*
|
||||
* This package is an SSL implementation written
|
||||
* by Eric Young (eay@cryptsoft.com).
|
||||
* The implementation was written so as to conform with Netscapes SSL.
|
||||
*
|
||||
* This library is free for commercial and non-commercial use as long as
|
||||
* the following conditions are aheared to. The following conditions
|
||||
* apply to all code found in this distribution, be it the RC4, RSA,
|
||||
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
|
||||
* included with this distribution is covered by the same copyright terms
|
||||
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
* Copyright remains Eric Young's, and as such any Copyright notices in
|
||||
* the code are not to be removed.
|
||||
* If this package is used in a product, Eric Young should be given attribution
|
||||
* as the author of the parts of the library used.
|
||||
* This can be in the form of a textual message at program startup or
|
||||
* in documentation (online or textual) provided with the package.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* "This product includes cryptographic software written by
|
||||
* Eric Young (eay@cryptsoft.com)"
|
||||
* The word 'cryptographic' can be left out if the rouines from the library
|
||||
* being used are not cryptographic related :-).
|
||||
* 4. If you include any Windows specific code (or a derivative thereof) from
|
||||
* the apps directory (application code) you must include an acknowledgement:
|
||||
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* The licence and distribution terms for any publically available version or
|
||||
* derivative of this code cannot be changed. i.e. this code cannot simply be
|
||||
* copied and put under another distribution licence
|
||||
* [including the GNU Public Licence.]
|
||||
*/
|
||||
|
||||
/* Original version from Steven Schoch <schoch@sheba.arc.nasa.gov> */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <openssl/bn.h>
|
||||
#include <openssl/dsa.h>
|
||||
#include <openssl/rand.h>
|
||||
#include <openssl/asn1.h>
|
||||
#include <openssl/err.h>
|
||||
#ifndef OPENSSL_NO_ENGINE
|
||||
#include <openssl/engine.h>
|
||||
#endif
|
||||
#include <openssl/fips.h>
|
||||
|
||||
#ifdef OPENSSL_FIPS
|
||||
|
||||
static DSA_SIG *dsa_do_sign(const unsigned char *dgst, FIPS_DSA_SIZE_T dlen, DSA *dsa);
|
||||
static int dsa_sign_setup(DSA *dsa, BN_CTX *ctx_in, BIGNUM **kinvp, BIGNUM **rp);
|
||||
static int dsa_do_verify(const unsigned char *dgst, FIPS_DSA_SIZE_T dgst_len, DSA_SIG *sig,
|
||||
DSA *dsa);
|
||||
static int dsa_init(DSA *dsa);
|
||||
static int dsa_finish(DSA *dsa);
|
||||
static int dsa_mod_exp(DSA *dsa, BIGNUM *rr, BIGNUM *a1, BIGNUM *p1,
|
||||
BIGNUM *a2, BIGNUM *p2, BIGNUM *m, BN_CTX *ctx,
|
||||
BN_MONT_CTX *in_mont);
|
||||
static int dsa_bn_mod_exp(DSA *dsa, BIGNUM *r, BIGNUM *a, const BIGNUM *p,
|
||||
const BIGNUM *m, BN_CTX *ctx,
|
||||
BN_MONT_CTX *m_ctx);
|
||||
|
||||
static const DSA_METHOD openssl_dsa_meth = {
|
||||
"OpenSSL FIPS DSA method",
|
||||
dsa_do_sign,
|
||||
dsa_sign_setup,
|
||||
dsa_do_verify,
|
||||
dsa_mod_exp,
|
||||
dsa_bn_mod_exp,
|
||||
dsa_init,
|
||||
dsa_finish,
|
||||
DSA_FLAG_FIPS_METHOD,
|
||||
NULL
|
||||
};
|
||||
#if 0
|
||||
int FIPS_dsa_check(struct dsa_st *dsa)
|
||||
{
|
||||
if(dsa->meth != &openssl_dsa_meth || dsa->meth->dsa_do_sign != dsa_do_sign
|
||||
|| dsa->meth->dsa_sign_setup != dsa_sign_setup
|
||||
|| dsa->meth->dsa_mod_exp != dsa_mod_exp
|
||||
|| dsa->meth->bn_mod_exp != dsa_bn_mod_exp
|
||||
|| dsa->meth->init != dsa_init
|
||||
|| dsa->meth->finish != dsa_finish)
|
||||
{
|
||||
FIPSerr(FIPS_F_FIPS_DSA_CHECK,FIPS_R_NON_FIPS_METHOD);
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
const DSA_METHOD *DSA_OpenSSL(void)
|
||||
{
|
||||
return &openssl_dsa_meth;
|
||||
}
|
||||
|
||||
static DSA_SIG *dsa_do_sign(const unsigned char *dgst, FIPS_DSA_SIZE_T dlen, DSA *dsa)
|
||||
{
|
||||
BIGNUM *kinv=NULL,*r=NULL,*s=NULL;
|
||||
BIGNUM m;
|
||||
BIGNUM xr;
|
||||
BN_CTX *ctx=NULL;
|
||||
int i,reason=ERR_R_BN_LIB;
|
||||
DSA_SIG *ret=NULL;
|
||||
|
||||
if(FIPS_selftest_failed())
|
||||
{
|
||||
FIPSerr(FIPS_F_DSA_DO_SIGN,FIPS_R_FIPS_SELFTEST_FAILED);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (FIPS_mode() && (BN_num_bits(dsa->p) < OPENSSL_DSA_FIPS_MIN_MODULUS_BITS))
|
||||
{
|
||||
DSAerr(DSA_F_DSA_DO_SIGN, DSA_R_KEY_SIZE_TOO_SMALL);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
BN_init(&m);
|
||||
BN_init(&xr);
|
||||
|
||||
if (!dsa->p || !dsa->q || !dsa->g)
|
||||
{
|
||||
reason=DSA_R_MISSING_PARAMETERS;
|
||||
goto err;
|
||||
}
|
||||
|
||||
s=BN_new();
|
||||
if (s == NULL) goto err;
|
||||
|
||||
i=BN_num_bytes(dsa->q); /* should be 20 */
|
||||
if ((dlen > i) || (dlen > 50))
|
||||
{
|
||||
reason=DSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE;
|
||||
goto err;
|
||||
}
|
||||
|
||||
ctx=BN_CTX_new();
|
||||
if (ctx == NULL) goto err;
|
||||
|
||||
if (!dsa->meth->dsa_sign_setup(dsa,ctx,&kinv,&r)) goto err;
|
||||
|
||||
if (BN_bin2bn(dgst,dlen,&m) == NULL) goto err;
|
||||
|
||||
/* Compute s = inv(k) (m + xr) mod q */
|
||||
if (!BN_mod_mul(&xr,dsa->priv_key,r,dsa->q,ctx)) goto err;/* s = xr */
|
||||
if (!BN_add(s, &xr, &m)) goto err; /* s = m + xr */
|
||||
if (BN_cmp(s,dsa->q) > 0)
|
||||
BN_sub(s,s,dsa->q);
|
||||
if (!BN_mod_mul(s,s,kinv,dsa->q,ctx)) goto err;
|
||||
|
||||
ret= DSA_SIG_new();
|
||||
if (ret == NULL) goto err;
|
||||
ret->r = r;
|
||||
ret->s = s;
|
||||
|
||||
err:
|
||||
if (!ret)
|
||||
{
|
||||
DSAerr(DSA_F_DSA_DO_SIGN,reason);
|
||||
BN_free(r);
|
||||
BN_free(s);
|
||||
}
|
||||
if (ctx != NULL) BN_CTX_free(ctx);
|
||||
BN_clear_free(&m);
|
||||
BN_clear_free(&xr);
|
||||
if (kinv != NULL) /* dsa->kinv is NULL now if we used it */
|
||||
BN_clear_free(kinv);
|
||||
return(ret);
|
||||
}
|
||||
|
||||
static int dsa_sign_setup(DSA *dsa, BN_CTX *ctx_in, BIGNUM **kinvp, BIGNUM **rp)
|
||||
{
|
||||
BN_CTX *ctx;
|
||||
BIGNUM k,kq,*K,*kinv=NULL,*r=NULL;
|
||||
int ret=0;
|
||||
|
||||
if (!dsa->p || !dsa->q || !dsa->g)
|
||||
{
|
||||
DSAerr(DSA_F_DSA_SIGN_SETUP,DSA_R_MISSING_PARAMETERS);
|
||||
return 0;
|
||||
}
|
||||
|
||||
BN_init(&k);
|
||||
BN_init(&kq);
|
||||
|
||||
if (ctx_in == NULL)
|
||||
{
|
||||
if ((ctx=BN_CTX_new()) == NULL) goto err;
|
||||
}
|
||||
else
|
||||
ctx=ctx_in;
|
||||
|
||||
if ((r=BN_new()) == NULL) goto err;
|
||||
|
||||
/* Get random k */
|
||||
do
|
||||
if (!BN_rand_range(&k, dsa->q)) goto err;
|
||||
while (BN_is_zero(&k));
|
||||
if ((dsa->flags & DSA_FLAG_NO_EXP_CONSTTIME) == 0)
|
||||
{
|
||||
BN_set_flags(&k, BN_FLG_CONSTTIME);
|
||||
}
|
||||
|
||||
if (dsa->flags & DSA_FLAG_CACHE_MONT_P)
|
||||
{
|
||||
if (!BN_MONT_CTX_set_locked((BN_MONT_CTX **)&dsa->method_mont_p,
|
||||
CRYPTO_LOCK_DSA,
|
||||
dsa->p, ctx))
|
||||
goto err;
|
||||
}
|
||||
|
||||
/* Compute r = (g^k mod p) mod q */
|
||||
|
||||
if ((dsa->flags & DSA_FLAG_NO_EXP_CONSTTIME) == 0)
|
||||
{
|
||||
if (!BN_copy(&kq, &k)) goto err;
|
||||
|
||||
/* We do not want timing information to leak the length of k,
|
||||
* so we compute g^k using an equivalent exponent of fixed length.
|
||||
*
|
||||
* (This is a kludge that we need because the BN_mod_exp_mont()
|
||||
* does not let us specify the desired timing behaviour.) */
|
||||
|
||||
if (!BN_add(&kq, &kq, dsa->q)) goto err;
|
||||
if (BN_num_bits(&kq) <= BN_num_bits(dsa->q))
|
||||
{
|
||||
if (!BN_add(&kq, &kq, dsa->q)) goto err;
|
||||
}
|
||||
|
||||
K = &kq;
|
||||
}
|
||||
else
|
||||
{
|
||||
K = &k;
|
||||
}
|
||||
if (!dsa->meth->bn_mod_exp(dsa, r,dsa->g,K,dsa->p,ctx,
|
||||
(BN_MONT_CTX *)dsa->method_mont_p)) goto err;
|
||||
if (!BN_mod(r,r,dsa->q,ctx)) goto err;
|
||||
|
||||
/* Compute part of 's = inv(k) (m + xr) mod q' */
|
||||
if ((kinv=BN_mod_inverse(NULL,&k,dsa->q,ctx)) == NULL) goto err;
|
||||
|
||||
if (*kinvp != NULL) BN_clear_free(*kinvp);
|
||||
*kinvp=kinv;
|
||||
kinv=NULL;
|
||||
if (*rp != NULL) BN_clear_free(*rp);
|
||||
*rp=r;
|
||||
ret=1;
|
||||
err:
|
||||
if (!ret)
|
||||
{
|
||||
DSAerr(DSA_F_DSA_SIGN_SETUP,ERR_R_BN_LIB);
|
||||
if (kinv != NULL) BN_clear_free(kinv);
|
||||
if (r != NULL) BN_clear_free(r);
|
||||
}
|
||||
if (ctx_in == NULL) BN_CTX_free(ctx);
|
||||
if (kinv != NULL) BN_clear_free(kinv);
|
||||
BN_clear_free(&k);
|
||||
BN_clear_free(&kq);
|
||||
return(ret);
|
||||
}
|
||||
|
||||
static int dsa_do_verify(const unsigned char *dgst, FIPS_DSA_SIZE_T dgst_len, DSA_SIG *sig,
|
||||
DSA *dsa)
|
||||
{
|
||||
BN_CTX *ctx;
|
||||
BIGNUM u1,u2,t1;
|
||||
BN_MONT_CTX *mont=NULL;
|
||||
int ret = -1;
|
||||
|
||||
if (!dsa->p || !dsa->q || !dsa->g)
|
||||
{
|
||||
DSAerr(DSA_F_DSA_DO_VERIFY,DSA_R_MISSING_PARAMETERS);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(FIPS_selftest_failed())
|
||||
{
|
||||
FIPSerr(FIPS_F_DSA_DO_VERIFY,FIPS_R_FIPS_SELFTEST_FAILED);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (BN_num_bits(dsa->q) != 160)
|
||||
{
|
||||
DSAerr(DSA_F_DSA_DO_VERIFY,DSA_R_BAD_Q_VALUE);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (BN_num_bits(dsa->p) > OPENSSL_DSA_MAX_MODULUS_BITS)
|
||||
{
|
||||
DSAerr(DSA_F_DSA_DO_VERIFY,DSA_R_MODULUS_TOO_LARGE);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (FIPS_mode() && (BN_num_bits(dsa->p) < OPENSSL_DSA_FIPS_MIN_MODULUS_BITS))
|
||||
{
|
||||
DSAerr(DSA_F_DSA_DO_VERIFY, DSA_R_KEY_SIZE_TOO_SMALL);
|
||||
return -1;
|
||||
}
|
||||
|
||||
BN_init(&u1);
|
||||
BN_init(&u2);
|
||||
BN_init(&t1);
|
||||
|
||||
if ((ctx=BN_CTX_new()) == NULL) goto err;
|
||||
|
||||
if (BN_is_zero(sig->r) || sig->r->neg || BN_ucmp(sig->r, dsa->q) >= 0)
|
||||
{
|
||||
ret = 0;
|
||||
goto err;
|
||||
}
|
||||
if (BN_is_zero(sig->s) || sig->s->neg || BN_ucmp(sig->s, dsa->q) >= 0)
|
||||
{
|
||||
ret = 0;
|
||||
goto err;
|
||||
}
|
||||
|
||||
/* Calculate W = inv(S) mod Q
|
||||
* save W in u2 */
|
||||
if ((BN_mod_inverse(&u2,sig->s,dsa->q,ctx)) == NULL) goto err;
|
||||
|
||||
/* save M in u1 */
|
||||
if (BN_bin2bn(dgst,dgst_len,&u1) == NULL) goto err;
|
||||
|
||||
/* u1 = M * w mod q */
|
||||
if (!BN_mod_mul(&u1,&u1,&u2,dsa->q,ctx)) goto err;
|
||||
|
||||
/* u2 = r * w mod q */
|
||||
if (!BN_mod_mul(&u2,sig->r,&u2,dsa->q,ctx)) goto err;
|
||||
|
||||
|
||||
if (dsa->flags & DSA_FLAG_CACHE_MONT_P)
|
||||
{
|
||||
mont = BN_MONT_CTX_set_locked(
|
||||
(BN_MONT_CTX **)&dsa->method_mont_p,
|
||||
CRYPTO_LOCK_DSA, dsa->p, ctx);
|
||||
if (!mont)
|
||||
goto err;
|
||||
}
|
||||
|
||||
#if 0
|
||||
{
|
||||
BIGNUM t2;
|
||||
|
||||
BN_init(&t2);
|
||||
/* v = ( g^u1 * y^u2 mod p ) mod q */
|
||||
/* let t1 = g ^ u1 mod p */
|
||||
if (!BN_mod_exp_mont(&t1,dsa->g,&u1,dsa->p,ctx,mont)) goto err;
|
||||
/* let t2 = y ^ u2 mod p */
|
||||
if (!BN_mod_exp_mont(&t2,dsa->pub_key,&u2,dsa->p,ctx,mont)) goto err;
|
||||
/* let u1 = t1 * t2 mod p */
|
||||
if (!BN_mod_mul(&u1,&t1,&t2,dsa->p,ctx)) goto err_bn;
|
||||
BN_free(&t2);
|
||||
}
|
||||
/* let u1 = u1 mod q */
|
||||
if (!BN_mod(&u1,&u1,dsa->q,ctx)) goto err;
|
||||
#else
|
||||
{
|
||||
if (!dsa->meth->dsa_mod_exp(dsa, &t1,dsa->g,&u1,dsa->pub_key,&u2,
|
||||
dsa->p,ctx,mont)) goto err;
|
||||
/* BN_copy(&u1,&t1); */
|
||||
/* let u1 = u1 mod q */
|
||||
if (!BN_mod(&u1,&t1,dsa->q,ctx)) goto err;
|
||||
}
|
||||
#endif
|
||||
/* V is now in u1. If the signature is correct, it will be
|
||||
* equal to R. */
|
||||
ret=(BN_ucmp(&u1, sig->r) == 0);
|
||||
|
||||
err:
|
||||
if (ret != 1) DSAerr(DSA_F_DSA_DO_VERIFY,ERR_R_BN_LIB);
|
||||
if (ctx != NULL) BN_CTX_free(ctx);
|
||||
BN_free(&u1);
|
||||
BN_free(&u2);
|
||||
BN_free(&t1);
|
||||
return(ret);
|
||||
}
|
||||
|
||||
static int dsa_init(DSA *dsa)
|
||||
{
|
||||
FIPS_selftest_check();
|
||||
dsa->flags|=DSA_FLAG_CACHE_MONT_P;
|
||||
return(1);
|
||||
}
|
||||
|
||||
static int dsa_finish(DSA *dsa)
|
||||
{
|
||||
if(dsa->method_mont_p)
|
||||
BN_MONT_CTX_free((BN_MONT_CTX *)dsa->method_mont_p);
|
||||
return(1);
|
||||
}
|
||||
|
||||
static int dsa_mod_exp(DSA *dsa, BIGNUM *rr, BIGNUM *a1, BIGNUM *p1,
|
||||
BIGNUM *a2, BIGNUM *p2, BIGNUM *m, BN_CTX *ctx,
|
||||
BN_MONT_CTX *in_mont)
|
||||
{
|
||||
return BN_mod_exp2_mont(rr, a1, p1, a2, p2, m, ctx, in_mont);
|
||||
}
|
||||
|
||||
static int dsa_bn_mod_exp(DSA *dsa, BIGNUM *r, BIGNUM *a, const BIGNUM *p,
|
||||
const BIGNUM *m, BN_CTX *ctx,
|
||||
BN_MONT_CTX *m_ctx)
|
||||
{
|
||||
return BN_mod_exp_mont(r, a, p, m, ctx, m_ctx);
|
||||
}
|
||||
|
||||
#else /* ndef OPENSSL_FIPS */
|
||||
|
||||
static void *dummy=&dummy;
|
||||
|
||||
#endif /* ndef OPENSSL_FIPS */
|
||||
|
|
@ -1,180 +0,0 @@
|
|||
/* crypto/dsa/dsatest.c */
|
||||
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
|
||||
* All rights reserved.
|
||||
*
|
||||
* This package is an SSL implementation written
|
||||
* by Eric Young (eay@cryptsoft.com).
|
||||
* The implementation was written so as to conform with Netscapes SSL.
|
||||
*
|
||||
* This library is free for commercial and non-commercial use as long as
|
||||
* the following conditions are aheared to. The following conditions
|
||||
* apply to all code found in this distribution, be it the RC4, RSA,
|
||||
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
|
||||
* included with this distribution is covered by the same copyright terms
|
||||
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
* Copyright remains Eric Young's, and as such any Copyright notices in
|
||||
* the code are not to be removed.
|
||||
* If this package is used in a product, Eric Young should be given attribution
|
||||
* as the author of the parts of the library used.
|
||||
* This can be in the form of a textual message at program startup or
|
||||
* in documentation (online or textual) provided with the package.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* "This product includes cryptographic software written by
|
||||
* Eric Young (eay@cryptsoft.com)"
|
||||
* The word 'cryptographic' can be left out if the rouines from the library
|
||||
* being used are not cryptographic related :-).
|
||||
* 4. If you include any Windows specific code (or a derivative thereof) from
|
||||
* the apps directory (application code) you must include an acknowledgement:
|
||||
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* The licence and distribution terms for any publically available version or
|
||||
* derivative of this code cannot be changed. i.e. this code cannot simply be
|
||||
* copied and put under another distribution licence
|
||||
* [including the GNU Public Licence.]
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <openssl/crypto.h>
|
||||
#include <openssl/dsa.h>
|
||||
#include <openssl/fips.h>
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/evp.h>
|
||||
#include <openssl/bn.h>
|
||||
|
||||
#ifdef OPENSSL_FIPS
|
||||
|
||||
/* seed, out_p, out_q, out_g are taken the NIST test vectors */
|
||||
|
||||
static unsigned char seed[20] = {
|
||||
0x77, 0x8f, 0x40, 0x74, 0x6f, 0x66, 0xbe, 0x33, 0xce, 0xbe, 0x99, 0x34,
|
||||
0x4c, 0xfc, 0xf3, 0x28, 0xaa, 0x70, 0x2d, 0x3a
|
||||
};
|
||||
|
||||
static unsigned char out_p[] = {
|
||||
0xf7, 0x7c, 0x1b, 0x83, 0xd8, 0xe8, 0x5c, 0x7f, 0x85, 0x30, 0x17, 0x57,
|
||||
0x21, 0x95, 0xfe, 0x26, 0x04, 0xeb, 0x47, 0x4c, 0x3a, 0x4a, 0x81, 0x4b,
|
||||
0x71, 0x2e, 0xed, 0x6e, 0x4f, 0x3d, 0x11, 0x0f, 0x7c, 0xfe, 0x36, 0x43,
|
||||
0x51, 0xd9, 0x81, 0x39, 0x17, 0xdf, 0x62, 0xf6, 0x9c, 0x01, 0xa8, 0x69,
|
||||
0x71, 0xdd, 0x29, 0x7f, 0x47, 0xe6, 0x65, 0xa6, 0x22, 0xe8, 0x6a, 0x12,
|
||||
0x2b, 0xc2, 0x81, 0xff, 0x32, 0x70, 0x2f, 0x9e, 0xca, 0x53, 0x26, 0x47,
|
||||
0x0f, 0x59, 0xd7, 0x9e, 0x2c, 0xa5, 0x07, 0xc4, 0x49, 0x52, 0xa3, 0xe4,
|
||||
0x6b, 0x04, 0x00, 0x25, 0x49, 0xe2, 0xe6, 0x7f, 0x28, 0x78, 0x97, 0xb8,
|
||||
0x3a, 0x32, 0x14, 0x38, 0xa2, 0x51, 0x33, 0x22, 0x44, 0x7e, 0xd7, 0xef,
|
||||
0x45, 0xdb, 0x06, 0x4a, 0xd2, 0x82, 0x4a, 0x82, 0x2c, 0xb1, 0xd7, 0xd8,
|
||||
0xb6, 0x73, 0x00, 0x4d, 0x94, 0x77, 0x94, 0xef
|
||||
};
|
||||
|
||||
static unsigned char out_q[] = {
|
||||
0xd4, 0x0a, 0xac, 0x9f, 0xbd, 0x8c, 0x80, 0xc2, 0x38, 0x7e, 0x2e, 0x0c,
|
||||
0x52, 0x5c, 0xea, 0x34, 0xa1, 0x83, 0x32, 0xf3
|
||||
};
|
||||
|
||||
static unsigned char out_g[] = {
|
||||
0x34, 0x73, 0x8b, 0x57, 0x84, 0x8e, 0x55, 0xbf, 0x57, 0xcc, 0x41, 0xbb,
|
||||
0x5e, 0x2b, 0xd5, 0x42, 0xdd, 0x24, 0x22, 0x2a, 0x09, 0xea, 0x26, 0x1e,
|
||||
0x17, 0x65, 0xcb, 0x1a, 0xb3, 0x12, 0x44, 0xa3, 0x9e, 0x99, 0xe9, 0x63,
|
||||
0xeb, 0x30, 0xb1, 0x78, 0x7b, 0x09, 0x40, 0x30, 0xfa, 0x83, 0xc2, 0x35,
|
||||
0xe1, 0xc4, 0x2d, 0x74, 0x1a, 0xb1, 0x83, 0x54, 0xd8, 0x29, 0xf4, 0xcf,
|
||||
0x7f, 0x6f, 0x67, 0x1c, 0x36, 0x49, 0xee, 0x6c, 0xa2, 0x3c, 0x2d, 0x6a,
|
||||
0xe9, 0xd3, 0x9a, 0xf6, 0x57, 0x78, 0x6f, 0xfd, 0x33, 0xcd, 0x3c, 0xed,
|
||||
0xfd, 0xd4, 0x41, 0xe6, 0x5c, 0x8b, 0xe0, 0x68, 0x31, 0x47, 0x47, 0xaf,
|
||||
0x12, 0xa7, 0xf9, 0x32, 0x0d, 0x94, 0x15, 0x48, 0xd0, 0x54, 0x85, 0xb2,
|
||||
0x04, 0xb5, 0x4d, 0xd4, 0x9d, 0x05, 0x22, 0x25, 0xd9, 0xfd, 0x6c, 0x36,
|
||||
0xef, 0xbe, 0x69, 0x6c, 0x55, 0xf4, 0xee, 0xec
|
||||
};
|
||||
|
||||
static const unsigned char str1[]="12345678901234567890";
|
||||
|
||||
void FIPS_corrupt_dsa()
|
||||
{
|
||||
++seed[0];
|
||||
}
|
||||
|
||||
int FIPS_selftest_dsa()
|
||||
{
|
||||
DSA *dsa=NULL;
|
||||
int counter,i,j, ret = 0;
|
||||
unsigned int slen;
|
||||
unsigned char buf[256];
|
||||
unsigned long h;
|
||||
EVP_MD_CTX mctx;
|
||||
EVP_PKEY pk;
|
||||
|
||||
EVP_MD_CTX_init(&mctx);
|
||||
|
||||
dsa = FIPS_dsa_new();
|
||||
|
||||
if(dsa == NULL)
|
||||
goto err;
|
||||
if(!DSA_generate_parameters_ex(dsa, 1024,seed,20,&counter,&h,NULL))
|
||||
goto err;
|
||||
if (counter != 378)
|
||||
goto err;
|
||||
if (h != 2)
|
||||
goto err;
|
||||
i=BN_bn2bin(dsa->q,buf);
|
||||
j=sizeof(out_q);
|
||||
if (i != j || memcmp(buf,out_q,i) != 0)
|
||||
goto err;
|
||||
|
||||
i=BN_bn2bin(dsa->p,buf);
|
||||
j=sizeof(out_p);
|
||||
if (i != j || memcmp(buf,out_p,i) != 0)
|
||||
goto err;
|
||||
|
||||
i=BN_bn2bin(dsa->g,buf);
|
||||
j=sizeof(out_g);
|
||||
if (i != j || memcmp(buf,out_g,i) != 0)
|
||||
goto err;
|
||||
DSA_generate_key(dsa);
|
||||
pk.type = EVP_PKEY_DSA;
|
||||
pk.pkey.dsa = dsa;
|
||||
|
||||
if (!EVP_SignInit_ex(&mctx, EVP_dss1(), NULL))
|
||||
goto err;
|
||||
if (!EVP_SignUpdate(&mctx, str1, 20))
|
||||
goto err;
|
||||
if (!EVP_SignFinal(&mctx, buf, &slen, &pk))
|
||||
goto err;
|
||||
|
||||
if (!EVP_VerifyInit_ex(&mctx, EVP_dss1(), NULL))
|
||||
goto err;
|
||||
if (!EVP_VerifyUpdate(&mctx, str1, 20))
|
||||
goto err;
|
||||
if (EVP_VerifyFinal(&mctx, buf, slen, &pk) != 1)
|
||||
goto err;
|
||||
|
||||
ret = 1;
|
||||
|
||||
err:
|
||||
EVP_MD_CTX_cleanup(&mctx);
|
||||
if (dsa)
|
||||
FIPS_dsa_free(dsa);
|
||||
if (ret == 0)
|
||||
FIPSerr(FIPS_F_FIPS_SELFTEST_DSA,FIPS_R_SELFTEST_FAILED);
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
|
@ -1,258 +0,0 @@
|
|||
/* fips_dsa_sign.c */
|
||||
/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
|
||||
* project 2007.
|
||||
*/
|
||||
/* ====================================================================
|
||||
* Copyright (c) 2007 The OpenSSL Project. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* 3. All advertising materials mentioning features or use of this
|
||||
* software must display the following acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
|
||||
*
|
||||
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission. For written permission, please contact
|
||||
* licensing@OpenSSL.org.
|
||||
*
|
||||
* 5. Products derived from this software may not be called "OpenSSL"
|
||||
* nor may "OpenSSL" appear in their names without prior written
|
||||
* permission of the OpenSSL Project.
|
||||
*
|
||||
* 6. Redistributions of any form whatsoever must retain the following
|
||||
* acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
|
||||
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
|
||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ====================================================================
|
||||
*
|
||||
* This product includes cryptographic software written by Eric Young
|
||||
* (eay@cryptsoft.com). This product includes software written by Tim
|
||||
* Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <openssl/evp.h>
|
||||
#include <openssl/dsa.h>
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/sha.h>
|
||||
#include <openssl/bn.h>
|
||||
|
||||
#ifdef OPENSSL_FIPS
|
||||
|
||||
/* FIPS versions of DSA_sign() and DSA_verify().
|
||||
* These include a tiny ASN1 encoder/decoder to handle the specific
|
||||
* case of a DSA signature.
|
||||
*/
|
||||
|
||||
#if 0
|
||||
int FIPS_dsa_size(DSA *r)
|
||||
{
|
||||
int ilen;
|
||||
ilen = BN_num_bytes(r->q);
|
||||
if (ilen > 20)
|
||||
return -1;
|
||||
/* If MSB set need padding byte */
|
||||
ilen ++;
|
||||
/* Also need 2 bytes INTEGER header for r and s plus
|
||||
* 2 bytes SEQUENCE header making 6 in total.
|
||||
*/
|
||||
return ilen * 2 + 6;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Tiny ASN1 encoder for DSA_SIG structure. We can assume r, s smaller than
|
||||
* 0x80 octets as by the DSA standards they will be less than 2^160
|
||||
*/
|
||||
|
||||
int FIPS_dsa_sig_encode(unsigned char *out, DSA_SIG *sig)
|
||||
{
|
||||
int rlen, slen, rpad, spad, seqlen;
|
||||
rlen = BN_num_bytes(sig->r);
|
||||
if (rlen > 20)
|
||||
return -1;
|
||||
if (BN_num_bits(sig->r) & 0x7)
|
||||
rpad = 0;
|
||||
else
|
||||
rpad = 1;
|
||||
slen = BN_num_bytes(sig->s);
|
||||
if (slen > 20)
|
||||
return -1;
|
||||
if (BN_num_bits(sig->s) & 0x7)
|
||||
spad = 0;
|
||||
else
|
||||
spad = 1;
|
||||
/* Length of SEQUENCE, (1 tag + 1 len octet) * 2 + content octets */
|
||||
seqlen = rlen + rpad + slen + spad + 4;
|
||||
/* Actual encoded length: include SEQUENCE header */
|
||||
if (!out)
|
||||
return seqlen + 2;
|
||||
|
||||
/* Output SEQUENCE header */
|
||||
*out++ = V_ASN1_SEQUENCE|V_ASN1_CONSTRUCTED;
|
||||
*out++ = (unsigned char)seqlen;
|
||||
|
||||
/* Output r */
|
||||
*out++ = V_ASN1_INTEGER;
|
||||
*out++ = (unsigned char)(rlen + rpad);
|
||||
if (rpad)
|
||||
*out++ = 0;
|
||||
BN_bn2bin(sig->r, out);
|
||||
out += rlen;
|
||||
|
||||
/* Output s */
|
||||
*out++ = V_ASN1_INTEGER;
|
||||
*out++ = (unsigned char)(slen + spad);
|
||||
if (spad)
|
||||
*out++ = 0;
|
||||
BN_bn2bin(sig->s, out);
|
||||
return seqlen + 2;
|
||||
}
|
||||
|
||||
/* Companion DSA_SIG decoder */
|
||||
|
||||
int FIPS_dsa_sig_decode(DSA_SIG *sig, const unsigned char *in, int inlen)
|
||||
{
|
||||
int seqlen, rlen, slen;
|
||||
const unsigned char *rbin;
|
||||
/* Sanity check */
|
||||
|
||||
/* Need SEQUENCE tag */
|
||||
if (*in++ != (V_ASN1_SEQUENCE|V_ASN1_CONSTRUCTED))
|
||||
return 0;
|
||||
/* Get length octet */
|
||||
seqlen = *in++;
|
||||
/* Check sensible length value */
|
||||
if (seqlen < 4 || seqlen > 0x7F)
|
||||
return 0;
|
||||
/* Check INTEGER tag */
|
||||
if (*in++ != V_ASN1_INTEGER)
|
||||
return 0;
|
||||
rlen = *in++;
|
||||
seqlen -= 2 + rlen;
|
||||
/* Check sensible seqlen value */
|
||||
if (seqlen < 2)
|
||||
return 0;
|
||||
rbin = in;
|
||||
in += rlen;
|
||||
/* Check INTEGER tag */
|
||||
if (*in++ != V_ASN1_INTEGER)
|
||||
return 0;
|
||||
slen = *in++;
|
||||
/* Remaining bytes of SEQUENCE should exactly match
|
||||
* encoding of s
|
||||
*/
|
||||
if (seqlen != (slen + 2))
|
||||
return 0;
|
||||
if (!sig->r && !(sig->r = BN_new()))
|
||||
return 0;
|
||||
if (!sig->s && !(sig->s = BN_new()))
|
||||
return 0;
|
||||
if (!BN_bin2bn(rbin, rlen, sig->r))
|
||||
return 0;
|
||||
if (!BN_bin2bn(in, slen, sig->s))
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int fips_dsa_sign(int type, const unsigned char *x, int y,
|
||||
unsigned char *sig, unsigned int *siglen, EVP_MD_SVCTX *sv)
|
||||
{
|
||||
DSA *dsa = sv->key;
|
||||
unsigned char dig[EVP_MAX_MD_SIZE];
|
||||
unsigned int dlen;
|
||||
DSA_SIG *s;
|
||||
EVP_DigestFinal_ex(sv->mctx, dig, &dlen);
|
||||
s=dsa->meth->dsa_do_sign(dig,dlen,dsa);
|
||||
OPENSSL_cleanse(dig, dlen);
|
||||
if (s == NULL)
|
||||
{
|
||||
*siglen=0;
|
||||
return 0;
|
||||
}
|
||||
*siglen= FIPS_dsa_sig_encode(sig, s);
|
||||
DSA_SIG_free(s);
|
||||
if (*siglen < 0)
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int fips_dsa_verify(int type, const unsigned char *x, int y,
|
||||
const unsigned char *sigbuf, unsigned int siglen, EVP_MD_SVCTX *sv)
|
||||
{
|
||||
DSA *dsa = sv->key;
|
||||
DSA_SIG *s;
|
||||
int ret=-1;
|
||||
unsigned char dig[EVP_MAX_MD_SIZE];
|
||||
unsigned int dlen;
|
||||
|
||||
s = DSA_SIG_new();
|
||||
if (s == NULL)
|
||||
return ret;
|
||||
if (!FIPS_dsa_sig_decode(s,sigbuf,siglen))
|
||||
goto err;
|
||||
EVP_DigestFinal_ex(sv->mctx, dig, &dlen);
|
||||
ret=dsa->meth->dsa_do_verify(dig,dlen,s,dsa);
|
||||
OPENSSL_cleanse(dig, dlen);
|
||||
err:
|
||||
DSA_SIG_free(s);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int init(EVP_MD_CTX *ctx)
|
||||
{ return SHA1_Init(ctx->md_data); }
|
||||
|
||||
static int update(EVP_MD_CTX *ctx,const void *data,size_t count)
|
||||
{ return SHA1_Update(ctx->md_data,data,count); }
|
||||
|
||||
static int final(EVP_MD_CTX *ctx,unsigned char *md)
|
||||
{ return SHA1_Final(md,ctx->md_data); }
|
||||
|
||||
static const EVP_MD dss1_md=
|
||||
{
|
||||
NID_dsa,
|
||||
NID_dsaWithSHA1,
|
||||
SHA_DIGEST_LENGTH,
|
||||
EVP_MD_FLAG_FIPS|EVP_MD_FLAG_SVCTX,
|
||||
init,
|
||||
update,
|
||||
final,
|
||||
NULL,
|
||||
NULL,
|
||||
(evp_sign_method *)fips_dsa_sign,
|
||||
(evp_verify_method *)fips_dsa_verify,
|
||||
{EVP_PKEY_DSA,EVP_PKEY_DSA2,EVP_PKEY_DSA3, EVP_PKEY_DSA4,0},
|
||||
SHA_CBLOCK,
|
||||
sizeof(EVP_MD *)+sizeof(SHA_CTX),
|
||||
};
|
||||
|
||||
const EVP_MD *EVP_dss1(void)
|
||||
{
|
||||
return(&dss1_md);
|
||||
}
|
||||
#endif
|
||||
|
|
@ -1,271 +0,0 @@
|
|||
/* crypto/dsa/dsatest.c */
|
||||
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
|
||||
* All rights reserved.
|
||||
*
|
||||
* This package is an SSL implementation written
|
||||
* by Eric Young (eay@cryptsoft.com).
|
||||
* The implementation was written so as to conform with Netscapes SSL.
|
||||
*
|
||||
* This library is free for commercial and non-commercial use as long as
|
||||
* the following conditions are aheared to. The following conditions
|
||||
* apply to all code found in this distribution, be it the RC4, RSA,
|
||||
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
|
||||
* included with this distribution is covered by the same copyright terms
|
||||
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
* Copyright remains Eric Young's, and as such any Copyright notices in
|
||||
* the code are not to be removed.
|
||||
* If this package is used in a product, Eric Young should be given attribution
|
||||
* as the author of the parts of the library used.
|
||||
* This can be in the form of a textual message at program startup or
|
||||
* in documentation (online or textual) provided with the package.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* "This product includes cryptographic software written by
|
||||
* Eric Young (eay@cryptsoft.com)"
|
||||
* The word 'cryptographic' can be left out if the rouines from the library
|
||||
* being used are not cryptographic related :-).
|
||||
* 4. If you include any Windows specific code (or a derivative thereof) from
|
||||
* the apps directory (application code) you must include an acknowledgement:
|
||||
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* The licence and distribution terms for any publically available version or
|
||||
* derivative of this code cannot be changed. i.e. this code cannot simply be
|
||||
* copied and put under another distribution licence
|
||||
* [including the GNU Public Licence.]
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include "e_os.h"
|
||||
|
||||
#include <openssl/crypto.h>
|
||||
#include <openssl/rand.h>
|
||||
#include <openssl/bio.h>
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/bn.h>
|
||||
#ifndef OPENSSL_NO_ENGINE
|
||||
#include <openssl/engine.h>
|
||||
#endif
|
||||
|
||||
|
||||
#if defined(OPENSSL_NO_DSA) || !defined(OPENSSL_FIPS)
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
printf("No FIPS DSA support\n");
|
||||
return(0);
|
||||
}
|
||||
#else
|
||||
#include <openssl/dsa.h>
|
||||
#include <openssl/fips.h>
|
||||
#include <openssl/fips_rand.h>
|
||||
#include <openssl/dsa.h>
|
||||
|
||||
#ifdef OPENSSL_SYS_WIN16
|
||||
#define MS_CALLBACK _far _loadds
|
||||
#else
|
||||
#define MS_CALLBACK
|
||||
#endif
|
||||
|
||||
#include "fips_utl.h"
|
||||
|
||||
static int MS_CALLBACK dsa_cb(int p, int n, BN_GENCB *cb);
|
||||
|
||||
/* seed, out_p, out_q, out_g are taken from the earlier validation test
|
||||
* vectors.
|
||||
*/
|
||||
|
||||
static unsigned char seed[20] = {
|
||||
0x1c, 0xfb, 0xa9, 0x6c, 0xf7, 0x95, 0xb3, 0x2e, 0x01, 0x01, 0x3c, 0x8d,
|
||||
0x7f, 0x6e, 0xf4, 0x59, 0xcc, 0x2f, 0x19, 0x59
|
||||
};
|
||||
|
||||
static unsigned char out_p[] = {
|
||||
0xc2, 0x3c, 0x48, 0x31, 0x7e, 0x3b, 0x4e, 0x5d, 0x3c, 0x93, 0x78, 0x60,
|
||||
0x5c, 0xf2, 0x60, 0xbb, 0x5a, 0xfa, 0x7f, 0x17, 0xf9, 0x26, 0x69, 0x46,
|
||||
0xe7, 0x07, 0xbb, 0x3b, 0x2e, 0xc4, 0xb5, 0x66, 0xf7, 0x4d, 0xae, 0x9b,
|
||||
0x8f, 0xf0, 0x42, 0xea, 0xb3, 0xa0, 0x7e, 0x81, 0x85, 0x89, 0xe6, 0xb0,
|
||||
0x29, 0x03, 0x6b, 0xcc, 0xfb, 0x8e, 0x46, 0x15, 0x4d, 0xc1, 0x69, 0xd8,
|
||||
0x2f, 0xef, 0x5c, 0x8b, 0x29, 0x32, 0x41, 0xbd, 0x13, 0x72, 0x3d, 0xac,
|
||||
0x81, 0xcc, 0x86, 0x6c, 0x06, 0x5d, 0x51, 0xa1, 0xa5, 0x07, 0x0c, 0x3e,
|
||||
0xbe, 0xdd, 0xf4, 0x6e, 0xa8, 0xed, 0xb4, 0x2f, 0xbd, 0x3e, 0x64, 0xea,
|
||||
0xee, 0x92, 0xec, 0x51, 0xe1, 0x0d, 0xab, 0x25, 0x45, 0xae, 0x55, 0x21,
|
||||
0x4d, 0xd6, 0x96, 0x6f, 0xe6, 0xaa, 0xd3, 0xca, 0x87, 0x92, 0xb1, 0x1c,
|
||||
0x3c, 0xaf, 0x29, 0x09, 0x8b, 0xc6, 0xed, 0xe1
|
||||
};
|
||||
|
||||
static unsigned char out_q[] = {
|
||||
0xae, 0x0a, 0x8c, 0xfb, 0x80, 0xe1, 0xc6, 0xd1, 0x09, 0x0f, 0x26, 0xde,
|
||||
0x91, 0x53, 0xc2, 0x8b, 0x2b, 0x0f, 0xde, 0x7f
|
||||
};
|
||||
|
||||
static unsigned char out_g[] = {
|
||||
0x0d, 0x7d, 0x92, 0x74, 0x10, 0xf6, 0xa4, 0x43, 0x86, 0x9a, 0xd1, 0xd9,
|
||||
0x56, 0x00, 0xbc, 0x18, 0x97, 0x99, 0x4e, 0x9a, 0x93, 0xfb, 0x00, 0x3d,
|
||||
0x6c, 0xa0, 0x1b, 0x95, 0x6b, 0xbd, 0xf7, 0x7a, 0xbc, 0x36, 0x3f, 0x3d,
|
||||
0xb9, 0xbf, 0xf9, 0x91, 0x37, 0x68, 0xd1, 0xb9, 0x1e, 0xfe, 0x7f, 0x10,
|
||||
0xc0, 0x6a, 0xcd, 0x5f, 0xc1, 0x65, 0x1a, 0xb8, 0xe7, 0xab, 0xb5, 0xc6,
|
||||
0x8d, 0xb7, 0x86, 0xad, 0x3a, 0xbf, 0x6b, 0x7b, 0x0a, 0x66, 0xbe, 0xd5,
|
||||
0x58, 0x23, 0x16, 0x48, 0x83, 0x29, 0xb6, 0xa7, 0x64, 0xc7, 0x08, 0xbe,
|
||||
0x55, 0x4c, 0x6f, 0xcb, 0x34, 0xc1, 0x73, 0xb0, 0x39, 0x68, 0x52, 0xdf,
|
||||
0x27, 0x7f, 0x32, 0xbc, 0x2b, 0x0d, 0x63, 0xed, 0x75, 0x3e, 0xb5, 0x54,
|
||||
0xac, 0xc8, 0x20, 0x2a, 0x73, 0xe8, 0x29, 0x51, 0x03, 0x77, 0xe8, 0xc9,
|
||||
0x61, 0x32, 0x25, 0xaf, 0x21, 0x5b, 0x6e, 0xda
|
||||
};
|
||||
|
||||
|
||||
static const unsigned char str1[]="12345678901234567890";
|
||||
|
||||
static const char rnd_seed[] = "string to make the random number generator think it has entropy";
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
DSA *dsa=NULL;
|
||||
EVP_PKEY pk;
|
||||
int counter,ret=0,i,j;
|
||||
unsigned int slen;
|
||||
unsigned char buf[256];
|
||||
unsigned long h;
|
||||
BN_GENCB cb;
|
||||
EVP_MD_CTX mctx;
|
||||
BN_GENCB_set(&cb, dsa_cb, stderr);
|
||||
EVP_MD_CTX_init(&mctx);
|
||||
|
||||
if(!FIPS_mode_set(1))
|
||||
{
|
||||
do_print_errors();
|
||||
EXIT(1);
|
||||
}
|
||||
|
||||
fprintf(stderr,"test generation of DSA parameters\n");
|
||||
|
||||
dsa = FIPS_dsa_new();
|
||||
DSA_generate_parameters_ex(dsa, 1024,seed,20,&counter,&h,&cb);
|
||||
|
||||
fprintf(stderr,"seed\n");
|
||||
for (i=0; i<20; i+=4)
|
||||
{
|
||||
fprintf(stderr,"%02X%02X%02X%02X ",
|
||||
seed[i],seed[i+1],seed[i+2],seed[i+3]);
|
||||
}
|
||||
fprintf(stderr,"\ncounter=%d h=%ld\n",counter,h);
|
||||
|
||||
if (dsa == NULL) goto end;
|
||||
if (counter != 16)
|
||||
{
|
||||
fprintf(stderr,"counter should be 105\n");
|
||||
goto end;
|
||||
}
|
||||
if (h != 2)
|
||||
{
|
||||
fprintf(stderr,"h should be 2\n");
|
||||
goto end;
|
||||
}
|
||||
|
||||
i=BN_bn2bin(dsa->q,buf);
|
||||
j=sizeof(out_q);
|
||||
if ((i != j) || (memcmp(buf,out_q,i) != 0))
|
||||
{
|
||||
fprintf(stderr,"q value is wrong\n");
|
||||
goto end;
|
||||
}
|
||||
|
||||
i=BN_bn2bin(dsa->p,buf);
|
||||
j=sizeof(out_p);
|
||||
if ((i != j) || (memcmp(buf,out_p,i) != 0))
|
||||
{
|
||||
fprintf(stderr,"p value is wrong\n");
|
||||
goto end;
|
||||
}
|
||||
|
||||
i=BN_bn2bin(dsa->g,buf);
|
||||
j=sizeof(out_g);
|
||||
if ((i != j) || (memcmp(buf,out_g,i) != 0))
|
||||
{
|
||||
fprintf(stderr,"g value is wrong\n");
|
||||
goto end;
|
||||
}
|
||||
DSA_generate_key(dsa);
|
||||
pk.type = EVP_PKEY_DSA;
|
||||
pk.pkey.dsa = dsa;
|
||||
|
||||
if (!EVP_SignInit_ex(&mctx, EVP_dss1(), NULL))
|
||||
goto end;
|
||||
if (!EVP_SignUpdate(&mctx, str1, 20))
|
||||
goto end;
|
||||
if (!EVP_SignFinal(&mctx, buf, &slen, &pk))
|
||||
goto end;
|
||||
|
||||
if (!EVP_VerifyInit_ex(&mctx, EVP_dss1(), NULL))
|
||||
goto end;
|
||||
if (!EVP_VerifyUpdate(&mctx, str1, 20))
|
||||
goto end;
|
||||
if (EVP_VerifyFinal(&mctx, buf, slen, &pk) != 1)
|
||||
goto end;
|
||||
|
||||
ret = 1;
|
||||
|
||||
end:
|
||||
if (!ret)
|
||||
do_print_errors();
|
||||
if (dsa != NULL) FIPS_dsa_free(dsa);
|
||||
EVP_MD_CTX_cleanup(&mctx);
|
||||
#if 0
|
||||
CRYPTO_mem_leaks(bio_err);
|
||||
#endif
|
||||
EXIT(!ret);
|
||||
return(!ret);
|
||||
}
|
||||
|
||||
static int cb_exit(int ec)
|
||||
{
|
||||
EXIT(ec);
|
||||
return(0); /* To keep some compilers quiet */
|
||||
}
|
||||
|
||||
static int MS_CALLBACK dsa_cb(int p, int n, BN_GENCB *cb)
|
||||
{
|
||||
char c='*';
|
||||
static int ok=0,num=0;
|
||||
|
||||
if (p == 0) { c='.'; num++; };
|
||||
if (p == 1) c='+';
|
||||
if (p == 2) { c='*'; ok++; }
|
||||
if (p == 3) c='\n';
|
||||
fwrite(&c,1, 1, cb->arg);
|
||||
fflush(cb->arg);
|
||||
|
||||
if (!ok && (p == 0) && (num > 1))
|
||||
{
|
||||
fprintf(cb->arg,"error in dsatest\n");
|
||||
cb_exit(1);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
|
@ -1,537 +0,0 @@
|
|||
#include <openssl/opensslconf.h>
|
||||
|
||||
#ifndef OPENSSL_FIPS
|
||||
#include <stdio.h>
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
printf("No FIPS DSA support\n");
|
||||
return(0);
|
||||
}
|
||||
#else
|
||||
|
||||
#include <openssl/bn.h>
|
||||
#include <openssl/dsa.h>
|
||||
#include <openssl/fips.h>
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/evp.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#include "fips_utl.h"
|
||||
|
||||
static void pbn(const char *name, BIGNUM *bn)
|
||||
{
|
||||
int len, i;
|
||||
unsigned char *tmp;
|
||||
len = BN_num_bytes(bn);
|
||||
tmp = OPENSSL_malloc(len);
|
||||
if (!tmp)
|
||||
{
|
||||
fprintf(stderr, "Memory allocation error\n");
|
||||
return;
|
||||
}
|
||||
BN_bn2bin(bn, tmp);
|
||||
printf("%s = ", name);
|
||||
for (i = 0; i < len; i++)
|
||||
printf("%02X", tmp[i]);
|
||||
fputs("\n", stdout);
|
||||
OPENSSL_free(tmp);
|
||||
return;
|
||||
}
|
||||
|
||||
static void primes()
|
||||
{
|
||||
char buf[10240];
|
||||
char lbuf[10240];
|
||||
char *keyword, *value;
|
||||
|
||||
while(fgets(buf,sizeof buf,stdin) != NULL)
|
||||
{
|
||||
fputs(buf,stdout);
|
||||
if (!parse_line(&keyword, &value, lbuf, buf))
|
||||
continue;
|
||||
if(!strcmp(keyword,"Prime"))
|
||||
{
|
||||
BIGNUM *pp;
|
||||
|
||||
pp=BN_new();
|
||||
do_hex2bn(&pp,value);
|
||||
printf("result= %c\n",
|
||||
BN_is_prime_ex(pp,20,NULL,NULL) ? 'P' : 'F');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void pqg()
|
||||
{
|
||||
char buf[1024];
|
||||
char lbuf[1024];
|
||||
char *keyword, *value;
|
||||
int nmod=0;
|
||||
|
||||
while(fgets(buf,sizeof buf,stdin) != NULL)
|
||||
{
|
||||
if (!parse_line(&keyword, &value, lbuf, buf))
|
||||
{
|
||||
fputs(buf,stdout);
|
||||
continue;
|
||||
}
|
||||
if(!strcmp(keyword,"[mod"))
|
||||
nmod=atoi(value);
|
||||
else if(!strcmp(keyword,"N"))
|
||||
{
|
||||
int n=atoi(value);
|
||||
|
||||
printf("[mod = %d]\n\n",nmod);
|
||||
|
||||
while(n--)
|
||||
{
|
||||
unsigned char seed[20];
|
||||
DSA *dsa;
|
||||
int counter;
|
||||
unsigned long h;
|
||||
dsa = FIPS_dsa_new();
|
||||
|
||||
if (!DSA_generate_parameters_ex(dsa, nmod,seed,0,&counter,&h,NULL))
|
||||
{
|
||||
do_print_errors();
|
||||
exit(1);
|
||||
}
|
||||
pbn("P",dsa->p);
|
||||
pbn("Q",dsa->q);
|
||||
pbn("G",dsa->g);
|
||||
pv("Seed",seed,20);
|
||||
printf("c = %d\n",counter);
|
||||
printf("H = %lx\n",h);
|
||||
putc('\n',stdout);
|
||||
}
|
||||
}
|
||||
else
|
||||
fputs(buf,stdout);
|
||||
}
|
||||
}
|
||||
|
||||
static void pqgver()
|
||||
{
|
||||
char buf[1024];
|
||||
char lbuf[1024];
|
||||
char *keyword, *value;
|
||||
BIGNUM *p = NULL, *q = NULL, *g = NULL;
|
||||
int counter, counter2;
|
||||
unsigned long h, h2;
|
||||
DSA *dsa=NULL;
|
||||
int nmod=0;
|
||||
unsigned char seed[1024];
|
||||
|
||||
while(fgets(buf,sizeof buf,stdin) != NULL)
|
||||
{
|
||||
if (!parse_line(&keyword, &value, lbuf, buf))
|
||||
{
|
||||
fputs(buf,stdout);
|
||||
continue;
|
||||
}
|
||||
fputs(buf, stdout);
|
||||
if(!strcmp(keyword,"[mod"))
|
||||
nmod=atoi(value);
|
||||
else if(!strcmp(keyword,"P"))
|
||||
p=hex2bn(value);
|
||||
else if(!strcmp(keyword,"Q"))
|
||||
q=hex2bn(value);
|
||||
else if(!strcmp(keyword,"G"))
|
||||
g=hex2bn(value);
|
||||
else if(!strcmp(keyword,"Seed"))
|
||||
{
|
||||
int slen = hex2bin(value, seed);
|
||||
if (slen != 20)
|
||||
{
|
||||
fprintf(stderr, "Seed parse length error\n");
|
||||
exit (1);
|
||||
}
|
||||
}
|
||||
else if(!strcmp(keyword,"c"))
|
||||
counter =atoi(buf+4);
|
||||
else if(!strcmp(keyword,"H"))
|
||||
{
|
||||
h = atoi(value);
|
||||
if (!p || !q || !g)
|
||||
{
|
||||
fprintf(stderr, "Parse Error\n");
|
||||
exit (1);
|
||||
}
|
||||
dsa = FIPS_dsa_new();
|
||||
if (!DSA_generate_parameters_ex(dsa, nmod,seed,20 ,&counter2,&h2,NULL))
|
||||
{
|
||||
do_print_errors();
|
||||
exit(1);
|
||||
}
|
||||
if (BN_cmp(dsa->p, p) || BN_cmp(dsa->q, q) || BN_cmp(dsa->g, g)
|
||||
|| (counter != counter2) || (h != h2))
|
||||
printf("Result = F\n");
|
||||
else
|
||||
printf("Result = P\n");
|
||||
BN_free(p);
|
||||
BN_free(q);
|
||||
BN_free(g);
|
||||
p = NULL;
|
||||
q = NULL;
|
||||
g = NULL;
|
||||
FIPS_dsa_free(dsa);
|
||||
dsa = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Keypair verification routine. NB: this isn't part of the standard FIPS140-2
|
||||
* algorithm tests. It is an additional test to perform sanity checks on the
|
||||
* output of the KeyPair test.
|
||||
*/
|
||||
|
||||
static int dss_paramcheck(int nmod, BIGNUM *p, BIGNUM *q, BIGNUM *g,
|
||||
BN_CTX *ctx)
|
||||
{
|
||||
BIGNUM *rem = NULL;
|
||||
if (BN_num_bits(p) != nmod)
|
||||
return 0;
|
||||
if (BN_num_bits(q) != 160)
|
||||
return 0;
|
||||
if (BN_is_prime_ex(p, BN_prime_checks, ctx, NULL) != 1)
|
||||
return 0;
|
||||
if (BN_is_prime_ex(q, BN_prime_checks, ctx, NULL) != 1)
|
||||
return 0;
|
||||
rem = BN_new();
|
||||
if (!BN_mod(rem, p, q, ctx) || !BN_is_one(rem)
|
||||
|| (BN_cmp(g, BN_value_one()) <= 0)
|
||||
|| !BN_mod_exp(rem, g, q, p, ctx) || !BN_is_one(rem))
|
||||
{
|
||||
BN_free(rem);
|
||||
return 0;
|
||||
}
|
||||
/* Todo: check g */
|
||||
BN_free(rem);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void keyver()
|
||||
{
|
||||
char buf[1024];
|
||||
char lbuf[1024];
|
||||
char *keyword, *value;
|
||||
BIGNUM *p = NULL, *q = NULL, *g = NULL, *X = NULL, *Y = NULL;
|
||||
BIGNUM *Y2;
|
||||
BN_CTX *ctx = NULL;
|
||||
int nmod=0, paramcheck = 0;
|
||||
|
||||
ctx = BN_CTX_new();
|
||||
Y2 = BN_new();
|
||||
|
||||
while(fgets(buf,sizeof buf,stdin) != NULL)
|
||||
{
|
||||
if (!parse_line(&keyword, &value, lbuf, buf))
|
||||
{
|
||||
fputs(buf,stdout);
|
||||
continue;
|
||||
}
|
||||
if(!strcmp(keyword,"[mod"))
|
||||
{
|
||||
if (p)
|
||||
BN_free(p);
|
||||
p = NULL;
|
||||
if (q)
|
||||
BN_free(q);
|
||||
q = NULL;
|
||||
if (g)
|
||||
BN_free(g);
|
||||
g = NULL;
|
||||
paramcheck = 0;
|
||||
nmod=atoi(value);
|
||||
}
|
||||
else if(!strcmp(keyword,"P"))
|
||||
p=hex2bn(value);
|
||||
else if(!strcmp(keyword,"Q"))
|
||||
q=hex2bn(value);
|
||||
else if(!strcmp(keyword,"G"))
|
||||
g=hex2bn(value);
|
||||
else if(!strcmp(keyword,"X"))
|
||||
X=hex2bn(value);
|
||||
else if(!strcmp(keyword,"Y"))
|
||||
{
|
||||
Y=hex2bn(value);
|
||||
if (!p || !q || !g || !X || !Y)
|
||||
{
|
||||
fprintf(stderr, "Parse Error\n");
|
||||
exit (1);
|
||||
}
|
||||
pbn("P",p);
|
||||
pbn("Q",q);
|
||||
pbn("G",g);
|
||||
pbn("X",X);
|
||||
pbn("Y",Y);
|
||||
if (!paramcheck)
|
||||
{
|
||||
if (dss_paramcheck(nmod, p, q, g, ctx))
|
||||
paramcheck = 1;
|
||||
else
|
||||
paramcheck = -1;
|
||||
}
|
||||
if (paramcheck != 1)
|
||||
printf("Result = F\n");
|
||||
else
|
||||
{
|
||||
if (!BN_mod_exp(Y2, g, X, p, ctx) || BN_cmp(Y2, Y))
|
||||
printf("Result = F\n");
|
||||
else
|
||||
printf("Result = P\n");
|
||||
}
|
||||
BN_free(X);
|
||||
BN_free(Y);
|
||||
X = NULL;
|
||||
Y = NULL;
|
||||
}
|
||||
}
|
||||
if (p)
|
||||
BN_free(p);
|
||||
if (q)
|
||||
BN_free(q);
|
||||
if (g)
|
||||
BN_free(g);
|
||||
if (Y2)
|
||||
BN_free(Y2);
|
||||
}
|
||||
|
||||
static void keypair()
|
||||
{
|
||||
char buf[1024];
|
||||
char lbuf[1024];
|
||||
char *keyword, *value;
|
||||
int nmod=0;
|
||||
|
||||
while(fgets(buf,sizeof buf,stdin) != NULL)
|
||||
{
|
||||
if (!parse_line(&keyword, &value, lbuf, buf))
|
||||
{
|
||||
fputs(buf,stdout);
|
||||
continue;
|
||||
}
|
||||
if(!strcmp(keyword,"[mod"))
|
||||
nmod=atoi(value);
|
||||
else if(!strcmp(keyword,"N"))
|
||||
{
|
||||
DSA *dsa;
|
||||
int n=atoi(value);
|
||||
|
||||
printf("[mod = %d]\n\n",nmod);
|
||||
dsa = FIPS_dsa_new();
|
||||
if (!DSA_generate_parameters_ex(dsa, nmod,NULL,0,NULL,NULL,NULL))
|
||||
{
|
||||
do_print_errors();
|
||||
exit(1);
|
||||
}
|
||||
pbn("P",dsa->p);
|
||||
pbn("Q",dsa->q);
|
||||
pbn("G",dsa->g);
|
||||
putc('\n',stdout);
|
||||
|
||||
while(n--)
|
||||
{
|
||||
if (!DSA_generate_key(dsa))
|
||||
{
|
||||
do_print_errors();
|
||||
exit(1);
|
||||
}
|
||||
|
||||
pbn("X",dsa->priv_key);
|
||||
pbn("Y",dsa->pub_key);
|
||||
putc('\n',stdout);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void siggen()
|
||||
{
|
||||
char buf[1024];
|
||||
char lbuf[1024];
|
||||
char *keyword, *value;
|
||||
int nmod=0;
|
||||
DSA *dsa=NULL;
|
||||
|
||||
while(fgets(buf,sizeof buf,stdin) != NULL)
|
||||
{
|
||||
if (!parse_line(&keyword, &value, lbuf, buf))
|
||||
{
|
||||
fputs(buf,stdout);
|
||||
continue;
|
||||
}
|
||||
if(!strcmp(keyword,"[mod"))
|
||||
{
|
||||
nmod=atoi(value);
|
||||
printf("[mod = %d]\n\n",nmod);
|
||||
if (dsa)
|
||||
FIPS_dsa_free(dsa);
|
||||
dsa = FIPS_dsa_new();
|
||||
if (!DSA_generate_parameters_ex(dsa, nmod,NULL,0,NULL,NULL,NULL))
|
||||
{
|
||||
do_print_errors();
|
||||
exit(1);
|
||||
}
|
||||
pbn("P",dsa->p);
|
||||
pbn("Q",dsa->q);
|
||||
pbn("G",dsa->g);
|
||||
putc('\n',stdout);
|
||||
}
|
||||
else if(!strcmp(keyword,"Msg"))
|
||||
{
|
||||
unsigned char msg[1024];
|
||||
unsigned char sbuf[60];
|
||||
unsigned int slen;
|
||||
int n;
|
||||
EVP_PKEY pk;
|
||||
EVP_MD_CTX mctx;
|
||||
DSA_SIG *sig;
|
||||
EVP_MD_CTX_init(&mctx);
|
||||
|
||||
n=hex2bin(value,msg);
|
||||
pv("Msg",msg,n);
|
||||
|
||||
if (!DSA_generate_key(dsa))
|
||||
{
|
||||
do_print_errors();
|
||||
exit(1);
|
||||
}
|
||||
pk.type = EVP_PKEY_DSA;
|
||||
pk.pkey.dsa = dsa;
|
||||
pbn("Y",dsa->pub_key);
|
||||
|
||||
EVP_SignInit_ex(&mctx, EVP_dss1(), NULL);
|
||||
EVP_SignUpdate(&mctx, msg, n);
|
||||
EVP_SignFinal(&mctx, sbuf, &slen, &pk);
|
||||
|
||||
sig = DSA_SIG_new();
|
||||
FIPS_dsa_sig_decode(sig, sbuf, slen);
|
||||
|
||||
pbn("R",sig->r);
|
||||
pbn("S",sig->s);
|
||||
putc('\n',stdout);
|
||||
DSA_SIG_free(sig);
|
||||
EVP_MD_CTX_cleanup(&mctx);
|
||||
}
|
||||
}
|
||||
if (dsa)
|
||||
FIPS_dsa_free(dsa);
|
||||
}
|
||||
|
||||
static void sigver()
|
||||
{
|
||||
DSA *dsa=NULL;
|
||||
char buf[1024];
|
||||
char lbuf[1024];
|
||||
unsigned char msg[1024];
|
||||
char *keyword, *value;
|
||||
int nmod=0, n=0;
|
||||
DSA_SIG sg, *sig = &sg;
|
||||
|
||||
sig->r = NULL;
|
||||
sig->s = NULL;
|
||||
|
||||
while(fgets(buf,sizeof buf,stdin) != NULL)
|
||||
{
|
||||
if (!parse_line(&keyword, &value, lbuf, buf))
|
||||
{
|
||||
fputs(buf,stdout);
|
||||
continue;
|
||||
}
|
||||
if(!strcmp(keyword,"[mod"))
|
||||
{
|
||||
nmod=atoi(value);
|
||||
if(dsa)
|
||||
FIPS_dsa_free(dsa);
|
||||
dsa=FIPS_dsa_new();
|
||||
}
|
||||
else if(!strcmp(keyword,"P"))
|
||||
dsa->p=hex2bn(value);
|
||||
else if(!strcmp(keyword,"Q"))
|
||||
dsa->q=hex2bn(value);
|
||||
else if(!strcmp(keyword,"G"))
|
||||
{
|
||||
dsa->g=hex2bn(value);
|
||||
|
||||
printf("[mod = %d]\n\n",nmod);
|
||||
pbn("P",dsa->p);
|
||||
pbn("Q",dsa->q);
|
||||
pbn("G",dsa->g);
|
||||
putc('\n',stdout);
|
||||
}
|
||||
else if(!strcmp(keyword,"Msg"))
|
||||
{
|
||||
n=hex2bin(value,msg);
|
||||
pv("Msg",msg,n);
|
||||
}
|
||||
else if(!strcmp(keyword,"Y"))
|
||||
dsa->pub_key=hex2bn(value);
|
||||
else if(!strcmp(keyword,"R"))
|
||||
sig->r=hex2bn(value);
|
||||
else if(!strcmp(keyword,"S"))
|
||||
{
|
||||
EVP_MD_CTX mctx;
|
||||
EVP_PKEY pk;
|
||||
unsigned char sigbuf[60];
|
||||
unsigned int slen;
|
||||
int r;
|
||||
EVP_MD_CTX_init(&mctx);
|
||||
pk.type = EVP_PKEY_DSA;
|
||||
pk.pkey.dsa = dsa;
|
||||
sig->s=hex2bn(value);
|
||||
|
||||
pbn("Y",dsa->pub_key);
|
||||
pbn("R",sig->r);
|
||||
pbn("S",sig->s);
|
||||
|
||||
slen = FIPS_dsa_sig_encode(sigbuf, sig);
|
||||
EVP_VerifyInit_ex(&mctx, EVP_dss1(), NULL);
|
||||
EVP_VerifyUpdate(&mctx, msg, n);
|
||||
r = EVP_VerifyFinal(&mctx, sigbuf, slen, &pk);
|
||||
EVP_MD_CTX_cleanup(&mctx);
|
||||
|
||||
printf("Result = %c\n", r == 1 ? 'P' : 'F');
|
||||
putc('\n',stdout);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc,char **argv)
|
||||
{
|
||||
if(argc != 2)
|
||||
{
|
||||
fprintf(stderr,"%s [prime|pqg|pqgver|keypair|siggen|sigver]\n",argv[0]);
|
||||
exit(1);
|
||||
}
|
||||
if(!FIPS_mode_set(1))
|
||||
{
|
||||
do_print_errors();
|
||||
exit(1);
|
||||
}
|
||||
if(!strcmp(argv[1],"prime"))
|
||||
primes();
|
||||
else if(!strcmp(argv[1],"pqg"))
|
||||
pqg();
|
||||
else if(!strcmp(argv[1],"pqgver"))
|
||||
pqgver();
|
||||
else if(!strcmp(argv[1],"keypair"))
|
||||
keypair();
|
||||
else if(!strcmp(argv[1],"keyver"))
|
||||
keyver();
|
||||
else if(!strcmp(argv[1],"siggen"))
|
||||
siggen();
|
||||
else if(!strcmp(argv[1],"sigver"))
|
||||
sigver();
|
||||
else
|
||||
{
|
||||
fprintf(stderr,"Don't know how to %s.\n",argv[1]);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -1,7 +0,0 @@
|
|||
KeyPair.rsp
|
||||
PQGGen.rsp
|
||||
SigGen.rsp
|
||||
SigGen15.rsp
|
||||
SigGenPSS.rsp
|
||||
SigGenRSA.rsp
|
||||
SigGenPSS.rsp
|
||||
|
|
@ -1,519 +0,0 @@
|
|||
/* ====================================================================
|
||||
* Copyright (c) 2003 The OpenSSL Project. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* 3. All advertising materials mentioning features or use of this
|
||||
* software must display the following acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
|
||||
*
|
||||
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission. For written permission, please contact
|
||||
* openssl-core@openssl.org.
|
||||
*
|
||||
* 5. Products derived from this software may not be called "OpenSSL"
|
||||
* nor may "OpenSSL" appear in their names without prior written
|
||||
* permission of the OpenSSL Project.
|
||||
*
|
||||
* 6. Redistributions of any form whatsoever must retain the following
|
||||
* acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit (http://www.openssl.org/)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
|
||||
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
|
||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include <openssl/rand.h>
|
||||
#include <openssl/fips_rand.h>
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/bio.h>
|
||||
#include <openssl/hmac.h>
|
||||
#include <openssl/rsa.h>
|
||||
#include <string.h>
|
||||
#include <limits.h>
|
||||
#include "fips_locl.h"
|
||||
|
||||
#ifdef OPENSSL_FIPS
|
||||
|
||||
#include <openssl/fips.h>
|
||||
|
||||
#ifndef PATH_MAX
|
||||
#define PATH_MAX 1024
|
||||
#endif
|
||||
|
||||
static int fips_selftest_fail;
|
||||
static int fips_mode;
|
||||
static const void *fips_rand_check;
|
||||
|
||||
static void fips_set_mode(int onoff)
|
||||
{
|
||||
int owning_thread = fips_is_owning_thread();
|
||||
|
||||
if (fips_is_started())
|
||||
{
|
||||
if (!owning_thread) fips_w_lock();
|
||||
fips_mode = onoff;
|
||||
if (!owning_thread) fips_w_unlock();
|
||||
}
|
||||
}
|
||||
|
||||
static void fips_set_rand_check(const void *rand_check)
|
||||
{
|
||||
int owning_thread = fips_is_owning_thread();
|
||||
|
||||
if (fips_is_started())
|
||||
{
|
||||
if (!owning_thread) fips_w_lock();
|
||||
fips_rand_check = rand_check;
|
||||
if (!owning_thread) fips_w_unlock();
|
||||
}
|
||||
}
|
||||
|
||||
int FIPS_mode(void)
|
||||
{
|
||||
int ret = 0;
|
||||
int owning_thread = fips_is_owning_thread();
|
||||
|
||||
if (fips_is_started())
|
||||
{
|
||||
if (!owning_thread) fips_r_lock();
|
||||
ret = fips_mode;
|
||||
if (!owning_thread) fips_r_unlock();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
const void *FIPS_rand_check(void)
|
||||
{
|
||||
const void *ret = 0;
|
||||
int owning_thread = fips_is_owning_thread();
|
||||
|
||||
if (fips_is_started())
|
||||
{
|
||||
if (!owning_thread) fips_r_lock();
|
||||
ret = fips_rand_check;
|
||||
if (!owning_thread) fips_r_unlock();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int FIPS_selftest_failed(void)
|
||||
{
|
||||
int ret = 0;
|
||||
if (fips_is_started())
|
||||
{
|
||||
int owning_thread = fips_is_owning_thread();
|
||||
|
||||
if (!owning_thread) fips_r_lock();
|
||||
ret = fips_selftest_fail;
|
||||
if (!owning_thread) fips_r_unlock();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Selftest failure fatal exit routine. This will be called
|
||||
* during *any* cryptographic operation. It has the minimum
|
||||
* overhead possible to avoid too big a performance hit.
|
||||
*/
|
||||
|
||||
void FIPS_selftest_check(void)
|
||||
{
|
||||
if (fips_selftest_fail)
|
||||
{
|
||||
OpenSSLDie(__FILE__,__LINE__, "FATAL FIPS SELFTEST FAILURE");
|
||||
}
|
||||
}
|
||||
|
||||
void fips_set_selftest_fail(void)
|
||||
{
|
||||
fips_selftest_fail = 1;
|
||||
}
|
||||
|
||||
int FIPS_selftest()
|
||||
{
|
||||
|
||||
return FIPS_selftest_sha1()
|
||||
&& FIPS_selftest_hmac()
|
||||
&& FIPS_selftest_aes()
|
||||
&& FIPS_selftest_des()
|
||||
&& FIPS_selftest_rsa()
|
||||
&& FIPS_selftest_dsa();
|
||||
}
|
||||
|
||||
extern const void *FIPS_text_start(), *FIPS_text_end();
|
||||
extern const unsigned char FIPS_rodata_start[], FIPS_rodata_end[];
|
||||
unsigned char FIPS_signature [20] = { 0 };
|
||||
static const char FIPS_hmac_key[]="etaonrishdlcupfm";
|
||||
|
||||
unsigned int FIPS_incore_fingerprint(unsigned char *sig,unsigned int len)
|
||||
{
|
||||
const unsigned char *p1 = FIPS_text_start();
|
||||
const unsigned char *p2 = FIPS_text_end();
|
||||
const unsigned char *p3 = FIPS_rodata_start;
|
||||
const unsigned char *p4 = FIPS_rodata_end;
|
||||
HMAC_CTX c;
|
||||
|
||||
HMAC_CTX_init(&c);
|
||||
HMAC_Init(&c,FIPS_hmac_key,strlen(FIPS_hmac_key),EVP_sha1());
|
||||
|
||||
/* detect overlapping regions */
|
||||
if (p1<=p3 && p2>=p3)
|
||||
p3=p1, p4=p2>p4?p2:p4, p1=NULL, p2=NULL;
|
||||
else if (p3<=p1 && p4>=p1)
|
||||
p3=p3, p4=p2>p4?p2:p4, p1=NULL, p2=NULL;
|
||||
|
||||
if (p1)
|
||||
HMAC_Update(&c,p1,(size_t)p2-(size_t)p1);
|
||||
|
||||
if (FIPS_signature>=p3 && FIPS_signature<p4)
|
||||
{
|
||||
/* "punch" hole */
|
||||
HMAC_Update(&c,p3,(size_t)FIPS_signature-(size_t)p3);
|
||||
p3 = FIPS_signature+sizeof(FIPS_signature);
|
||||
if (p3<p4)
|
||||
HMAC_Update(&c,p3,(size_t)p4-(size_t)p3);
|
||||
}
|
||||
else
|
||||
HMAC_Update(&c,p3,(size_t)p4-(size_t)p3);
|
||||
|
||||
HMAC_Final(&c,sig,&len);
|
||||
HMAC_CTX_cleanup(&c);
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
int FIPS_check_incore_fingerprint(void)
|
||||
{
|
||||
unsigned char sig[EVP_MAX_MD_SIZE];
|
||||
unsigned int len;
|
||||
#if defined(__sgi) && (defined(__mips) || defined(mips))
|
||||
extern int __dso_displacement[];
|
||||
#else
|
||||
extern int OPENSSL_NONPIC_relocated;
|
||||
#endif
|
||||
|
||||
if (FIPS_text_start()==NULL)
|
||||
{
|
||||
FIPSerr(FIPS_F_FIPS_CHECK_INCORE_FINGERPRINT,FIPS_R_UNSUPPORTED_PLATFORM);
|
||||
return 0;
|
||||
}
|
||||
|
||||
len=FIPS_incore_fingerprint (sig,sizeof(sig));
|
||||
|
||||
if (len!=sizeof(FIPS_signature) ||
|
||||
memcmp(FIPS_signature,sig,sizeof(FIPS_signature)))
|
||||
{
|
||||
if (FIPS_signature>=FIPS_rodata_start && FIPS_signature<FIPS_rodata_end)
|
||||
FIPSerr(FIPS_F_FIPS_CHECK_INCORE_FINGERPRINT,FIPS_R_FINGERPRINT_DOES_NOT_MATCH_SEGMENT_ALIASING);
|
||||
#if defined(__sgi) && (defined(__mips) || defined(mips))
|
||||
else if (__dso_displacement!=NULL)
|
||||
#else
|
||||
else if (OPENSSL_NONPIC_relocated)
|
||||
#endif
|
||||
FIPSerr(FIPS_F_FIPS_CHECK_INCORE_FINGERPRINT,FIPS_R_FINGERPRINT_DOES_NOT_MATCH_NONPIC_RELOCATED);
|
||||
else
|
||||
FIPSerr(FIPS_F_FIPS_CHECK_INCORE_FINGERPRINT,FIPS_R_FINGERPRINT_DOES_NOT_MATCH);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int FIPS_mode_set(int onoff)
|
||||
{
|
||||
int fips_set_owning_thread();
|
||||
int fips_clear_owning_thread();
|
||||
int ret = 0;
|
||||
|
||||
fips_w_lock();
|
||||
fips_set_started();
|
||||
fips_set_owning_thread();
|
||||
|
||||
if(onoff)
|
||||
{
|
||||
unsigned char buf[48];
|
||||
|
||||
fips_selftest_fail = 0;
|
||||
|
||||
/* Don't go into FIPS mode twice, just so we can do automagic
|
||||
seeding */
|
||||
if(FIPS_mode())
|
||||
{
|
||||
FIPSerr(FIPS_F_FIPS_MODE_SET,FIPS_R_FIPS_MODE_ALREADY_SET);
|
||||
fips_selftest_fail = 1;
|
||||
ret = 0;
|
||||
goto end;
|
||||
}
|
||||
|
||||
#ifdef OPENSSL_IA32_SSE2
|
||||
if ((OPENSSL_ia32cap & (1<<25|1<<26)) != (1<<25|1<<26))
|
||||
{
|
||||
FIPSerr(FIPS_F_FIPS_MODE_SET,FIPS_R_UNSUPPORTED_PLATFORM);
|
||||
fips_selftest_fail = 1;
|
||||
ret = 0;
|
||||
goto end;
|
||||
}
|
||||
#endif
|
||||
|
||||
if(fips_signature_witness() != FIPS_signature)
|
||||
{
|
||||
FIPSerr(FIPS_F_FIPS_MODE_SET,FIPS_R_CONTRADICTING_EVIDENCE);
|
||||
fips_selftest_fail = 1;
|
||||
ret = 0;
|
||||
goto end;
|
||||
}
|
||||
|
||||
if(!FIPS_check_incore_fingerprint())
|
||||
{
|
||||
fips_selftest_fail = 1;
|
||||
ret = 0;
|
||||
goto end;
|
||||
}
|
||||
|
||||
/* Perform RNG KAT before seeding */
|
||||
if (!FIPS_selftest_rng())
|
||||
{
|
||||
fips_selftest_fail = 1;
|
||||
ret = 0;
|
||||
goto end;
|
||||
}
|
||||
|
||||
/* automagically seed PRNG if not already seeded */
|
||||
if(!FIPS_rand_status())
|
||||
{
|
||||
if(RAND_bytes(buf,sizeof buf) <= 0)
|
||||
{
|
||||
fips_selftest_fail = 1;
|
||||
ret = 0;
|
||||
goto end;
|
||||
}
|
||||
FIPS_rand_set_key(buf,32);
|
||||
FIPS_rand_seed(buf+32,16);
|
||||
}
|
||||
|
||||
/* now switch into FIPS mode */
|
||||
fips_set_rand_check(FIPS_rand_method());
|
||||
RAND_set_rand_method(FIPS_rand_method());
|
||||
if(FIPS_selftest())
|
||||
fips_set_mode(1);
|
||||
else
|
||||
{
|
||||
fips_selftest_fail = 1;
|
||||
ret = 0;
|
||||
goto end;
|
||||
}
|
||||
ret = 1;
|
||||
goto end;
|
||||
}
|
||||
fips_set_mode(0);
|
||||
fips_selftest_fail = 0;
|
||||
ret = 1;
|
||||
end:
|
||||
fips_clear_owning_thread();
|
||||
fips_w_unlock();
|
||||
return ret;
|
||||
}
|
||||
|
||||
void fips_w_lock(void) { CRYPTO_w_lock(CRYPTO_LOCK_FIPS); }
|
||||
void fips_w_unlock(void) { CRYPTO_w_unlock(CRYPTO_LOCK_FIPS); }
|
||||
void fips_r_lock(void) { CRYPTO_r_lock(CRYPTO_LOCK_FIPS); }
|
||||
void fips_r_unlock(void) { CRYPTO_r_unlock(CRYPTO_LOCK_FIPS); }
|
||||
|
||||
static int fips_started = 0;
|
||||
static unsigned long fips_thread = 0;
|
||||
|
||||
void fips_set_started(void)
|
||||
{
|
||||
fips_started = 1;
|
||||
}
|
||||
|
||||
int fips_is_started(void)
|
||||
{
|
||||
return fips_started;
|
||||
}
|
||||
|
||||
int fips_is_owning_thread(void)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
if (fips_is_started())
|
||||
{
|
||||
CRYPTO_r_lock(CRYPTO_LOCK_FIPS2);
|
||||
if (fips_thread != 0 && fips_thread == CRYPTO_thread_id())
|
||||
ret = 1;
|
||||
CRYPTO_r_unlock(CRYPTO_LOCK_FIPS2);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int fips_set_owning_thread(void)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
if (fips_is_started())
|
||||
{
|
||||
CRYPTO_w_lock(CRYPTO_LOCK_FIPS2);
|
||||
if (fips_thread == 0)
|
||||
{
|
||||
fips_thread = CRYPTO_thread_id();
|
||||
ret = 1;
|
||||
}
|
||||
CRYPTO_w_unlock(CRYPTO_LOCK_FIPS2);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int fips_clear_owning_thread(void)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
if (fips_is_started())
|
||||
{
|
||||
CRYPTO_w_lock(CRYPTO_LOCK_FIPS2);
|
||||
if (fips_thread == CRYPTO_thread_id())
|
||||
{
|
||||
fips_thread = 0;
|
||||
ret = 1;
|
||||
}
|
||||
CRYPTO_w_unlock(CRYPTO_LOCK_FIPS2);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
unsigned char *fips_signature_witness(void)
|
||||
{
|
||||
extern unsigned char FIPS_signature[];
|
||||
return FIPS_signature;
|
||||
}
|
||||
|
||||
/* Generalized public key test routine. Signs and verifies the data
|
||||
* supplied in tbs using mesage digest md and setting option digest
|
||||
* flags md_flags. If the 'kat' parameter is not NULL it will
|
||||
* additionally check the signature matches it: a known answer test
|
||||
* The string "fail_str" is used for identification purposes in case
|
||||
* of failure.
|
||||
*/
|
||||
|
||||
int fips_pkey_signature_test(EVP_PKEY *pkey,
|
||||
const unsigned char *tbs, int tbslen,
|
||||
const unsigned char *kat, unsigned int katlen,
|
||||
const EVP_MD *digest, unsigned int md_flags,
|
||||
const char *fail_str)
|
||||
{
|
||||
int ret = 0;
|
||||
unsigned char sigtmp[256], *sig = sigtmp;
|
||||
unsigned int siglen;
|
||||
EVP_MD_CTX mctx;
|
||||
EVP_MD_CTX_init(&mctx);
|
||||
|
||||
if ((pkey->type == EVP_PKEY_RSA)
|
||||
&& (RSA_size(pkey->pkey.rsa) > sizeof(sigtmp)))
|
||||
{
|
||||
sig = OPENSSL_malloc(RSA_size(pkey->pkey.rsa));
|
||||
if (!sig)
|
||||
{
|
||||
FIPSerr(FIPS_F_FIPS_PKEY_SIGNATURE_TEST,ERR_R_MALLOC_FAILURE);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (tbslen == -1)
|
||||
tbslen = strlen((char *)tbs);
|
||||
|
||||
if (md_flags)
|
||||
M_EVP_MD_CTX_set_flags(&mctx, md_flags);
|
||||
|
||||
if (!EVP_SignInit_ex(&mctx, digest, NULL))
|
||||
goto error;
|
||||
if (!EVP_SignUpdate(&mctx, tbs, tbslen))
|
||||
goto error;
|
||||
if (!EVP_SignFinal(&mctx, sig, &siglen, pkey))
|
||||
goto error;
|
||||
|
||||
if (kat && ((siglen != katlen) || memcmp(kat, sig, katlen)))
|
||||
goto error;
|
||||
|
||||
if (!EVP_VerifyInit_ex(&mctx, digest, NULL))
|
||||
goto error;
|
||||
if (!EVP_VerifyUpdate(&mctx, tbs, tbslen))
|
||||
goto error;
|
||||
ret = EVP_VerifyFinal(&mctx, sig, siglen, pkey);
|
||||
|
||||
error:
|
||||
if (sig != sigtmp)
|
||||
OPENSSL_free(sig);
|
||||
EVP_MD_CTX_cleanup(&mctx);
|
||||
if (ret != 1)
|
||||
{
|
||||
FIPSerr(FIPS_F_FIPS_PKEY_SIGNATURE_TEST,FIPS_R_TEST_FAILURE);
|
||||
if (fail_str)
|
||||
ERR_add_error_data(2, "Type=", fail_str);
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Generalized symmetric cipher test routine. Encrypt data, verify result
|
||||
* against known answer, decrypt and compare with original plaintext.
|
||||
*/
|
||||
|
||||
int fips_cipher_test(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher,
|
||||
const unsigned char *key,
|
||||
const unsigned char *iv,
|
||||
const unsigned char *plaintext,
|
||||
const unsigned char *ciphertext,
|
||||
int len)
|
||||
{
|
||||
unsigned char pltmp[FIPS_MAX_CIPHER_TEST_SIZE];
|
||||
unsigned char citmp[FIPS_MAX_CIPHER_TEST_SIZE];
|
||||
OPENSSL_assert(len <= FIPS_MAX_CIPHER_TEST_SIZE);
|
||||
if (EVP_CipherInit_ex(ctx, cipher, NULL, key, iv, 1) <= 0)
|
||||
return 0;
|
||||
EVP_Cipher(ctx, citmp, plaintext, len);
|
||||
if (memcmp(citmp, ciphertext, len))
|
||||
return 0;
|
||||
if (EVP_CipherInit_ex(ctx, cipher, NULL, key, iv, 0) <= 0)
|
||||
return 0;
|
||||
EVP_Cipher(ctx, pltmp, citmp, len);
|
||||
if (memcmp(pltmp, plaintext, len))
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
#if 0
|
||||
/* The purpose of this is to ensure the error code exists and the function
|
||||
* name is to keep the error checking script quiet
|
||||
*/
|
||||
void hash_final(void)
|
||||
{
|
||||
FIPSerr(FIPS_F_HASH_FINAL,FIPS_R_NON_FIPS_METHOD);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
||||
|
|
@ -1,163 +0,0 @@
|
|||
/* ====================================================================
|
||||
* Copyright (c) 2003 The OpenSSL Project. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* 3. All advertising materials mentioning features or use of this
|
||||
* software must display the following acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
|
||||
*
|
||||
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission. For written permission, please contact
|
||||
* openssl-core@openssl.org.
|
||||
*
|
||||
* 5. Products derived from this software may not be called "OpenSSL"
|
||||
* nor may "OpenSSL" appear in their names without prior written
|
||||
* permission of the OpenSSL Project.
|
||||
*
|
||||
* 6. Redistributions of any form whatsoever must retain the following
|
||||
* acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit (http://www.openssl.org/)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
|
||||
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
|
||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <openssl/opensslconf.h>
|
||||
|
||||
#ifndef OPENSSL_FIPS
|
||||
#error FIPS is disabled.
|
||||
#endif
|
||||
|
||||
#ifdef OPENSSL_FIPS
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct dsa_st;
|
||||
struct evp_pkey_st;
|
||||
struct env_md_st;
|
||||
struct evp_cipher_st;
|
||||
struct evp_cipher_ctx_st;
|
||||
|
||||
int FIPS_mode_set(int onoff);
|
||||
int FIPS_mode(void);
|
||||
const void *FIPS_rand_check(void);
|
||||
int FIPS_selftest_failed(void);
|
||||
void FIPS_selftest_check(void);
|
||||
void FIPS_corrupt_sha1(void);
|
||||
int FIPS_selftest_sha1(void);
|
||||
void FIPS_corrupt_aes(void);
|
||||
int FIPS_selftest_aes(void);
|
||||
void FIPS_corrupt_des(void);
|
||||
int FIPS_selftest_des(void);
|
||||
void FIPS_corrupt_rsa(void);
|
||||
void FIPS_corrupt_rsa_keygen(void);
|
||||
int FIPS_selftest_rsa(void);
|
||||
void FIPS_corrupt_dsa(void);
|
||||
void FIPS_corrupt_dsa_keygen(void);
|
||||
int FIPS_selftest_dsa(void);
|
||||
void FIPS_corrupt_rng(void);
|
||||
void FIPS_rng_stick(void);
|
||||
int FIPS_selftest_rng(void);
|
||||
int FIPS_selftest_hmac(void);
|
||||
|
||||
int fips_pkey_signature_test(struct evp_pkey_st *pkey,
|
||||
const unsigned char *tbs, int tbslen,
|
||||
const unsigned char *kat, unsigned int katlen,
|
||||
const struct env_md_st *digest, unsigned int md_flags,
|
||||
const char *fail_str);
|
||||
|
||||
int fips_cipher_test(struct evp_cipher_ctx_st *ctx,
|
||||
const struct evp_cipher_st *cipher,
|
||||
const unsigned char *key,
|
||||
const unsigned char *iv,
|
||||
const unsigned char *plaintext,
|
||||
const unsigned char *ciphertext,
|
||||
int len);
|
||||
|
||||
/* BEGIN ERROR CODES */
|
||||
/* The following lines are auto generated by the script mkerr.pl. Any changes
|
||||
* made after this point may be overwritten when the script is next run.
|
||||
*/
|
||||
void ERR_load_FIPS_strings(void);
|
||||
|
||||
/* Error codes for the FIPS functions. */
|
||||
|
||||
/* Function codes. */
|
||||
#define FIPS_F_DH_BUILTIN_GENPARAMS 100
|
||||
#define FIPS_F_DSA_BUILTIN_PARAMGEN 101
|
||||
#define FIPS_F_DSA_DO_SIGN 102
|
||||
#define FIPS_F_DSA_DO_VERIFY 103
|
||||
#define FIPS_F_EVP_CIPHERINIT_EX 124
|
||||
#define FIPS_F_EVP_DIGESTINIT_EX 125
|
||||
#define FIPS_F_FIPS_CHECK_DSA 104
|
||||
#define FIPS_F_FIPS_CHECK_INCORE_FINGERPRINT 105
|
||||
#define FIPS_F_FIPS_CHECK_RSA 106
|
||||
#define FIPS_F_FIPS_DSA_CHECK 107
|
||||
#define FIPS_F_FIPS_MODE_SET 108
|
||||
#define FIPS_F_FIPS_PKEY_SIGNATURE_TEST 109
|
||||
#define FIPS_F_FIPS_SELFTEST_AES 110
|
||||
#define FIPS_F_FIPS_SELFTEST_DES 111
|
||||
#define FIPS_F_FIPS_SELFTEST_DSA 112
|
||||
#define FIPS_F_FIPS_SELFTEST_HMAC 113
|
||||
#define FIPS_F_FIPS_SELFTEST_RNG 114
|
||||
#define FIPS_F_FIPS_SELFTEST_SHA1 115
|
||||
#define FIPS_F_HASH_FINAL 123
|
||||
#define FIPS_F_RSA_BUILTIN_KEYGEN 116
|
||||
#define FIPS_F_RSA_EAY_PRIVATE_DECRYPT 117
|
||||
#define FIPS_F_RSA_EAY_PRIVATE_ENCRYPT 118
|
||||
#define FIPS_F_RSA_EAY_PUBLIC_DECRYPT 119
|
||||
#define FIPS_F_RSA_EAY_PUBLIC_ENCRYPT 120
|
||||
#define FIPS_F_RSA_X931_GENERATE_KEY_EX 121
|
||||
#define FIPS_F_SSLEAY_RAND_BYTES 122
|
||||
|
||||
/* Reason codes. */
|
||||
#define FIPS_R_CANNOT_READ_EXE 103
|
||||
#define FIPS_R_CANNOT_READ_EXE_DIGEST 104
|
||||
#define FIPS_R_CONTRADICTING_EVIDENCE 114
|
||||
#define FIPS_R_EXE_DIGEST_DOES_NOT_MATCH 105
|
||||
#define FIPS_R_FINGERPRINT_DOES_NOT_MATCH 110
|
||||
#define FIPS_R_FINGERPRINT_DOES_NOT_MATCH_NONPIC_RELOCATED 111
|
||||
#define FIPS_R_FINGERPRINT_DOES_NOT_MATCH_SEGMENT_ALIASING 112
|
||||
#define FIPS_R_FIPS_MODE_ALREADY_SET 102
|
||||
#define FIPS_R_FIPS_SELFTEST_FAILED 106
|
||||
#define FIPS_R_INVALID_KEY_LENGTH 109
|
||||
#define FIPS_R_KEY_TOO_SHORT 108
|
||||
#define FIPS_R_NON_FIPS_METHOD 100
|
||||
#define FIPS_R_PAIRWISE_TEST_FAILED 107
|
||||
#define FIPS_R_RSA_DECRYPT_ERROR 115
|
||||
#define FIPS_R_RSA_ENCRYPT_ERROR 116
|
||||
#define FIPS_R_SELFTEST_FAILED 101
|
||||
#define FIPS_R_TEST_FAILURE 117
|
||||
#define FIPS_R_UNSUPPORTED_PLATFORM 113
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
|
@ -1,187 +0,0 @@
|
|||
/* ====================================================================
|
||||
* Copyright (c) 2005 The OpenSSL Project. Rights for redistribution
|
||||
* and usage in source and binary forms are granted according to the
|
||||
* OpenSSL license.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#if defined(__DECC)
|
||||
# include <c_asm.h>
|
||||
# pragma __nostandard
|
||||
#endif
|
||||
|
||||
#include "e_os.h"
|
||||
|
||||
#if !defined(POINTER_TO_FUNCTION_IS_POINTER_TO_1ST_INSTRUCTION)
|
||||
# if (defined(__sun) && (defined(__sparc) || defined(__sparcv9))) || \
|
||||
(defined(__sgi) && (defined(__mips) || defined(mips))) || \
|
||||
(defined(__osf__) && defined(__alpha)) || \
|
||||
(defined(__linux) && (defined(__arm) || defined(__arm__))) || \
|
||||
(defined(__i386) || defined(__i386__)) || \
|
||||
(defined(__x86_64) || defined(__x86_64__)) || \
|
||||
defined(__ANDROID__) || \
|
||||
(defined(vax) || defined(__vax__))
|
||||
# define POINTER_TO_FUNCTION_IS_POINTER_TO_1ST_INSTRUCTION
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if defined(__xlC__) && __xlC__>=0x600 && (defined(_POWER) || defined(_ARCH_PPC))
|
||||
static void *instruction_pointer_xlc(void);
|
||||
# pragma mc_func instruction_pointer_xlc {\
|
||||
"7c0802a6" /* mflr r0 */ \
|
||||
"48000005" /* bl $+4 */ \
|
||||
"7c6802a6" /* mflr r3 */ \
|
||||
"7c0803a6" /* mtlr r0 */ }
|
||||
# pragma reg_killed_by instruction_pointer_xlc gr0 gr3
|
||||
# define INSTRUCTION_POINTER_IMPLEMENTED(ret) (ret=instruction_pointer_xlc());
|
||||
#endif
|
||||
|
||||
#ifdef FIPS_START
|
||||
#define FIPS_ref_point FIPS_text_start
|
||||
/* Some compilers put string literals into a separate segment. As we
|
||||
* are mostly interested to hash AES tables in .rodata, we declare
|
||||
* reference points accordingly. In case you wonder, the values are
|
||||
* big-endian encoded variable names, just to prevent these arrays
|
||||
* from being merged by linker. */
|
||||
const unsigned int FIPS_rodata_start[]=
|
||||
{ 0x46495053, 0x5f726f64, 0x6174615f, 0x73746172 };
|
||||
#else
|
||||
#define FIPS_ref_point FIPS_text_end
|
||||
const unsigned int FIPS_rodata_end[]=
|
||||
{ 0x46495053, 0x5f726f64, 0x6174615f, 0x656e645b };
|
||||
#endif
|
||||
|
||||
/*
|
||||
* I declare reference function as static in order to avoid certain
|
||||
* pitfalls in -dynamic linker behaviour...
|
||||
*/
|
||||
static void *instruction_pointer(void)
|
||||
{ void *ret=NULL;
|
||||
/* These are ABI-neutral CPU-specific snippets. ABI-neutrality means
|
||||
* that they are designed to work under any OS running on particular
|
||||
* CPU, which is why you don't find any #ifdef THIS_OR_THAT_OS in
|
||||
* this function. */
|
||||
#if defined(INSTRUCTION_POINTER_IMPLEMENTED)
|
||||
INSTRUCTION_POINTER_IMPLEMENTED(ret);
|
||||
#elif defined(__GNUC__) && __GNUC__>=2
|
||||
# if defined(__alpha) || defined(__alpha__)
|
||||
# define INSTRUCTION_POINTER_IMPLEMENTED
|
||||
__asm __volatile ( "br %0,1f\n1:" : "=r"(ret) );
|
||||
# elif defined(__i386) || defined(__i386__)
|
||||
# define INSTRUCTION_POINTER_IMPLEMENTED
|
||||
__asm __volatile ( "call 1f\n1: popl %0" : "=r"(ret) );
|
||||
ret = (void *)((size_t)ret&~3UL); /* align for better performance */
|
||||
# elif defined(__ia64) || defined(__ia64__)
|
||||
# define INSTRUCTION_POINTER_IMPLEMENTED
|
||||
__asm __volatile ( "mov %0=ip" : "=r"(ret) );
|
||||
# elif defined(__hppa) || defined(__hppa__) || defined(__pa_risc)
|
||||
# define INSTRUCTION_POINTER_IMPLEMENTED
|
||||
__asm __volatile ( "blr %%r0,%0\n\tnop" : "=r"(ret) );
|
||||
ret = (void *)((size_t)ret&~3UL); /* mask privilege level */
|
||||
# elif defined(__mips) || defined(__mips__)
|
||||
# define INSTRUCTION_POINTER_IMPLEMENTED
|
||||
void *scratch;
|
||||
__asm __volatile ( "move %1,$31\n\t" /* save ra */
|
||||
"bal .+8; nop\n\t"
|
||||
"move %0,$31\n\t"
|
||||
"move $31,%1" /* restore ra */
|
||||
: "=r"(ret),"=r"(scratch) );
|
||||
# elif defined(__ppc__) || defined(__powerpc) || defined(__powerpc__) || \
|
||||
defined(__POWERPC__) || defined(_POWER) || defined(__PPC__) || \
|
||||
defined(__PPC64__) || defined(__powerpc64__)
|
||||
# define INSTRUCTION_POINTER_IMPLEMENTED
|
||||
void *scratch;
|
||||
__asm __volatile ( "mfspr %1,8\n\t" /* save lr */
|
||||
"bl $+4\n\t"
|
||||
"mfspr %0,8\n\t" /* mflr ret */
|
||||
"mtspr 8,%1" /* restore lr */
|
||||
: "=r"(ret),"=r"(scratch) );
|
||||
# elif defined(__s390__) || defined(__s390x__)
|
||||
# define INSTRUCTION_POINTER_IMPLEMENTED
|
||||
__asm __volatile ( "bras %0,1f\n1:" : "=r"(ret) );
|
||||
ret = (void *)((size_t)ret&~3UL);
|
||||
# elif defined(__sparc) || defined(__sparc__) || defined(__sparcv9)
|
||||
# define INSTRUCTION_POINTER_IMPLEMENTED
|
||||
void *scratch;
|
||||
__asm __volatile ( "mov %%o7,%1\n\t"
|
||||
"call .+8; nop\n\t"
|
||||
"mov %%o7,%0\n\t"
|
||||
"mov %1,%%o7"
|
||||
: "=r"(ret),"=r"(scratch) );
|
||||
# elif defined(__x86_64) || defined(__x86_64__)
|
||||
# define INSTRUCTION_POINTER_IMPLEMENTED
|
||||
__asm __volatile ( "leaq 0(%%rip),%0" : "=r"(ret) );
|
||||
ret = (void *)((size_t)ret&~3UL); /* align for better performance */
|
||||
# endif
|
||||
#elif defined(__DECC) && defined(__alpha)
|
||||
# define INSTRUCTION_POINTER_IMPLEMENTED
|
||||
ret = (void *)(size_t)asm("br %v0,1f\n1:");
|
||||
#elif defined(_MSC_VER) && defined(_M_IX86)
|
||||
# define INSTRUCTION_POINTER_IMPLEMENTED
|
||||
void *scratch;
|
||||
_asm {
|
||||
call self
|
||||
self: pop eax
|
||||
mov scratch,eax
|
||||
}
|
||||
ret = (void *)((size_t)scratch&~3UL);
|
||||
#endif
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* This function returns pointer to an instruction in the vicinity of
|
||||
* its entry point, but not outside this object module. This guarantees
|
||||
* that sequestered code is covered...
|
||||
*/
|
||||
void *FIPS_ref_point()
|
||||
{
|
||||
#if defined(INSTRUCTION_POINTER_IMPLEMENTED)
|
||||
return instruction_pointer();
|
||||
/* Below we essentially cover vendor compilers which do not support
|
||||
* inline assembler... */
|
||||
#elif defined(_AIX)
|
||||
struct { void *ip,*gp,*env; } *p = (void *)instruction_pointer;
|
||||
return p->ip;
|
||||
#elif defined(_HPUX_SOURCE)
|
||||
# if defined(__hppa) || defined(__hppa__)
|
||||
struct { void *i[4]; } *p = (void *)FIPS_ref_point;
|
||||
|
||||
if (sizeof(p) == 8) /* 64-bit */
|
||||
return p->i[2];
|
||||
else if ((size_t)p & 2)
|
||||
{ p = (void *)((size_t)p&~3UL);
|
||||
return p->i[0];
|
||||
}
|
||||
else
|
||||
return (void *)p;
|
||||
# elif defined(__ia64) || defined(__ia64__)
|
||||
struct { unsigned long long ip,gp; } *p=(void *)instruction_pointer;
|
||||
return (void *)(size_t)p->ip;
|
||||
# endif
|
||||
#elif (defined(__VMS) || defined(VMS)) && !(defined(vax) || defined(__vax__))
|
||||
/* applies to both alpha and ia64 */
|
||||
struct { unsigned __int64 opaque,ip; } *p=(void *)instruction_pointer;
|
||||
return (void *)(size_t)p->ip;
|
||||
#elif defined(__VOS__)
|
||||
/* applies to both pa-risc and ia32 */
|
||||
struct { void *dp,*ip,*gp; } *p = (void *)instruction_pointer;
|
||||
return p->ip;
|
||||
#elif defined(_WIN32)
|
||||
# if defined(_WIN64) && defined(_M_IA64)
|
||||
struct { void *ip,*gp; } *p = (void *)FIPS_ref_point;
|
||||
return p->ip;
|
||||
# else
|
||||
return (void *)FIPS_ref_point;
|
||||
# endif
|
||||
/*
|
||||
* In case you wonder why there is no #ifdef __linux. All Linux targets
|
||||
* are GCC-based and therefore are covered by instruction_pointer above
|
||||
* [well, some are covered by by the one below]...
|
||||
*/
|
||||
#elif defined(POINTER_TO_FUNCTION_IS_POINTER_TO_1ST_INSTRUCTION)
|
||||
return (void *)instruction_pointer;
|
||||
#else
|
||||
return NULL;
|
||||
#endif
|
||||
}
|
||||
|
|
@ -1,74 +0,0 @@
|
|||
/* ====================================================================
|
||||
* Copyright (c) 2003 The OpenSSL Project. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* 3. All advertising materials mentioning features or use of this
|
||||
* software must display the following acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
|
||||
*
|
||||
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission. For written permission, please contact
|
||||
* openssl-core@openssl.org.
|
||||
*
|
||||
* 5. Products derived from this software may not be called "OpenSSL"
|
||||
* nor may "OpenSSL" appear in their names without prior written
|
||||
* permission of the OpenSSL Project.
|
||||
*
|
||||
* 6. Redistributions of any form whatsoever must retain the following
|
||||
* acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit (http://www.openssl.org/)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
|
||||
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
|
||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef OPENSSL_FIPS
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void fips_w_lock(void);
|
||||
void fips_w_unlock(void);
|
||||
void fips_r_lock(void);
|
||||
void fips_r_unlock(void);
|
||||
int fips_is_started(void);
|
||||
void fips_set_started(void);
|
||||
int fips_is_owning_thread(void);
|
||||
int fips_set_owning_thread(void);
|
||||
void fips_set_selftest_fail(void);
|
||||
int fips_clear_owning_thread(void);
|
||||
unsigned char *fips_signature_witness(void);
|
||||
int fips_check_rsa(RSA *rsa);
|
||||
|
||||
#define FIPS_MAX_CIPHER_TEST_SIZE 16
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
|
@ -1,176 +0,0 @@
|
|||
/* ====================================================================
|
||||
* Copyright (c) 2005 The OpenSSL Project. Rights for redistribution
|
||||
* and usage in source and binary forms are granted according to the
|
||||
* OpenSSL license.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#if defined(__unix) || defined(__unix__)
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#ifndef FINGERPRINT_PREMAIN_DSO_LOAD
|
||||
|
||||
#if defined(__GNUC__) && __GNUC__>=2
|
||||
void FINGERPRINT_premain(void) __attribute__((constructor));
|
||||
/* Most commonly this results in pointer to premain to be dropped
|
||||
* to .ctors segment, which is traversed by GCC crtbegin.o upon
|
||||
* program startup. Except on a.out OpenBSD where it results in
|
||||
* _GLOBAL_$I$premain() {premain();} being auto-generated by
|
||||
* compiler... But one way or another this is believed to cover
|
||||
* *all* GCC targets. */
|
||||
#elif defined(_MSC_VER)
|
||||
# ifdef _WINDLL
|
||||
__declspec(dllexport) /* this is essentially cosmetics... */
|
||||
# endif
|
||||
void FINGERPRINT_premain(void);
|
||||
static int premain_wrapper(void) { FINGERPRINT_premain(); return 0; }
|
||||
# ifdef _WIN64
|
||||
# pragma section(".CRT$XCU",read)
|
||||
__declspec(allocate(".CRT$XCU"))
|
||||
# else
|
||||
# pragma data_seg(".CRT$XCU")
|
||||
# endif
|
||||
static int (*p)(void) = premain_wrapper;
|
||||
/* This results in pointer to premain to appear in .CRT segment,
|
||||
* which is traversed by Visual C run-time initialization code.
|
||||
* This applies to both Win32 and [all flavors of] Win64. */
|
||||
# pragma data_seg()
|
||||
#elif defined(__SUNPRO_C)
|
||||
void FINGERPRINT_premain(void);
|
||||
# pragma init(FINGERPRINT_premain)
|
||||
/* This results in a call to premain to appear in .init segment. */
|
||||
#elif defined(__DECC) && (defined(__VMS) || defined(VMS))
|
||||
void FINGERPRINT_premain(void);
|
||||
# pragma __nostandard
|
||||
globaldef { "LIB$INITIALIZ" } readonly _align (LONGWORD)
|
||||
int spare[8] = {0};
|
||||
globaldef { "LIB$INITIALIZE" } readonly _align (LONGWORD)
|
||||
void (*x_FINGERPRINT_premain)(void) = FINGERPRINT_premain;
|
||||
/* Refer to LIB$INITIALIZE to ensure it exists in the image. */
|
||||
int lib$initialize();
|
||||
globaldef int (*lib_init_ref)() = lib$initialize;
|
||||
# pragma __standard
|
||||
#elif 0
|
||||
The rest has to be taken care of through command line:
|
||||
|
||||
-Wl,-init,FINGERPRINT_premain on OSF1 and IRIX
|
||||
-Wl,+init,FINGERPRINT_premain on HP-UX
|
||||
-Wl,-binitfini:FINGERPRINT_premain on AIX
|
||||
|
||||
On ELF platforms this results in a call to premain to appear in
|
||||
.init segment...
|
||||
#endif
|
||||
|
||||
#ifndef HMAC_SHA1_SIG
|
||||
#define HMAC_SHA1_SIG "?have to make sure this string is unique"
|
||||
#endif
|
||||
|
||||
static const unsigned char FINGERPRINT_ascii_value[40] = HMAC_SHA1_SIG;
|
||||
|
||||
#define atox(c) ((c)>='a'?((c)-'a'+10):((c)>='A'?(c)-'A'+10:(c)-'0'))
|
||||
|
||||
extern const void *FIPS_text_start(), *FIPS_text_end();
|
||||
extern const unsigned char FIPS_rodata_start[], FIPS_rodata_end[];
|
||||
extern unsigned char FIPS_signature[20];
|
||||
extern unsigned int FIPS_incore_fingerprint(unsigned char *,unsigned int);
|
||||
|
||||
/*
|
||||
* As name suggests this code is executed prior main(). We use this
|
||||
* opportunity to fingerprint sequestered code in virtual address
|
||||
* space of target application.
|
||||
*/
|
||||
void FINGERPRINT_premain(void)
|
||||
{ unsigned char sig[sizeof(FIPS_signature)];
|
||||
const unsigned char * volatile p=FINGERPRINT_ascii_value;
|
||||
unsigned int len=sizeof(sig),i;
|
||||
|
||||
/* "volatilization" is done to disengage unwanted optimization... */
|
||||
if (*((volatile unsigned char *)p)=='?')
|
||||
{ if (FIPS_text_start()==NULL)
|
||||
{ fprintf(stderr,"FIPS_text_start() returns NULL\n");
|
||||
_exit(1);
|
||||
}
|
||||
#if defined(DEBUG_FINGERPRINT_PREMAIN)
|
||||
fprintf(stderr,".text:%p+%d=%p\n",FIPS_text_start(),
|
||||
(int)((size_t)FIPS_text_end()-(size_t)FIPS_text_start()),
|
||||
FIPS_text_end());
|
||||
fprintf(stderr,".rodata:%p+%d=%p\n",FIPS_rodata_start,
|
||||
(int)((size_t)FIPS_rodata_end-(size_t)FIPS_rodata_start),
|
||||
FIPS_rodata_end);
|
||||
#endif
|
||||
|
||||
len=FIPS_incore_fingerprint(sig,sizeof(sig));
|
||||
|
||||
if (len!=sizeof(sig))
|
||||
{ fprintf(stderr,"fingerprint length mismatch: %u\n",len);
|
||||
_exit(1);
|
||||
}
|
||||
|
||||
for (i=0;i<len;i++) printf("%02x",sig[i]);
|
||||
printf("\n");
|
||||
fflush(stdout);
|
||||
_exit(0);
|
||||
}
|
||||
else if (FIPS_signature[0]=='\0') do
|
||||
{ for (i=0;i<sizeof(FIPS_signature);i++,p+=2)
|
||||
FIPS_signature[i] = (atox(p[0])<<4)|atox(p[1]);
|
||||
|
||||
#if defined(DEBUG_FINGERPRINT_PREMAIN)
|
||||
if (getenv("OPENSSL_FIPS")==NULL) break;
|
||||
|
||||
len=FIPS_incore_fingerprint(sig,sizeof(sig));
|
||||
|
||||
if (memcmp(FIPS_signature,sig,sizeof(FIPS_signature)))
|
||||
{ fprintf(stderr,"FINGERPRINT_premain: FIPS_signature mismatch\n");
|
||||
_exit(1);
|
||||
}
|
||||
#endif
|
||||
} while(0);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
#include <openssl/bio.h>
|
||||
#include <openssl/dso.h>
|
||||
#include <openssl/err.h>
|
||||
|
||||
int main(int argc,char *argv[])
|
||||
{ DSO *dso;
|
||||
DSO_FUNC_TYPE func;
|
||||
BIO *bio_err;
|
||||
|
||||
if (argc < 2)
|
||||
{ fprintf (stderr,"usage: %s libcrypto.dso\n",argv[0]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if ((bio_err=BIO_new(BIO_s_file())) == NULL)
|
||||
{ fprintf (stderr,"unable to allocate BIO\n");
|
||||
return 1;
|
||||
}
|
||||
BIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT);
|
||||
ERR_load_crypto_strings();
|
||||
|
||||
dso = DSO_load(NULL,argv[1],NULL,DSO_FLAG_NO_NAME_TRANSLATION);
|
||||
if (dso == NULL)
|
||||
{ ERR_print_errors(bio_err);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* This is not normally reached, because FINGERPRINT_premain should
|
||||
* have executed and terminated application already upon DSO_load... */
|
||||
func = DSO_bind_func(dso,"FINGERPRINT_premain");
|
||||
if (func == NULL)
|
||||
{ ERR_print_errors(bio_err);
|
||||
return 1;
|
||||
}
|
||||
|
||||
(*func)();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -1 +0,0 @@
|
|||
HMAC-SHA1(fips_premain.c)= 9e5ddba185ac446e0cf36fcf8e1b3acffe5d0b2c
|
||||
|
|
@ -1,579 +0,0 @@
|
|||
/* ====================================================================
|
||||
* Copyright (c) 2003 The OpenSSL Project. All rights reserved.
|
||||
*
|
||||
*
|
||||
* This command is intended as a test driver for the FIPS-140 testing
|
||||
* lab performing FIPS-140 validation. It demonstrates the use of the
|
||||
* OpenSSL library ito perform a variety of common cryptographic
|
||||
* functions. A power-up self test is demonstrated by deliberately
|
||||
* pointing to an invalid executable hash
|
||||
*
|
||||
* Contributed by Steve Marquess.
|
||||
*
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <openssl/aes.h>
|
||||
#include <openssl/des.h>
|
||||
#include <openssl/hmac.h>
|
||||
#include <openssl/err.h>
|
||||
|
||||
#include <openssl/bn.h>
|
||||
#include <openssl/rand.h>
|
||||
#include <openssl/sha.h>
|
||||
|
||||
|
||||
#ifndef OPENSSL_FIPS
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
printf("No FIPS support\n");
|
||||
return(0);
|
||||
}
|
||||
#else
|
||||
|
||||
#include <openssl/rsa.h>
|
||||
#include <openssl/dsa.h>
|
||||
#include <openssl/dh.h>
|
||||
|
||||
#include <openssl/fips.h>
|
||||
#include "fips_utl.h"
|
||||
|
||||
/* AES: encrypt and decrypt known plaintext, verify result matches original plaintext
|
||||
*/
|
||||
static int FIPS_aes_test(void)
|
||||
{
|
||||
int ret = 0;
|
||||
unsigned char pltmp[16];
|
||||
unsigned char citmp[16];
|
||||
unsigned char key[16] = { 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16};
|
||||
unsigned char plaintext[16] = "etaonrishdlcu";
|
||||
EVP_CIPHER_CTX ctx;
|
||||
EVP_CIPHER_CTX_init(&ctx);
|
||||
if (EVP_CipherInit_ex(&ctx, EVP_aes_128_ecb(),NULL, key, NULL, 1) <= 0)
|
||||
goto err;
|
||||
EVP_Cipher(&ctx, citmp, plaintext, 16);
|
||||
if (EVP_CipherInit_ex(&ctx, EVP_aes_128_ecb(),NULL, key, NULL, 0) <= 0)
|
||||
goto err;
|
||||
EVP_Cipher(&ctx, pltmp, citmp, 16);
|
||||
if (memcmp(pltmp, plaintext, 16))
|
||||
goto err;
|
||||
ret = 1;
|
||||
err:
|
||||
EVP_CIPHER_CTX_cleanup(&ctx);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int FIPS_des3_test(void)
|
||||
{
|
||||
int ret = 0;
|
||||
unsigned char pltmp[8];
|
||||
unsigned char citmp[8];
|
||||
unsigned char key[] = { 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,
|
||||
19,20,21,22,23,24};
|
||||
unsigned char plaintext[] = { 'e', 't', 'a', 'o', 'n', 'r', 'i', 's' };
|
||||
EVP_CIPHER_CTX ctx;
|
||||
EVP_CIPHER_CTX_init(&ctx);
|
||||
if (EVP_CipherInit_ex(&ctx, EVP_des_ede3_ecb(),NULL, key, NULL, 1) <= 0)
|
||||
goto err;
|
||||
EVP_Cipher(&ctx, citmp, plaintext, 8);
|
||||
if (EVP_CipherInit_ex(&ctx, EVP_des_ede3_ecb(),NULL, key, NULL, 0) <= 0)
|
||||
goto err;
|
||||
EVP_Cipher(&ctx, pltmp, citmp, 8);
|
||||
if (memcmp(pltmp, plaintext, 8))
|
||||
goto err;
|
||||
ret = 1;
|
||||
err:
|
||||
EVP_CIPHER_CTX_cleanup(&ctx);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* DSA: generate keys and sign, verify input plaintext.
|
||||
*/
|
||||
static int FIPS_dsa_test(int bad)
|
||||
{
|
||||
DSA *dsa = NULL;
|
||||
EVP_PKEY pk;
|
||||
unsigned char dgst[] = "etaonrishdlc";
|
||||
unsigned char buf[60];
|
||||
unsigned int slen;
|
||||
int r = 0;
|
||||
EVP_MD_CTX mctx;
|
||||
|
||||
ERR_clear_error();
|
||||
EVP_MD_CTX_init(&mctx);
|
||||
dsa = FIPS_dsa_new();
|
||||
if (!dsa)
|
||||
goto end;
|
||||
if (!DSA_generate_parameters_ex(dsa, 1024,NULL,0,NULL,NULL,NULL))
|
||||
goto end;
|
||||
if (!DSA_generate_key(dsa))
|
||||
goto end;
|
||||
if (bad)
|
||||
BN_add_word(dsa->pub_key, 1);
|
||||
|
||||
pk.type = EVP_PKEY_DSA;
|
||||
pk.pkey.dsa = dsa;
|
||||
|
||||
if (!EVP_SignInit_ex(&mctx, EVP_dss1(), NULL))
|
||||
goto end;
|
||||
if (!EVP_SignUpdate(&mctx, dgst, sizeof(dgst) - 1))
|
||||
goto end;
|
||||
if (!EVP_SignFinal(&mctx, buf, &slen, &pk))
|
||||
goto end;
|
||||
|
||||
if (!EVP_VerifyInit_ex(&mctx, EVP_dss1(), NULL))
|
||||
goto end;
|
||||
if (!EVP_VerifyUpdate(&mctx, dgst, sizeof(dgst) - 1))
|
||||
goto end;
|
||||
r = EVP_VerifyFinal(&mctx, buf, slen, &pk);
|
||||
end:
|
||||
EVP_MD_CTX_cleanup(&mctx);
|
||||
if (dsa)
|
||||
FIPS_dsa_free(dsa);
|
||||
if (r != 1)
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* RSA: generate keys and sign, verify input plaintext.
|
||||
*/
|
||||
static int FIPS_rsa_test(int bad)
|
||||
{
|
||||
RSA *key;
|
||||
unsigned char input_ptext[] = "etaonrishdlc";
|
||||
unsigned char buf[256];
|
||||
unsigned int slen;
|
||||
BIGNUM *bn;
|
||||
EVP_MD_CTX mctx;
|
||||
EVP_PKEY pk;
|
||||
int r = 0;
|
||||
|
||||
ERR_clear_error();
|
||||
EVP_MD_CTX_init(&mctx);
|
||||
key = FIPS_rsa_new();
|
||||
bn = BN_new();
|
||||
if (!key || !bn)
|
||||
return 0;
|
||||
BN_set_word(bn, 65537);
|
||||
if (!RSA_generate_key_ex(key, 1024,bn,NULL))
|
||||
return 0;
|
||||
BN_free(bn);
|
||||
if (bad)
|
||||
BN_add_word(key->n, 1);
|
||||
|
||||
pk.type = EVP_PKEY_RSA;
|
||||
pk.pkey.rsa = key;
|
||||
|
||||
if (!EVP_SignInit_ex(&mctx, EVP_sha1(), NULL))
|
||||
goto end;
|
||||
if (!EVP_SignUpdate(&mctx, input_ptext, sizeof(input_ptext) - 1))
|
||||
goto end;
|
||||
if (!EVP_SignFinal(&mctx, buf, &slen, &pk))
|
||||
goto end;
|
||||
|
||||
if (!EVP_VerifyInit_ex(&mctx, EVP_sha1(), NULL))
|
||||
goto end;
|
||||
if (!EVP_VerifyUpdate(&mctx, input_ptext, sizeof(input_ptext) - 1))
|
||||
goto end;
|
||||
r = EVP_VerifyFinal(&mctx, buf, slen, &pk);
|
||||
end:
|
||||
EVP_MD_CTX_cleanup(&mctx);
|
||||
if (key)
|
||||
FIPS_rsa_free(key);
|
||||
if (r != 1)
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* SHA1: generate hash of known digest value and compare to known
|
||||
precomputed correct hash
|
||||
*/
|
||||
static int FIPS_sha1_test()
|
||||
{
|
||||
unsigned char digest[SHA_DIGEST_LENGTH] =
|
||||
{ 0x11, 0xf1, 0x9a, 0x3a, 0xec, 0x1a, 0x1e, 0x8e, 0x65, 0xd4, 0x9a, 0x38, 0x0c, 0x8b, 0x1e, 0x2c, 0xe8, 0xb3, 0xc5, 0x18 };
|
||||
unsigned char str[] = "etaonrishd";
|
||||
|
||||
unsigned char md[SHA_DIGEST_LENGTH];
|
||||
|
||||
ERR_clear_error();
|
||||
if (!EVP_Digest(str,sizeof(str) - 1,md, NULL, EVP_sha1(), NULL)) return 0;
|
||||
if (memcmp(md,digest,sizeof(md)))
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* SHA256: generate hash of known digest value and compare to known
|
||||
precomputed correct hash
|
||||
*/
|
||||
static int FIPS_sha256_test()
|
||||
{
|
||||
unsigned char digest[SHA256_DIGEST_LENGTH] =
|
||||
{0xf5, 0x53, 0xcd, 0xb8, 0xcf, 0x1, 0xee, 0x17, 0x9b, 0x93, 0xc9, 0x68, 0xc0, 0xea, 0x40, 0x91,
|
||||
0x6, 0xec, 0x8e, 0x11, 0x96, 0xc8, 0x5d, 0x1c, 0xaf, 0x64, 0x22, 0xe6, 0x50, 0x4f, 0x47, 0x57};
|
||||
unsigned char str[] = "etaonrishd";
|
||||
|
||||
unsigned char md[SHA256_DIGEST_LENGTH];
|
||||
|
||||
ERR_clear_error();
|
||||
if (!EVP_Digest(str,sizeof(str) - 1,md, NULL, EVP_sha256(), NULL)) return 0;
|
||||
if (memcmp(md,digest,sizeof(md)))
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* SHA512: generate hash of known digest value and compare to known
|
||||
precomputed correct hash
|
||||
*/
|
||||
static int FIPS_sha512_test()
|
||||
{
|
||||
unsigned char digest[SHA512_DIGEST_LENGTH] =
|
||||
{0x99, 0xc9, 0xe9, 0x5b, 0x88, 0xd4, 0x78, 0x88, 0xdf, 0x88, 0x5f, 0x94, 0x71, 0x64, 0x28, 0xca,
|
||||
0x16, 0x1f, 0x3d, 0xf4, 0x1f, 0xf3, 0x0f, 0xc5, 0x03, 0x99, 0xb2, 0xd0, 0xe7, 0x0b, 0x94, 0x4a,
|
||||
0x45, 0xd2, 0x6c, 0x4f, 0x20, 0x06, 0xef, 0x71, 0xa9, 0x25, 0x7f, 0x24, 0xb1, 0xd9, 0x40, 0x22,
|
||||
0x49, 0x54, 0x10, 0xc2, 0x22, 0x9d, 0x27, 0xfe, 0xbd, 0xd6, 0xd6, 0xeb, 0x2d, 0x42, 0x1d, 0xa3};
|
||||
unsigned char str[] = "etaonrishd";
|
||||
|
||||
unsigned char md[SHA512_DIGEST_LENGTH];
|
||||
|
||||
ERR_clear_error();
|
||||
if (!EVP_Digest(str,sizeof(str) - 1,md, NULL, EVP_sha512(), NULL)) return 0;
|
||||
if (memcmp(md,digest,sizeof(md)))
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* HMAC-SHA1: generate hash of known digest value and compare to known
|
||||
precomputed correct hash
|
||||
*/
|
||||
static int FIPS_hmac_sha1_test()
|
||||
{
|
||||
unsigned char key[] = "etaonrishd";
|
||||
unsigned char iv[] = "Sample text";
|
||||
unsigned char kaval[EVP_MAX_MD_SIZE] =
|
||||
{0x73, 0xf7, 0xa0, 0x48, 0xf8, 0x94, 0xed, 0xdd, 0x0a, 0xea, 0xea, 0x56, 0x1b, 0x61, 0x2e, 0x70,
|
||||
0xb2, 0xfb, 0xec, 0xc6};
|
||||
|
||||
unsigned char out[EVP_MAX_MD_SIZE];
|
||||
unsigned int outlen;
|
||||
|
||||
ERR_clear_error();
|
||||
if (!HMAC(EVP_sha1(),key,sizeof(key)-1,iv,sizeof(iv)-1,out,&outlen)) return 0;
|
||||
if (memcmp(out,kaval,outlen))
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* HMAC-SHA224: generate hash of known digest value and compare to known
|
||||
precomputed correct hash
|
||||
*/
|
||||
static int FIPS_hmac_sha224_test()
|
||||
{
|
||||
unsigned char key[] = "etaonrishd";
|
||||
unsigned char iv[] = "Sample text";
|
||||
unsigned char kaval[EVP_MAX_MD_SIZE] =
|
||||
{0x75, 0x58, 0xd5, 0xbd, 0x55, 0x6d, 0x87, 0x0f, 0x75, 0xff, 0xbe, 0x1c, 0xb2, 0xf0, 0x20, 0x35,
|
||||
0xe5, 0x62, 0x49, 0xb6, 0x94, 0xb9, 0xfc, 0x65, 0x34, 0x33, 0x3a, 0x19};
|
||||
|
||||
unsigned char out[EVP_MAX_MD_SIZE];
|
||||
unsigned int outlen;
|
||||
|
||||
ERR_clear_error();
|
||||
if (!HMAC(EVP_sha224(),key,sizeof(key)-1,iv,sizeof(iv)-1,out,&outlen)) return 0;
|
||||
if (memcmp(out,kaval,outlen))
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* HMAC-SHA256: generate hash of known digest value and compare to known
|
||||
precomputed correct hash
|
||||
*/
|
||||
static int FIPS_hmac_sha256_test()
|
||||
{
|
||||
unsigned char key[] = "etaonrishd";
|
||||
unsigned char iv[] = "Sample text";
|
||||
unsigned char kaval[EVP_MAX_MD_SIZE] =
|
||||
{0xe9, 0x17, 0xc1, 0x7b, 0x4c, 0x6b, 0x77, 0xda, 0xd2, 0x30, 0x36, 0x02, 0xf5, 0x72, 0x33, 0x87,
|
||||
0x9f, 0xc6, 0x6e, 0x7b, 0x7e, 0xa8, 0xea, 0xaa, 0x9f, 0xba, 0xee, 0x51, 0xff, 0xda, 0x24, 0xf4};
|
||||
|
||||
unsigned char out[EVP_MAX_MD_SIZE];
|
||||
unsigned int outlen;
|
||||
|
||||
ERR_clear_error();
|
||||
if (!HMAC(EVP_sha256(),key,sizeof(key)-1,iv,sizeof(iv)-1,out,&outlen)) return 0;
|
||||
if (memcmp(out,kaval,outlen))
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* HMAC-SHA384: generate hash of known digest value and compare to known
|
||||
precomputed correct hash
|
||||
*/
|
||||
static int FIPS_hmac_sha384_test()
|
||||
{
|
||||
unsigned char key[] = "etaonrishd";
|
||||
unsigned char iv[] = "Sample text";
|
||||
unsigned char kaval[EVP_MAX_MD_SIZE] =
|
||||
{0xb2, 0x9d, 0x40, 0x58, 0x32, 0xc4, 0xe3, 0x31, 0xb6, 0x63, 0x08, 0x26, 0x99, 0xef, 0x3b, 0x10,
|
||||
0xe2, 0xdf, 0xf8, 0xff, 0xc6, 0xe1, 0x03, 0x29, 0x81, 0x2a, 0x1b, 0xac, 0xb0, 0x07, 0x39, 0x08,
|
||||
0xf3, 0x91, 0x35, 0x11, 0x76, 0xd6, 0x4c, 0x20, 0xfb, 0x4d, 0xc3, 0xf3, 0xb8, 0x9b, 0x88, 0x1c};
|
||||
|
||||
unsigned char out[EVP_MAX_MD_SIZE];
|
||||
unsigned int outlen;
|
||||
|
||||
ERR_clear_error();
|
||||
if (!HMAC(EVP_sha384(),key,sizeof(key)-1,iv,sizeof(iv)-1,out,&outlen)) return 0;
|
||||
if (memcmp(out,kaval,outlen))
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* HMAC-SHA512: generate hash of known digest value and compare to known
|
||||
precomputed correct hash
|
||||
*/
|
||||
static int FIPS_hmac_sha512_test()
|
||||
{
|
||||
unsigned char key[] = "etaonrishd";
|
||||
unsigned char iv[] = "Sample text";
|
||||
unsigned char kaval[EVP_MAX_MD_SIZE] =
|
||||
{0xcd, 0x3e, 0xb9, 0x51, 0xb8, 0xbc, 0x7f, 0x9a, 0x23, 0xaf, 0xf3, 0x77, 0x59, 0x85, 0xa9, 0xe6,
|
||||
0xf7, 0xd1, 0x51, 0x96, 0x17, 0xe0, 0x92, 0xd8, 0xa6, 0x3b, 0xc1, 0xad, 0x7e, 0x24, 0xca, 0xb1,
|
||||
0xd7, 0x79, 0x0a, 0xa5, 0xea, 0x2c, 0x02, 0x58, 0x0b, 0xa6, 0x52, 0x6b, 0x61, 0x7f, 0xeb, 0x9c,
|
||||
0x47, 0x86, 0x5d, 0x74, 0x2b, 0x88, 0xdf, 0xee, 0x46, 0x69, 0x96, 0x3d, 0xa6, 0xd9, 0x2a, 0x53};
|
||||
|
||||
unsigned char out[EVP_MAX_MD_SIZE];
|
||||
unsigned int outlen;
|
||||
|
||||
ERR_clear_error();
|
||||
if (!HMAC(EVP_sha512(),key,sizeof(key)-1,iv,sizeof(iv)-1,out,&outlen)) return 0;
|
||||
if (memcmp(out,kaval,outlen))
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/* DH: generate shared parameters
|
||||
*/
|
||||
static int dh_test()
|
||||
{
|
||||
DH *dh;
|
||||
ERR_clear_error();
|
||||
dh = FIPS_dh_new();
|
||||
if (!dh)
|
||||
return 0;
|
||||
if (!DH_generate_parameters_ex(dh, 1024, 2, NULL))
|
||||
return 0;
|
||||
FIPS_dh_free(dh);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Zeroize
|
||||
*/
|
||||
static int Zeroize()
|
||||
{
|
||||
RSA *key;
|
||||
BIGNUM *bn;
|
||||
unsigned char userkey[16] =
|
||||
{ 0x48, 0x50, 0xf0, 0xa3, 0x3a, 0xed, 0xd3, 0xaf, 0x6e, 0x47, 0x7f, 0x83, 0x02, 0xb1, 0x09, 0x68 };
|
||||
size_t i;
|
||||
int n;
|
||||
|
||||
key = FIPS_rsa_new();
|
||||
bn = BN_new();
|
||||
if (!key || !bn)
|
||||
return 0;
|
||||
BN_set_word(bn, 65537);
|
||||
if (!RSA_generate_key_ex(key, 1024,bn,NULL))
|
||||
return 0;
|
||||
BN_free(bn);
|
||||
|
||||
n = BN_num_bytes(key->d);
|
||||
printf(" Generated %d byte RSA private key\n", n);
|
||||
printf("\tBN key before overwriting:\n");
|
||||
do_bn_print(stdout, key->d);
|
||||
BN_rand(key->d,n*8,-1,0);
|
||||
printf("\tBN key after overwriting:\n");
|
||||
do_bn_print(stdout, key->d);
|
||||
|
||||
printf("\tchar buffer key before overwriting: \n\t\t");
|
||||
for(i = 0; i < sizeof(userkey); i++) printf("%02x", userkey[i]);
|
||||
printf("\n");
|
||||
RAND_bytes(userkey, sizeof userkey);
|
||||
printf("\tchar buffer key after overwriting: \n\t\t");
|
||||
for(i = 0; i < sizeof(userkey); i++) printf("%02x", userkey[i]);
|
||||
printf("\n");
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int Error;
|
||||
static const char * Fail(const char *msg)
|
||||
{
|
||||
do_print_errors();
|
||||
Error++;
|
||||
return msg;
|
||||
}
|
||||
|
||||
static void test_msg(const char *msg, int result)
|
||||
{
|
||||
printf("%s...%s\n", msg, result ? "successful" : Fail("Failed!"));
|
||||
}
|
||||
|
||||
int main(int argc,char **argv)
|
||||
{
|
||||
|
||||
int do_corrupt_rsa_keygen = 0, do_corrupt_dsa_keygen = 0;
|
||||
int bad_rsa = 0, bad_dsa = 0;
|
||||
int do_rng_stick = 0;
|
||||
int no_exit = 0;
|
||||
|
||||
printf("\tFIPS-mode test application\n\n");
|
||||
|
||||
/* Load entropy from external file, if any */
|
||||
RAND_load_file(".rnd", 1024);
|
||||
|
||||
if (argv[1]) {
|
||||
/* Corrupted KAT tests */
|
||||
if (!strcmp(argv[1], "aes")) {
|
||||
FIPS_corrupt_aes();
|
||||
printf("AES encryption/decryption with corrupted KAT...\n");
|
||||
} else if (!strcmp(argv[1], "des")) {
|
||||
FIPS_corrupt_des();
|
||||
printf("DES3-ECB encryption/decryption with corrupted KAT...\n");
|
||||
} else if (!strcmp(argv[1], "dsa")) {
|
||||
FIPS_corrupt_dsa();
|
||||
printf("DSA key generation and signature validation with corrupted KAT...\n");
|
||||
} else if (!strcmp(argv[1], "rsa")) {
|
||||
FIPS_corrupt_rsa();
|
||||
printf("RSA key generation and signature validation with corrupted KAT...\n");
|
||||
} else if (!strcmp(argv[1], "rsakey")) {
|
||||
printf("RSA key generation and signature validation with corrupted key...\n");
|
||||
bad_rsa = 1;
|
||||
no_exit = 1;
|
||||
} else if (!strcmp(argv[1], "rsakeygen")) {
|
||||
do_corrupt_rsa_keygen = 1;
|
||||
no_exit = 1;
|
||||
printf("RSA key generation and signature validation with corrupted keygen...\n");
|
||||
} else if (!strcmp(argv[1], "dsakey")) {
|
||||
printf("DSA key generation and signature validation with corrupted key...\n");
|
||||
bad_dsa = 1;
|
||||
no_exit = 1;
|
||||
} else if (!strcmp(argv[1], "dsakeygen")) {
|
||||
do_corrupt_dsa_keygen = 1;
|
||||
no_exit = 1;
|
||||
printf("DSA key generation and signature validation with corrupted keygen...\n");
|
||||
} else if (!strcmp(argv[1], "sha1")) {
|
||||
FIPS_corrupt_sha1();
|
||||
printf("SHA-1 hash with corrupted KAT...\n");
|
||||
} else if (!strcmp(argv[1], "rng")) {
|
||||
FIPS_corrupt_rng();
|
||||
} else if (!strcmp(argv[1], "rngstick")) {
|
||||
do_rng_stick = 1;
|
||||
no_exit = 1;
|
||||
printf("RNG test with stuck continuous test...\n");
|
||||
} else {
|
||||
printf("Bad argument \"%s\"\n", argv[1]);
|
||||
exit(1);
|
||||
}
|
||||
if (!no_exit) {
|
||||
if (!FIPS_mode_set(1)) {
|
||||
do_print_errors();
|
||||
printf("Power-up self test failed\n");
|
||||
exit(1);
|
||||
}
|
||||
printf("Power-up self test successful\n");
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
/* Non-Approved cryptographic operation
|
||||
*/
|
||||
printf("1. Non-Approved cryptographic operation test...\n");
|
||||
test_msg("\ta. Included algorithm (D-H)...", dh_test());
|
||||
|
||||
/* Power-up self test
|
||||
*/
|
||||
ERR_clear_error();
|
||||
test_msg("2. Automatic power-up self test", FIPS_mode_set(1));
|
||||
if (!FIPS_mode())
|
||||
exit(1);
|
||||
if (do_corrupt_dsa_keygen)
|
||||
FIPS_corrupt_dsa_keygen();
|
||||
if (do_corrupt_rsa_keygen)
|
||||
FIPS_corrupt_rsa_keygen();
|
||||
if (do_rng_stick)
|
||||
FIPS_rng_stick();
|
||||
|
||||
/* AES encryption/decryption
|
||||
*/
|
||||
test_msg("3. AES encryption/decryption", FIPS_aes_test());
|
||||
|
||||
/* RSA key generation and encryption/decryption
|
||||
*/
|
||||
test_msg("4. RSA key generation and encryption/decryption",
|
||||
FIPS_rsa_test(bad_rsa));
|
||||
|
||||
/* DES-CBC encryption/decryption
|
||||
*/
|
||||
test_msg("5. DES-ECB encryption/decryption", FIPS_des3_test());
|
||||
|
||||
/* DSA key generation and signature validation
|
||||
*/
|
||||
test_msg("6. DSA key generation and signature validation",
|
||||
FIPS_dsa_test(bad_dsa));
|
||||
|
||||
/* SHA-1 hash
|
||||
*/
|
||||
test_msg("7a. SHA-1 hash", FIPS_sha1_test());
|
||||
|
||||
/* SHA-256 hash
|
||||
*/
|
||||
test_msg("7b. SHA-256 hash", FIPS_sha256_test());
|
||||
|
||||
/* SHA-512 hash
|
||||
*/
|
||||
test_msg("7c. SHA-512 hash", FIPS_sha512_test());
|
||||
|
||||
/* HMAC-SHA-1 hash
|
||||
*/
|
||||
test_msg("7d. HMAC-SHA-1 hash", FIPS_hmac_sha1_test());
|
||||
|
||||
/* HMAC-SHA-224 hash
|
||||
*/
|
||||
test_msg("7e. HMAC-SHA-224 hash", FIPS_hmac_sha224_test());
|
||||
|
||||
/* HMAC-SHA-256 hash
|
||||
*/
|
||||
test_msg("7f. HMAC-SHA-256 hash", FIPS_hmac_sha256_test());
|
||||
|
||||
/* HMAC-SHA-384 hash
|
||||
*/
|
||||
test_msg("7g. HMAC-SHA-384 hash", FIPS_hmac_sha384_test());
|
||||
|
||||
/* HMAC-SHA-512 hash
|
||||
*/
|
||||
test_msg("7h. HMAC-SHA-512 hash", FIPS_hmac_sha512_test());
|
||||
|
||||
/* Non-Approved cryptographic operation
|
||||
*/
|
||||
printf("8. Non-Approved cryptographic operation test...\n");
|
||||
printf("\ta. Included algorithm (D-H)...%s\n",
|
||||
dh_test() ? "successful as expected"
|
||||
: Fail("failed INCORRECTLY!") );
|
||||
|
||||
/* Zeroization
|
||||
*/
|
||||
printf("9. Zero-ization...\n\t%s\n",
|
||||
Zeroize() ? "successful as expected"
|
||||
: Fail("failed INCORRECTLY!") );
|
||||
|
||||
printf("\nAll tests completed with %d errors\n", Error);
|
||||
return Error ? 1 : 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -1,359 +0,0 @@
|
|||
/* ====================================================================
|
||||
* Copyright (c) 2007 The OpenSSL Project. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* 3. All advertising materials mentioning features or use of this
|
||||
* software must display the following acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
|
||||
*
|
||||
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission. For written permission, please contact
|
||||
* openssl-core@openssl.org.
|
||||
*
|
||||
* 5. Products derived from this software may not be called "OpenSSL"
|
||||
* nor may "OpenSSL" appear in their names without prior written
|
||||
* permission of the OpenSSL Project.
|
||||
*
|
||||
* 6. Redistributions of any form whatsoever must retain the following
|
||||
* acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit (http://www.openssl.org/)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
|
||||
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
|
||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
void do_print_errors(void);
|
||||
int hex2bin(const char *in, unsigned char *out);
|
||||
unsigned char *hex2bin_m(const char *in, long *plen);
|
||||
int do_hex2bn(BIGNUM **pr, const char *in);
|
||||
int do_bn_print(FILE *out, BIGNUM *bn);
|
||||
int do_bn_print_name(FILE *out, const char *name, BIGNUM *bn);
|
||||
int parse_line(char **pkw, char **pval, char *linebuf, char *olinebuf);
|
||||
BIGNUM *hex2bn(const char *in);
|
||||
int bin2hex(const unsigned char *in,int len,char *out);
|
||||
void pv(const char *tag,const unsigned char *val,int len);
|
||||
int tidy_line(char *linebuf, char *olinebuf);
|
||||
int bint2bin(const char *in, int len, unsigned char *out);
|
||||
int bin2bint(const unsigned char *in,int len,char *out);
|
||||
void PrintValue(char *tag, unsigned char *val, int len);
|
||||
void OutputValue(char *tag, unsigned char *val, int len, FILE *rfp,int bitmode);
|
||||
|
||||
void do_print_errors(void)
|
||||
{
|
||||
const char *file, *data;
|
||||
int line, flags;
|
||||
unsigned long l;
|
||||
while ((l = ERR_get_error_line_data(&file, &line, &data, &flags)))
|
||||
{
|
||||
fprintf(stderr, "ERROR:%lx:lib=%d,func=%d,reason=%d"
|
||||
":file=%s:line=%d:%s\n",
|
||||
l, ERR_GET_LIB(l), ERR_GET_FUNC(l), ERR_GET_REASON(l),
|
||||
file, line, flags & ERR_TXT_STRING ? data : "");
|
||||
}
|
||||
}
|
||||
|
||||
int hex2bin(const char *in, unsigned char *out)
|
||||
{
|
||||
int n1, n2;
|
||||
unsigned char ch;
|
||||
|
||||
for (n1=0,n2=0 ; in[n1] && in[n1] != '\n' ; )
|
||||
{ /* first byte */
|
||||
if ((in[n1] >= '0') && (in[n1] <= '9'))
|
||||
ch = in[n1++] - '0';
|
||||
else if ((in[n1] >= 'A') && (in[n1] <= 'F'))
|
||||
ch = in[n1++] - 'A' + 10;
|
||||
else if ((in[n1] >= 'a') && (in[n1] <= 'f'))
|
||||
ch = in[n1++] - 'a' + 10;
|
||||
else
|
||||
return -1;
|
||||
if(!in[n1])
|
||||
{
|
||||
out[n2++]=ch;
|
||||
break;
|
||||
}
|
||||
out[n2] = ch << 4;
|
||||
/* second byte */
|
||||
if ((in[n1] >= '0') && (in[n1] <= '9'))
|
||||
ch = in[n1++] - '0';
|
||||
else if ((in[n1] >= 'A') && (in[n1] <= 'F'))
|
||||
ch = in[n1++] - 'A' + 10;
|
||||
else if ((in[n1] >= 'a') && (in[n1] <= 'f'))
|
||||
ch = in[n1++] - 'a' + 10;
|
||||
else
|
||||
return -1;
|
||||
out[n2++] |= ch;
|
||||
}
|
||||
return n2;
|
||||
}
|
||||
|
||||
unsigned char *hex2bin_m(const char *in, long *plen)
|
||||
{
|
||||
unsigned char *p;
|
||||
p = OPENSSL_malloc((strlen(in) + 1)/2);
|
||||
*plen = hex2bin(in, p);
|
||||
return p;
|
||||
}
|
||||
|
||||
int do_hex2bn(BIGNUM **pr, const char *in)
|
||||
{
|
||||
unsigned char *p;
|
||||
long plen;
|
||||
int r = 0;
|
||||
p = hex2bin_m(in, &plen);
|
||||
if (!p)
|
||||
return 0;
|
||||
if (!*pr)
|
||||
*pr = BN_new();
|
||||
if (!*pr)
|
||||
return 0;
|
||||
if (BN_bin2bn(p, plen, *pr))
|
||||
r = 1;
|
||||
OPENSSL_free(p);
|
||||
return r;
|
||||
}
|
||||
|
||||
int do_bn_print(FILE *out, BIGNUM *bn)
|
||||
{
|
||||
int len, i;
|
||||
unsigned char *tmp;
|
||||
len = BN_num_bytes(bn);
|
||||
if (len == 0)
|
||||
{
|
||||
fputs("00", out);
|
||||
return 1;
|
||||
}
|
||||
|
||||
tmp = OPENSSL_malloc(len);
|
||||
if (!tmp)
|
||||
{
|
||||
fprintf(stderr, "Memory allocation error\n");
|
||||
return 0;
|
||||
}
|
||||
BN_bn2bin(bn, tmp);
|
||||
for (i = 0; i < len; i++)
|
||||
fprintf(out, "%02x", tmp[i]);
|
||||
OPENSSL_free(tmp);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int do_bn_print_name(FILE *out, const char *name, BIGNUM *bn)
|
||||
{
|
||||
int r;
|
||||
fprintf(out, "%s = ", name);
|
||||
r = do_bn_print(out, bn);
|
||||
if (!r)
|
||||
return 0;
|
||||
fputs("\n", out);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int parse_line(char **pkw, char **pval, char *linebuf, char *olinebuf)
|
||||
{
|
||||
char *keyword, *value, *p, *q;
|
||||
strcpy(linebuf, olinebuf);
|
||||
keyword = linebuf;
|
||||
/* Skip leading space */
|
||||
while (isspace((unsigned char)*keyword))
|
||||
keyword++;
|
||||
|
||||
/* Look for = sign */
|
||||
p = strchr(linebuf, '=');
|
||||
|
||||
/* If no '=' exit */
|
||||
if (!p)
|
||||
return 0;
|
||||
|
||||
q = p - 1;
|
||||
|
||||
/* Remove trailing space */
|
||||
while (isspace((unsigned char)*q))
|
||||
*q-- = 0;
|
||||
|
||||
*p = 0;
|
||||
value = p + 1;
|
||||
|
||||
/* Remove leading space from value */
|
||||
while (isspace((unsigned char)*value))
|
||||
value++;
|
||||
|
||||
/* Remove trailing space from value */
|
||||
p = value + strlen(value) - 1;
|
||||
|
||||
while (*p == '\n' || isspace((unsigned char)*p))
|
||||
*p-- = 0;
|
||||
|
||||
*pkw = keyword;
|
||||
*pval = value;
|
||||
return 1;
|
||||
}
|
||||
|
||||
BIGNUM *hex2bn(const char *in)
|
||||
{
|
||||
BIGNUM *p=NULL;
|
||||
|
||||
if (!do_hex2bn(&p, in))
|
||||
return NULL;
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
int bin2hex(const unsigned char *in,int len,char *out)
|
||||
{
|
||||
int n1, n2;
|
||||
unsigned char ch;
|
||||
|
||||
for (n1=0,n2=0 ; n1 < len ; ++n1)
|
||||
{
|
||||
ch=in[n1] >> 4;
|
||||
if (ch <= 0x09)
|
||||
out[n2++]=ch+'0';
|
||||
else
|
||||
out[n2++]=ch-10+'a';
|
||||
ch=in[n1] & 0x0f;
|
||||
if(ch <= 0x09)
|
||||
out[n2++]=ch+'0';
|
||||
else
|
||||
out[n2++]=ch-10+'a';
|
||||
}
|
||||
out[n2]='\0';
|
||||
return n2;
|
||||
}
|
||||
|
||||
void pv(const char *tag,const unsigned char *val,int len)
|
||||
{
|
||||
char obuf[2048];
|
||||
|
||||
bin2hex(val,len,obuf);
|
||||
printf("%s = %s\n",tag,obuf);
|
||||
}
|
||||
|
||||
/* To avoid extensive changes to test program at this stage just convert
|
||||
* the input line into an acceptable form. Keyword lines converted to form
|
||||
* "keyword = value\n" no matter what white space present, all other lines
|
||||
* just have leading and trailing space removed.
|
||||
*/
|
||||
|
||||
int tidy_line(char *linebuf, char *olinebuf)
|
||||
{
|
||||
char *keyword, *value, *p, *q;
|
||||
strcpy(linebuf, olinebuf);
|
||||
keyword = linebuf;
|
||||
/* Skip leading space */
|
||||
while (isspace((unsigned char)*keyword))
|
||||
keyword++;
|
||||
/* Look for = sign */
|
||||
p = strchr(linebuf, '=');
|
||||
|
||||
/* If no '=' just chop leading, trailing ws */
|
||||
if (!p)
|
||||
{
|
||||
p = keyword + strlen(keyword) - 1;
|
||||
while (*p == '\n' || isspace((unsigned char)*p))
|
||||
*p-- = 0;
|
||||
strcpy(olinebuf, keyword);
|
||||
strcat(olinebuf, "\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
q = p - 1;
|
||||
|
||||
/* Remove trailing space */
|
||||
while (isspace((unsigned char)*q))
|
||||
*q-- = 0;
|
||||
|
||||
*p = 0;
|
||||
value = p + 1;
|
||||
|
||||
/* Remove leading space from value */
|
||||
while (isspace((unsigned char)*value))
|
||||
value++;
|
||||
|
||||
/* Remove trailing space from value */
|
||||
p = value + strlen(value) - 1;
|
||||
|
||||
while (*p == '\n' || isspace((unsigned char)*p))
|
||||
*p-- = 0;
|
||||
|
||||
strcpy(olinebuf, keyword);
|
||||
strcat(olinebuf, " = ");
|
||||
strcat(olinebuf, value);
|
||||
strcat(olinebuf, "\n");
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* NB: this return the number of _bits_ read */
|
||||
int bint2bin(const char *in, int len, unsigned char *out)
|
||||
{
|
||||
int n;
|
||||
|
||||
memset(out,0,len);
|
||||
for(n=0 ; n < len ; ++n)
|
||||
if(in[n] == '1')
|
||||
out[n/8]|=(0x80 >> (n%8));
|
||||
return len;
|
||||
}
|
||||
|
||||
int bin2bint(const unsigned char *in,int len,char *out)
|
||||
{
|
||||
int n;
|
||||
|
||||
for(n=0 ; n < len ; ++n)
|
||||
out[n]=(in[n/8]&(0x80 >> (n%8))) ? '1' : '0';
|
||||
return n;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------*/
|
||||
|
||||
void PrintValue(char *tag, unsigned char *val, int len)
|
||||
{
|
||||
#if VERBOSE
|
||||
char obuf[2048];
|
||||
int olen;
|
||||
olen = bin2hex(val, len, obuf);
|
||||
printf("%s = %.*s\n", tag, olen, obuf);
|
||||
#endif
|
||||
}
|
||||
|
||||
void OutputValue(char *tag, unsigned char *val, int len, FILE *rfp,int bitmode)
|
||||
{
|
||||
char obuf[2048];
|
||||
int olen;
|
||||
|
||||
if(bitmode)
|
||||
olen=bin2bint(val,len,obuf);
|
||||
else
|
||||
olen=bin2hex(val,len,obuf);
|
||||
|
||||
fprintf(rfp, "%s = %.*s\n", tag, olen, obuf);
|
||||
#if VERBOSE
|
||||
printf("%s = %.*s\n", tag, olen, obuf);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
@ -1,887 +0,0 @@
|
|||
#!/usr/bin/perl -w
|
||||
# Perl utility to run or verify FIPS 140-2 CMVP algorithm tests based on the
|
||||
# pathnames of input algorithm test files actually present (the unqualified
|
||||
# file names are consistent but the pathnames are not).
|
||||
#
|
||||
|
||||
# FIPS test definitions
|
||||
# List of all the unqualified file names we expect and command lines to run
|
||||
|
||||
# DSA tests
|
||||
my @fips_dsa_test_list = (
|
||||
|
||||
"DSA",
|
||||
|
||||
[ "PQGGen", "fips_dssvs pqg" ],
|
||||
[ "KeyPair", "fips_dssvs keypair" ],
|
||||
[ "SigGen", "fips_dssvs siggen" ],
|
||||
[ "SigVer", "fips_dssvs sigver" ]
|
||||
|
||||
);
|
||||
|
||||
my @fips_dsa_pqgver_test_list = (
|
||||
|
||||
[ "PQGVer", "fips_dssvs pqgver" ]
|
||||
|
||||
);
|
||||
|
||||
# RSA tests
|
||||
|
||||
my @fips_rsa_test_list = (
|
||||
|
||||
"RSA",
|
||||
|
||||
[ "SigGen15", "fips_rsastest" ],
|
||||
[ "SigVer15", "fips_rsavtest" ],
|
||||
[ "SigVerRSA", "fips_rsavtest -x931" ],
|
||||
[ "KeyGenRSA", "fips_rsagtest" ],
|
||||
[ "SigGenRSA", "fips_rsastest -x931" ]
|
||||
|
||||
);
|
||||
|
||||
# Special cases for PSS. The filename itself is
|
||||
# not sufficient to determine the test. Addditionally we
|
||||
# need to examine the file contents to determine the salt length
|
||||
# In these cases the test filename has (saltlen) appended.
|
||||
|
||||
# RSA PSS salt length 0 tests
|
||||
|
||||
my @fips_rsa_pss0_test_list = (
|
||||
|
||||
[ "SigGenPSS(0)", "fips_rsastest -saltlen 0" ],
|
||||
[ "SigVerPSS(0)", "fips_rsavtest -saltlen 0" ]
|
||||
|
||||
);
|
||||
|
||||
# RSA PSS salt length 62 tests
|
||||
|
||||
my @fips_rsa_pss62_test_list = (
|
||||
[ "SigGenPSS(62)", "fips_rsastest -saltlen 62" ],
|
||||
[ "SigVerPSS(62)", "fips_rsavtest -saltlen 62" ]
|
||||
|
||||
);
|
||||
|
||||
# SHA tests
|
||||
|
||||
my @fips_sha_test_list = (
|
||||
|
||||
"SHA",
|
||||
|
||||
[ "SHA1LongMsg", "fips_shatest" ],
|
||||
[ "SHA1Monte", "fips_shatest" ],
|
||||
[ "SHA1ShortMsg", "fips_shatest" ],
|
||||
[ "SHA224LongMsg", "fips_shatest" ],
|
||||
[ "SHA224Monte", "fips_shatest" ],
|
||||
[ "SHA224ShortMsg", "fips_shatest" ],
|
||||
[ "SHA256LongMsg", "fips_shatest" ],
|
||||
[ "SHA256Monte", "fips_shatest" ],
|
||||
[ "SHA256ShortMsg", "fips_shatest" ],
|
||||
[ "SHA384LongMsg", "fips_shatest" ],
|
||||
[ "SHA384Monte", "fips_shatest" ],
|
||||
[ "SHA384ShortMsg", "fips_shatest" ],
|
||||
[ "SHA512LongMsg", "fips_shatest" ],
|
||||
[ "SHA512Monte", "fips_shatest" ],
|
||||
[ "SHA512ShortMsg", "fips_shatest" ]
|
||||
|
||||
);
|
||||
|
||||
# HMAC
|
||||
|
||||
my @fips_hmac_test_list = (
|
||||
|
||||
"HMAC",
|
||||
|
||||
[ "HMAC", "fips_hmactest" ]
|
||||
|
||||
);
|
||||
|
||||
# RAND tests, AES version
|
||||
|
||||
my @fips_rand_aes_test_list = (
|
||||
|
||||
"RAND (AES)",
|
||||
|
||||
[ "ANSI931_AES128MCT", "fips_rngvs mct" ],
|
||||
[ "ANSI931_AES192MCT", "fips_rngvs mct" ],
|
||||
[ "ANSI931_AES256MCT", "fips_rngvs mct" ],
|
||||
[ "ANSI931_AES128VST", "fips_rngvs vst" ],
|
||||
[ "ANSI931_AES192VST", "fips_rngvs vst" ],
|
||||
[ "ANSI931_AES256VST", "fips_rngvs vst" ]
|
||||
|
||||
);
|
||||
|
||||
# RAND tests, DES2 version
|
||||
|
||||
my @fips_rand_des2_test_list = (
|
||||
|
||||
"RAND (DES2)",
|
||||
|
||||
[ "ANSI931_TDES2MCT", "fips_rngvs mct" ],
|
||||
[ "ANSI931_TDES2VST", "fips_rngvs vst" ]
|
||||
|
||||
);
|
||||
|
||||
# AES tests
|
||||
|
||||
my @fips_aes_test_list = (
|
||||
|
||||
"AES",
|
||||
|
||||
[ "CBCGFSbox128", "fips_aesavs -f" ],
|
||||
[ "CBCGFSbox192", "fips_aesavs -f" ],
|
||||
[ "CBCGFSbox256", "fips_aesavs -f" ],
|
||||
[ "CBCKeySbox128", "fips_aesavs -f" ],
|
||||
[ "CBCKeySbox192", "fips_aesavs -f" ],
|
||||
[ "CBCKeySbox256", "fips_aesavs -f" ],
|
||||
[ "CBCMCT128", "fips_aesavs -f" ],
|
||||
[ "CBCMCT192", "fips_aesavs -f" ],
|
||||
[ "CBCMCT256", "fips_aesavs -f" ],
|
||||
[ "CBCMMT128", "fips_aesavs -f" ],
|
||||
[ "CBCMMT192", "fips_aesavs -f" ],
|
||||
[ "CBCMMT256", "fips_aesavs -f" ],
|
||||
[ "CBCVarKey128", "fips_aesavs -f" ],
|
||||
[ "CBCVarKey192", "fips_aesavs -f" ],
|
||||
[ "CBCVarKey256", "fips_aesavs -f" ],
|
||||
[ "CBCVarTxt128", "fips_aesavs -f" ],
|
||||
[ "CBCVarTxt192", "fips_aesavs -f" ],
|
||||
[ "CBCVarTxt256", "fips_aesavs -f" ],
|
||||
[ "CFB128GFSbox128", "fips_aesavs -f" ],
|
||||
[ "CFB128GFSbox192", "fips_aesavs -f" ],
|
||||
[ "CFB128GFSbox256", "fips_aesavs -f" ],
|
||||
[ "CFB128KeySbox128", "fips_aesavs -f" ],
|
||||
[ "CFB128KeySbox192", "fips_aesavs -f" ],
|
||||
[ "CFB128KeySbox256", "fips_aesavs -f" ],
|
||||
[ "CFB128MCT128", "fips_aesavs -f" ],
|
||||
[ "CFB128MCT192", "fips_aesavs -f" ],
|
||||
[ "CFB128MCT256", "fips_aesavs -f" ],
|
||||
[ "CFB128MMT128", "fips_aesavs -f" ],
|
||||
[ "CFB128MMT192", "fips_aesavs -f" ],
|
||||
[ "CFB128MMT256", "fips_aesavs -f" ],
|
||||
[ "CFB128VarKey128", "fips_aesavs -f" ],
|
||||
[ "CFB128VarKey192", "fips_aesavs -f" ],
|
||||
[ "CFB128VarKey256", "fips_aesavs -f" ],
|
||||
[ "CFB128VarTxt128", "fips_aesavs -f" ],
|
||||
[ "CFB128VarTxt192", "fips_aesavs -f" ],
|
||||
[ "CFB128VarTxt256", "fips_aesavs -f" ],
|
||||
[ "CFB8GFSbox128", "fips_aesavs -f" ],
|
||||
[ "CFB8GFSbox192", "fips_aesavs -f" ],
|
||||
[ "CFB8GFSbox256", "fips_aesavs -f" ],
|
||||
[ "CFB8KeySbox128", "fips_aesavs -f" ],
|
||||
[ "CFB8KeySbox192", "fips_aesavs -f" ],
|
||||
[ "CFB8KeySbox256", "fips_aesavs -f" ],
|
||||
[ "CFB8MCT128", "fips_aesavs -f" ],
|
||||
[ "CFB8MCT192", "fips_aesavs -f" ],
|
||||
[ "CFB8MCT256", "fips_aesavs -f" ],
|
||||
[ "CFB8MMT128", "fips_aesavs -f" ],
|
||||
[ "CFB8MMT192", "fips_aesavs -f" ],
|
||||
[ "CFB8MMT256", "fips_aesavs -f" ],
|
||||
[ "CFB8VarKey128", "fips_aesavs -f" ],
|
||||
[ "CFB8VarKey192", "fips_aesavs -f" ],
|
||||
[ "CFB8VarKey256", "fips_aesavs -f" ],
|
||||
[ "CFB8VarTxt128", "fips_aesavs -f" ],
|
||||
[ "CFB8VarTxt192", "fips_aesavs -f" ],
|
||||
[ "CFB8VarTxt256", "fips_aesavs -f" ],
|
||||
|
||||
[ "ECBGFSbox128", "fips_aesavs -f" ],
|
||||
[ "ECBGFSbox192", "fips_aesavs -f" ],
|
||||
[ "ECBGFSbox256", "fips_aesavs -f" ],
|
||||
[ "ECBKeySbox128", "fips_aesavs -f" ],
|
||||
[ "ECBKeySbox192", "fips_aesavs -f" ],
|
||||
[ "ECBKeySbox256", "fips_aesavs -f" ],
|
||||
[ "ECBMCT128", "fips_aesavs -f" ],
|
||||
[ "ECBMCT192", "fips_aesavs -f" ],
|
||||
[ "ECBMCT256", "fips_aesavs -f" ],
|
||||
[ "ECBMMT128", "fips_aesavs -f" ],
|
||||
[ "ECBMMT192", "fips_aesavs -f" ],
|
||||
[ "ECBMMT256", "fips_aesavs -f" ],
|
||||
[ "ECBVarKey128", "fips_aesavs -f" ],
|
||||
[ "ECBVarKey192", "fips_aesavs -f" ],
|
||||
[ "ECBVarKey256", "fips_aesavs -f" ],
|
||||
[ "ECBVarTxt128", "fips_aesavs -f" ],
|
||||
[ "ECBVarTxt192", "fips_aesavs -f" ],
|
||||
[ "ECBVarTxt256", "fips_aesavs -f" ],
|
||||
[ "OFBGFSbox128", "fips_aesavs -f" ],
|
||||
[ "OFBGFSbox192", "fips_aesavs -f" ],
|
||||
[ "OFBGFSbox256", "fips_aesavs -f" ],
|
||||
[ "OFBKeySbox128", "fips_aesavs -f" ],
|
||||
[ "OFBKeySbox192", "fips_aesavs -f" ],
|
||||
[ "OFBKeySbox256", "fips_aesavs -f" ],
|
||||
[ "OFBMCT128", "fips_aesavs -f" ],
|
||||
[ "OFBMCT192", "fips_aesavs -f" ],
|
||||
[ "OFBMCT256", "fips_aesavs -f" ],
|
||||
[ "OFBMMT128", "fips_aesavs -f" ],
|
||||
[ "OFBMMT192", "fips_aesavs -f" ],
|
||||
[ "OFBMMT256", "fips_aesavs -f" ],
|
||||
[ "OFBVarKey128", "fips_aesavs -f" ],
|
||||
[ "OFBVarKey192", "fips_aesavs -f" ],
|
||||
[ "OFBVarKey256", "fips_aesavs -f" ],
|
||||
[ "OFBVarTxt128", "fips_aesavs -f" ],
|
||||
[ "OFBVarTxt192", "fips_aesavs -f" ],
|
||||
[ "OFBVarTxt256", "fips_aesavs -f" ]
|
||||
|
||||
);
|
||||
|
||||
my @fips_aes_cfb1_test_list = (
|
||||
|
||||
# AES CFB1 tests
|
||||
|
||||
[ "CFB1GFSbox128", "fips_aesavs -f" ],
|
||||
[ "CFB1GFSbox192", "fips_aesavs -f" ],
|
||||
[ "CFB1GFSbox256", "fips_aesavs -f" ],
|
||||
[ "CFB1KeySbox128", "fips_aesavs -f" ],
|
||||
[ "CFB1KeySbox192", "fips_aesavs -f" ],
|
||||
[ "CFB1KeySbox256", "fips_aesavs -f" ],
|
||||
[ "CFB1MCT128", "fips_aesavs -f" ],
|
||||
[ "CFB1MCT192", "fips_aesavs -f" ],
|
||||
[ "CFB1MCT256", "fips_aesavs -f" ],
|
||||
[ "CFB1MMT128", "fips_aesavs -f" ],
|
||||
[ "CFB1MMT192", "fips_aesavs -f" ],
|
||||
[ "CFB1MMT256", "fips_aesavs -f" ],
|
||||
[ "CFB1VarKey128", "fips_aesavs -f" ],
|
||||
[ "CFB1VarKey192", "fips_aesavs -f" ],
|
||||
[ "CFB1VarKey256", "fips_aesavs -f" ],
|
||||
[ "CFB1VarTxt128", "fips_aesavs -f" ],
|
||||
[ "CFB1VarTxt192", "fips_aesavs -f" ],
|
||||
[ "CFB1VarTxt256", "fips_aesavs -f" ]
|
||||
|
||||
);
|
||||
|
||||
# Triple DES tests
|
||||
|
||||
my @fips_des3_test_list = (
|
||||
|
||||
"Triple DES",
|
||||
|
||||
[ "TCBCinvperm", "fips_desmovs -f" ],
|
||||
[ "TCBCMMT1", "fips_desmovs -f" ],
|
||||
[ "TCBCMMT2", "fips_desmovs -f" ],
|
||||
[ "TCBCMMT3", "fips_desmovs -f" ],
|
||||
[ "TCBCMonte1", "fips_desmovs -f" ],
|
||||
[ "TCBCMonte2", "fips_desmovs -f" ],
|
||||
[ "TCBCMonte3", "fips_desmovs -f" ],
|
||||
[ "TCBCpermop", "fips_desmovs -f" ],
|
||||
[ "TCBCsubtab", "fips_desmovs -f" ],
|
||||
[ "TCBCvarkey", "fips_desmovs -f" ],
|
||||
[ "TCBCvartext", "fips_desmovs -f" ],
|
||||
[ "TCFB64invperm", "fips_desmovs -f" ],
|
||||
[ "TCFB64MMT1", "fips_desmovs -f" ],
|
||||
[ "TCFB64MMT2", "fips_desmovs -f" ],
|
||||
[ "TCFB64MMT3", "fips_desmovs -f" ],
|
||||
[ "TCFB64Monte1", "fips_desmovs -f" ],
|
||||
[ "TCFB64Monte2", "fips_desmovs -f" ],
|
||||
[ "TCFB64Monte3", "fips_desmovs -f" ],
|
||||
[ "TCFB64permop", "fips_desmovs -f" ],
|
||||
[ "TCFB64subtab", "fips_desmovs -f" ],
|
||||
[ "TCFB64varkey", "fips_desmovs -f" ],
|
||||
[ "TCFB64vartext", "fips_desmovs -f" ],
|
||||
[ "TCFB8invperm", "fips_desmovs -f" ],
|
||||
[ "TCFB8MMT1", "fips_desmovs -f" ],
|
||||
[ "TCFB8MMT2", "fips_desmovs -f" ],
|
||||
[ "TCFB8MMT3", "fips_desmovs -f" ],
|
||||
[ "TCFB8Monte1", "fips_desmovs -f" ],
|
||||
[ "TCFB8Monte2", "fips_desmovs -f" ],
|
||||
[ "TCFB8Monte3", "fips_desmovs -f" ],
|
||||
[ "TCFB8permop", "fips_desmovs -f" ],
|
||||
[ "TCFB8subtab", "fips_desmovs -f" ],
|
||||
[ "TCFB8varkey", "fips_desmovs -f" ],
|
||||
[ "TCFB8vartext", "fips_desmovs -f" ],
|
||||
[ "TECBinvperm", "fips_desmovs -f" ],
|
||||
[ "TECBMMT1", "fips_desmovs -f" ],
|
||||
[ "TECBMMT2", "fips_desmovs -f" ],
|
||||
[ "TECBMMT3", "fips_desmovs -f" ],
|
||||
[ "TECBMonte1", "fips_desmovs -f" ],
|
||||
[ "TECBMonte2", "fips_desmovs -f" ],
|
||||
[ "TECBMonte3", "fips_desmovs -f" ],
|
||||
[ "TECBpermop", "fips_desmovs -f" ],
|
||||
[ "TECBsubtab", "fips_desmovs -f" ],
|
||||
[ "TECBvarkey", "fips_desmovs -f" ],
|
||||
[ "TECBvartext", "fips_desmovs -f" ],
|
||||
[ "TOFBinvperm", "fips_desmovs -f" ],
|
||||
[ "TOFBMMT1", "fips_desmovs -f" ],
|
||||
[ "TOFBMMT2", "fips_desmovs -f" ],
|
||||
[ "TOFBMMT3", "fips_desmovs -f" ],
|
||||
[ "TOFBMonte1", "fips_desmovs -f" ],
|
||||
[ "TOFBMonte2", "fips_desmovs -f" ],
|
||||
[ "TOFBMonte3", "fips_desmovs -f" ],
|
||||
[ "TOFBpermop", "fips_desmovs -f" ],
|
||||
[ "TOFBsubtab", "fips_desmovs -f" ],
|
||||
[ "TOFBvarkey", "fips_desmovs -f" ],
|
||||
[ "TOFBvartext", "fips_desmovs -f" ]
|
||||
|
||||
);
|
||||
|
||||
my @fips_des3_cfb1_test_list = (
|
||||
|
||||
# DES3 CFB1 tests
|
||||
|
||||
[ "TCFB1invperm", "fips_desmovs -f" ],
|
||||
[ "TCFB1MMT1", "fips_desmovs -f" ],
|
||||
[ "TCFB1MMT2", "fips_desmovs -f" ],
|
||||
[ "TCFB1MMT3", "fips_desmovs -f" ],
|
||||
[ "TCFB1Monte1", "fips_desmovs -f" ],
|
||||
[ "TCFB1Monte2", "fips_desmovs -f" ],
|
||||
[ "TCFB1Monte3", "fips_desmovs -f" ],
|
||||
[ "TCFB1permop", "fips_desmovs -f" ],
|
||||
[ "TCFB1subtab", "fips_desmovs -f" ],
|
||||
[ "TCFB1varkey", "fips_desmovs -f" ],
|
||||
[ "TCFB1vartext", "fips_desmovs -f" ],
|
||||
|
||||
);
|
||||
|
||||
# Verification special cases.
|
||||
# In most cases the output of a test is deterministic and
|
||||
# it can be compared to a known good result. A few involve
|
||||
# the genration and use of random keys and the output will
|
||||
# be different each time. In thoses cases we perform special tests
|
||||
# to simply check their consistency. For example signature generation
|
||||
# output will be run through signature verification to see if all outputs
|
||||
# show as valid.
|
||||
#
|
||||
|
||||
my %verify_special = (
|
||||
"PQGGen" => "fips_dssvs pqgver",
|
||||
"KeyPair" => "fips_dssvs keyver",
|
||||
"SigGen" => "fips_dssvs sigver",
|
||||
"SigGen15" => "fips_rsavtest",
|
||||
"SigGenRSA" => "fips_rsavtest -x931",
|
||||
"SigGenPSS(0)" => "fips_rsavtest -saltlen 0",
|
||||
"SigGenPSS(62)" => "fips_rsavtest -saltlen 62",
|
||||
);
|
||||
|
||||
my $win32 = $^O =~ m/mswin/i;
|
||||
my $onedir = 0;
|
||||
my $filter = "";
|
||||
my $tvdir;
|
||||
my $tprefix;
|
||||
my $shwrap_prefix;
|
||||
my $debug = 0;
|
||||
my $quiet = 0;
|
||||
my $notest = 0;
|
||||
my $verify = 1;
|
||||
my $rspdir = "rsp";
|
||||
my $ignore_missing = 0;
|
||||
my $ignore_bogus = 0;
|
||||
my $bufout = '';
|
||||
my $list_tests = 0;
|
||||
|
||||
my %fips_enabled = (
|
||||
dsa => 1,
|
||||
"dsa-pqgver" => 0,
|
||||
rsa => 1,
|
||||
"rsa-pss0" => 0,
|
||||
"rsa-pss62" => 1,
|
||||
sha => 1,
|
||||
hmac => 1,
|
||||
"rand-aes" => 1,
|
||||
"rand-des2" => 0,
|
||||
aes => 1,
|
||||
"aes-cfb1" => 0,
|
||||
des3 => 1,
|
||||
"des3-cfb1" => 0
|
||||
);
|
||||
|
||||
foreach (@ARGV) {
|
||||
if ( $_ eq "--win32" ) {
|
||||
$win32 = 1;
|
||||
}
|
||||
elsif ( $_ eq "--onedir" ) {
|
||||
$onedir = 1;
|
||||
}
|
||||
elsif ( $_ eq "--debug" ) {
|
||||
$debug = 1;
|
||||
}
|
||||
elsif ( $_ eq "--ignore-missing" ) {
|
||||
$ignore_missing = 1;
|
||||
}
|
||||
elsif ( $_ eq "--ignore-bogus" ) {
|
||||
$ignore_bogus = 1;
|
||||
}
|
||||
elsif ( $_ eq "--generate" ) {
|
||||
$verify = 0;
|
||||
}
|
||||
elsif ( $_ eq "--notest" ) {
|
||||
$notest = 1;
|
||||
}
|
||||
elsif ( $_ eq "--quiet" ) {
|
||||
$quiet = 1;
|
||||
}
|
||||
elsif (/--dir=(.*)$/) {
|
||||
$tvdir = $1;
|
||||
}
|
||||
elsif (/--rspdir=(.*)$/) {
|
||||
$rspdir = $1;
|
||||
}
|
||||
elsif (/--tprefix=(.*)$/) {
|
||||
$tprefix = $1;
|
||||
}
|
||||
elsif (/--shwrap_prefix=(.*)$/) {
|
||||
$shwrap_prefix = $1;
|
||||
}
|
||||
elsif (/^--(enable|disable)-(.*)$/) {
|
||||
if ( !exists $fips_enabled{$2} ) {
|
||||
print STDERR "Unknown test $2\n";
|
||||
}
|
||||
if ( $1 eq "enable" ) {
|
||||
$fips_enabled{$2} = 1;
|
||||
}
|
||||
else {
|
||||
$fips_enabled{$2} = 0;
|
||||
}
|
||||
}
|
||||
elsif (/--filter=(.*)$/) {
|
||||
$filter = $1;
|
||||
}
|
||||
elsif (/^--list-tests$/) {
|
||||
$list_tests = 1;
|
||||
}
|
||||
else {
|
||||
Help();
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
my @fips_test_list;
|
||||
|
||||
push @fips_test_list, @fips_dsa_test_list if $fips_enabled{"dsa"};
|
||||
push @fips_test_list, @fips_dsa_pqgver_test_list if $fips_enabled{"dsa-pqgver"};
|
||||
push @fips_test_list, @fips_rsa_test_list if $fips_enabled{"rsa"};
|
||||
push @fips_test_list, @fips_rsa_pss0_test_list if $fips_enabled{"rsa-pss0"};
|
||||
push @fips_test_list, @fips_rsa_pss62_test_list if $fips_enabled{"rsa-pss62"};
|
||||
push @fips_test_list, @fips_sha_test_list if $fips_enabled{"sha"};
|
||||
push @fips_test_list, @fips_hmac_test_list if $fips_enabled{"hmac"};
|
||||
push @fips_test_list, @fips_rand_aes_test_list if $fips_enabled{"rand-aes"};
|
||||
push @fips_test_list, @fips_rand_des2_test_list if $fips_enabled{"rand-des2"};
|
||||
push @fips_test_list, @fips_aes_test_list if $fips_enabled{"aes"};
|
||||
push @fips_test_list, @fips_aes_cfb1_test_list if $fips_enabled{"aes-cfb1"};
|
||||
push @fips_test_list, @fips_des3_test_list if $fips_enabled{"des3"};
|
||||
push @fips_test_list, @fips_des3_cfb1_test_list if $fips_enabled{"des3-cfb1"};
|
||||
|
||||
if ($list_tests) {
|
||||
my ( $test, $en );
|
||||
print "=====TEST LIST=====\n";
|
||||
foreach $test ( sort keys %fips_enabled ) {
|
||||
$en = $fips_enabled{$test};
|
||||
$test =~ tr/[a-z]/[A-Z]/;
|
||||
printf "%-10s %s\n", $test, $en ? "enabled" : "disabled";
|
||||
}
|
||||
exit(0);
|
||||
}
|
||||
|
||||
foreach (@fips_test_list) {
|
||||
next unless ref($_);
|
||||
my $nm = $_->[0];
|
||||
$_->[2] = "";
|
||||
$_->[3] = "";
|
||||
print STDERR "Duplicate test $nm\n" if exists $fips_tests{$nm};
|
||||
$fips_tests{$nm} = $_;
|
||||
}
|
||||
|
||||
$tvdir = "." unless defined $tvdir;
|
||||
|
||||
if ($win32) {
|
||||
if ( !defined $tprefix ) {
|
||||
if ($onedir) {
|
||||
$tprefix = ".\\";
|
||||
}
|
||||
else {
|
||||
$tprefix = "..\\out32dll\\";
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
if ($onedir) {
|
||||
$tprefix = "./" unless defined $tprefix;
|
||||
$shwrap_prefix = "./" unless defined $shwrap_prefix;
|
||||
}
|
||||
else {
|
||||
$tprefix = "../test/" unless defined $tprefix;
|
||||
$shwrap_prefix = "../util/" unless defined $shwrap_prefix;
|
||||
}
|
||||
}
|
||||
|
||||
sanity_check_exe( $win32, $tprefix, $shwrap_prefix );
|
||||
|
||||
my $cmd_prefix = $win32 ? "" : "${shwrap_prefix}shlib_wrap.sh ";
|
||||
|
||||
find_files( $filter, $tvdir );
|
||||
|
||||
sanity_check_files();
|
||||
|
||||
my ( $runerr, $cmperr, $cmpok, $scheckrunerr, $scheckerr, $scheckok, $skipcnt )
|
||||
= ( 0, 0, 0, 0, 0, 0, 0 );
|
||||
|
||||
exit(0) if $notest;
|
||||
|
||||
run_tests( $verify, $win32, $tprefix, $filter, $tvdir );
|
||||
|
||||
if ($verify) {
|
||||
print "ALGORITHM TEST VERIFY SUMMARY REPORT:\n";
|
||||
print "Tests skipped due to missing files: $skipcnt\n";
|
||||
print "Algorithm test program execution failures: $runerr\n";
|
||||
print "Test comparisons successful: $cmpok\n";
|
||||
print "Test comparisons failed: $cmperr\n";
|
||||
print "Test sanity checks successful: $scheckok\n";
|
||||
print "Test sanity checks failed: $scheckerr\n";
|
||||
print "Sanity check program execution failures: $scheckrunerr\n";
|
||||
|
||||
if ( $runerr || $cmperr || $scheckrunerr || $scheckerr ) {
|
||||
print "***TEST FAILURE***\n";
|
||||
}
|
||||
else {
|
||||
print "***ALL TESTS SUCCESSFUL***\n";
|
||||
}
|
||||
}
|
||||
else {
|
||||
print "ALGORITHM TEST SUMMARY REPORT:\n";
|
||||
print "Tests skipped due to missing files: $skipcnt\n";
|
||||
print "Algorithm test program execution failures: $runerr\n";
|
||||
|
||||
if ($runerr) {
|
||||
print "***TEST FAILURE***\n";
|
||||
}
|
||||
else {
|
||||
print "***ALL TESTS SUCCESSFUL***\n";
|
||||
}
|
||||
}
|
||||
|
||||
#--------------------------------
|
||||
sub Help {
|
||||
( my $cmd ) = ( $0 =~ m#([^/]+)$# );
|
||||
print <<EOF;
|
||||
$cmd: generate run CMVP algorithm tests
|
||||
--debug Enable debug output
|
||||
--dir=<dirname> Optional root for *.req file search
|
||||
--filter=<regexp>
|
||||
--onedir <dirname> Assume all components in current directory
|
||||
--rspdir=<dirname> Name of subdirectories containing *.rsp files, default "rsp"
|
||||
--shwrap_prefix=<prefix>
|
||||
--tprefix=<prefix>
|
||||
--ignore-bogus Ignore duplicate or bogus files
|
||||
--ignore-missing Ignore missing test files
|
||||
--quiet Shhh....
|
||||
--generate Generate algorithm test output
|
||||
--win32 Win32 environment
|
||||
--enable-<alg> Enable algorithm set <alg>.
|
||||
--disable-<alg> Disable algorithm set <alg>.
|
||||
Where <alg> can be one of:
|
||||
EOF
|
||||
|
||||
while (my ($key, $value) = each %fips_enabled)
|
||||
{
|
||||
printf "\t\t%-20s(%s by default)\n", $key ,
|
||||
$value ? "enabled" : "disabled";
|
||||
}
|
||||
}
|
||||
|
||||
# Sanity check to see if all necessary executables exist
|
||||
|
||||
sub sanity_check_exe {
|
||||
my ( $win32, $tprefix, $shwrap_prefix ) = @_;
|
||||
my %exe_list;
|
||||
my $bad = 0;
|
||||
$exe_list{ $shwrap_prefix . "shlib_wrap.sh" } = 1 unless $win32;
|
||||
foreach (@fips_test_list) {
|
||||
next unless ref($_);
|
||||
my $cmd = $_->[1];
|
||||
$cmd =~ s/ .*$//;
|
||||
$cmd = $tprefix . $cmd;
|
||||
$cmd .= ".exe" if $win32;
|
||||
$exe_list{$cmd} = 1;
|
||||
}
|
||||
|
||||
foreach ( sort keys %exe_list ) {
|
||||
if ( !-f $_ ) {
|
||||
print STDERR "ERROR: can't find executable $_\n";
|
||||
$bad = 1;
|
||||
}
|
||||
}
|
||||
if ($bad) {
|
||||
print STDERR "FATAL ERROR: executables missing\n";
|
||||
exit(1);
|
||||
}
|
||||
elsif ($debug) {
|
||||
print STDERR "Executable sanity check passed OK\n";
|
||||
}
|
||||
}
|
||||
|
||||
# Search for all request and response files
|
||||
|
||||
sub find_files {
|
||||
my ( $filter, $dir ) = @_;
|
||||
my ( $dirh, $testname );
|
||||
opendir( $dirh, $dir );
|
||||
while ( $_ = readdir($dirh) ) {
|
||||
next if ( $_ eq "." || $_ eq ".." );
|
||||
$_ = "$dir/$_";
|
||||
if ( -f "$_" ) {
|
||||
if (/\/([^\/]*)\.rsp$/) {
|
||||
$testname = fix_pss( $1, $_ );
|
||||
if ( exists $fips_tests{$testname} ) {
|
||||
if ( $fips_tests{$testname}->[3] eq "" ) {
|
||||
$fips_tests{$testname}->[3] = $_;
|
||||
}
|
||||
else {
|
||||
print STDERR
|
||||
"WARNING: duplicate response file $_ for test $testname\n";
|
||||
$nbogus++;
|
||||
}
|
||||
}
|
||||
else {
|
||||
print STDERR "WARNING: bogus file $_\n";
|
||||
$nbogus++;
|
||||
}
|
||||
}
|
||||
next unless /$filter.*\.req$/i;
|
||||
if (/\/([^\/]*)\.req$/) {
|
||||
$testname = fix_pss( $1, $_ );
|
||||
if ( exists $fips_tests{$testname} ) {
|
||||
if ( $fips_tests{$testname}->[2] eq "" ) {
|
||||
$fips_tests{$testname}->[2] = $_;
|
||||
}
|
||||
else {
|
||||
print STDERR
|
||||
"WARNING: duplicate request file $_ for test $testname\n";
|
||||
$nbogus++;
|
||||
}
|
||||
|
||||
}
|
||||
elsif ( !/SHAmix\.req$/ ) {
|
||||
print STDERR "WARNING: unrecognized filename $_\n";
|
||||
$nbogus++;
|
||||
}
|
||||
}
|
||||
}
|
||||
elsif ( -d "$_" ) {
|
||||
find_files( $filter, $_ );
|
||||
}
|
||||
}
|
||||
closedir($dirh);
|
||||
}
|
||||
|
||||
sub fix_pss {
|
||||
my ( $test, $path ) = @_;
|
||||
my $sl = "";
|
||||
local $_;
|
||||
if ( $test =~ /PSS/ ) {
|
||||
open( IN, $path ) || die "Can't Open File $path";
|
||||
while (<IN>) {
|
||||
if (/^\s*#\s*salt\s+len:\s+(\d+)\s*$/i) {
|
||||
$sl = $1;
|
||||
last;
|
||||
}
|
||||
}
|
||||
close IN;
|
||||
if ( $sl eq "" ) {
|
||||
print STDERR "WARNING: No Salt length detected for file $path\n";
|
||||
}
|
||||
else {
|
||||
return $test . "($sl)";
|
||||
}
|
||||
}
|
||||
return $test;
|
||||
}
|
||||
|
||||
sub sanity_check_files {
|
||||
my $bad = 0;
|
||||
foreach (@fips_test_list) {
|
||||
next unless ref($_);
|
||||
my ( $tst, $cmd, $req, $resp ) = @$_;
|
||||
|
||||
#print STDERR "FILES $tst, $cmd, $req, $resp\n";
|
||||
if ( $req eq "" ) {
|
||||
print STDERR "WARNING: missing request file for $tst\n";
|
||||
$bad = 1;
|
||||
next;
|
||||
}
|
||||
if ( $verify && $resp eq "" ) {
|
||||
print STDERR "WARNING: no response file for test $tst\n";
|
||||
$bad = 1;
|
||||
}
|
||||
elsif ( !$verify && $resp ne "" ) {
|
||||
print STDERR "WARNING: response file $resp will be overwritten\n";
|
||||
}
|
||||
}
|
||||
if ($bad) {
|
||||
print STDERR "ERROR: test vector file set not complete\n";
|
||||
exit(1) unless $ignore_missing;
|
||||
}
|
||||
if ($nbogus) {
|
||||
print STDERR
|
||||
"ERROR: $nbogus bogus or duplicate request and response files\n";
|
||||
exit(1) unless $ignore_bogus;
|
||||
}
|
||||
if ( $debug && !$nbogus && !$bad ) {
|
||||
print STDERR "test vector file set complete\n";
|
||||
}
|
||||
}
|
||||
|
||||
sub run_tests {
|
||||
my ( $verify, $win32, $tprefix, $filter, $tvdir ) = @_;
|
||||
my ( $tname, $tref );
|
||||
my $bad = 0;
|
||||
foreach (@fips_test_list) {
|
||||
if ( !ref($_) ) {
|
||||
print "Running $_ tests\n" unless $quiet;
|
||||
next;
|
||||
}
|
||||
my ( $tname, $tcmd, $req, $rsp ) = @$_;
|
||||
my $out = $rsp;
|
||||
if ($verify) {
|
||||
$out =~ s/\.rsp$/.tst/;
|
||||
}
|
||||
if ( $req eq "" ) {
|
||||
print STDERR
|
||||
"WARNING: Request file for $tname missing: test skipped\n";
|
||||
$skipcnt++;
|
||||
next;
|
||||
}
|
||||
if ( $verify && $rsp eq "" ) {
|
||||
print STDERR
|
||||
"WARNING: Response file for $tname missing: test skipped\n";
|
||||
$skipcnt++;
|
||||
next;
|
||||
}
|
||||
elsif ( !$verify ) {
|
||||
if ( $rsp ne "" ) {
|
||||
print STDERR "WARNING: Response file for $tname deleted\n";
|
||||
unlink $rsp;
|
||||
}
|
||||
$out = $req;
|
||||
$out =~ s|/req/(\S+)\.req|/$rspdir/$1.rsp|;
|
||||
my $outdir = $out;
|
||||
$outdir =~ s|/[^/]*$||;
|
||||
if ( !-d $outdir ) {
|
||||
print STDERR "DEBUG: Creating directory $outdir\n" if $debug;
|
||||
mkdir($outdir) || die "Can't create directory $outdir";
|
||||
}
|
||||
}
|
||||
my $cmd = "$cmd_prefix$tprefix$tcmd ";
|
||||
if ( $tcmd =~ /-f$/ ) {
|
||||
$cmd .= "\"$req\" \"$out\"";
|
||||
}
|
||||
else {
|
||||
$cmd .= "<\"$req\" >\"$out\"";
|
||||
}
|
||||
print STDERR "DEBUG: running test $tname\n" if ( $debug && !$verify );
|
||||
system($cmd);
|
||||
if ( $? != 0 ) {
|
||||
print STDERR
|
||||
"WARNING: error executing test $tname for command: $cmd\n";
|
||||
$runerr++;
|
||||
next;
|
||||
}
|
||||
if ($verify) {
|
||||
if ( exists $verify_special{$tname} ) {
|
||||
my $vout = $rsp;
|
||||
$vout =~ s/\.rsp$/.ver/;
|
||||
$tcmd = $verify_special{$tname};
|
||||
$cmd = "$cmd_prefix$tprefix$tcmd ";
|
||||
$cmd .= "<\"$out\" >\"$vout\"";
|
||||
system($cmd);
|
||||
if ( $? != 0 ) {
|
||||
print STDERR
|
||||
"WARNING: error executing verify test $tname $cmd\n";
|
||||
$scheckrunerr++;
|
||||
next;
|
||||
}
|
||||
my ( $fcount, $pcount ) = ( 0, 0 );
|
||||
open VER, "$vout";
|
||||
while (<VER>) {
|
||||
if (/^Result\s*=\s*(\S*)\s*$/i)
|
||||
|
||||
{
|
||||
if ( $1 eq "F" ) {
|
||||
$fcount++;
|
||||
}
|
||||
else {
|
||||
$pcount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
close VER;
|
||||
|
||||
unlink $vout;
|
||||
if ( $fcount || $debug ) {
|
||||
print STDERR "DEBUG: $tname, Pass=$pcount, Fail=$fcount\n";
|
||||
}
|
||||
if ( $fcount || !$pcount ) {
|
||||
$scheckerr++;
|
||||
}
|
||||
else {
|
||||
$scheckok++;
|
||||
}
|
||||
|
||||
}
|
||||
elsif ( !cmp_file( $tname, $rsp, $out ) ) {
|
||||
$cmperr++;
|
||||
}
|
||||
else {
|
||||
$cmpok++;
|
||||
}
|
||||
unlink $out;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sub cmp_file {
|
||||
my ( $tname, $rsp, $tst ) = @_;
|
||||
my ( $rspf, $tstf );
|
||||
my ( $rspline, $tstline );
|
||||
if ( !open( $rspf, $rsp ) ) {
|
||||
print STDERR "ERROR: can't open request file $rsp\n";
|
||||
return 0;
|
||||
}
|
||||
if ( !open( $tstf, $tst ) ) {
|
||||
print STDERR "ERROR: can't open output file $tst\n";
|
||||
return 0;
|
||||
}
|
||||
for ( ; ; ) {
|
||||
$rspline = next_line($rspf);
|
||||
$tstline = next_line($tstf);
|
||||
if ( !defined($rspline) && !defined($tstline) ) {
|
||||
print STDERR "DEBUG: $tname file comparison OK\n" if $debug;
|
||||
return 1;
|
||||
}
|
||||
if ( !defined($rspline) ) {
|
||||
print STDERR "ERROR: $tname EOF on $rsp\n";
|
||||
return 0;
|
||||
}
|
||||
if ( !defined($tstline) ) {
|
||||
print STDERR "ERROR: $tname EOF on $tst\n";
|
||||
return 0;
|
||||
}
|
||||
|
||||
# Workaround for bug in RAND des2 test output */
|
||||
if ( $tstline =~ /^Key2 =/ && $rspline =~ /^Key1 =/ ) {
|
||||
$rspline =~ s/^Key1/Key2/;
|
||||
}
|
||||
|
||||
if ( $tstline ne $rspline ) {
|
||||
print STDERR "ERROR: $tname mismatch:\n";
|
||||
print STDERR "\t \"$tstline\" != \"$rspline\"\n";
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
sub next_line {
|
||||
my ($in) = @_;
|
||||
|
||||
while (<$in>) {
|
||||
chomp;
|
||||
|
||||
# Delete comments
|
||||
s/#.*$//;
|
||||
|
||||
# Ignore blank lines
|
||||
next if (/^\s*$/);
|
||||
|
||||
# Translate multiple space into one
|
||||
s/\s+/ /g;
|
||||
# Delete trailing whitespace
|
||||
s/\s+$//;
|
||||
return $_;
|
||||
}
|
||||
return undef;
|
||||
}
|
||||
|
|
@ -1,178 +0,0 @@
|
|||
#!/bin/sh -e
|
||||
#
|
||||
# Copyright (c) 2005-2007 The OpenSSL Project.
|
||||
#
|
||||
# Depending on output file name, the script either embeds fingerprint
|
||||
# into libcrypto.so or static application. "Static" refers to static
|
||||
# libcrypto.a, not [necessarily] application per se.
|
||||
#
|
||||
# Even though this script is called fipsld, it expects C compiler
|
||||
# command line syntax and $FIPSLD_CC or $CC environment variable set
|
||||
# and can even be used to compile source files.
|
||||
|
||||
#set -x
|
||||
|
||||
CC=${FIPSLD_CC:-${CC}}
|
||||
[ -n "${CC}" ] || { echo '$CC is not defined'; exit 1; }
|
||||
|
||||
# Initially -c wasn't intended to be interpreted here, but it might
|
||||
# make life easier for those who want to build FIPS-ified applications
|
||||
# with minimal [if any] modifications to their Makefiles...
|
||||
( while [ "x$1" != "x" -a "x$1" != "x-c" -a "x$1" != "x-E" ]; do shift; done;
|
||||
[ $# -ge 1 ]
|
||||
) && exec ${CC} "$@"
|
||||
|
||||
TARGET=`(while [ "x$1" != "x" -a "x$1" != "x-o" ]; do shift; done; echo $2)`
|
||||
|
||||
# If using an auto-tooled (autoconf/automake/libtool) project,
|
||||
# configure will fail when testing the compiler or even performing
|
||||
# simple checks. Pass-through to compiler directly if application is
|
||||
# is not being linked with libcrypto, allowing auto-tooled applications
|
||||
# to utilize fipsld (e.g. CC=/usr/local/ssl/bin/fipsld FIPSLD_CC=gcc
|
||||
# ./configure && make). But keep in mind[!] that if certified code
|
||||
# resides in a shared library, then fipsld *may not* be used and
|
||||
# end-developer should not modify application configuration and build
|
||||
# procedures. This is because in-core fingerprint and associated
|
||||
# procedures are already embedded into and executed in shared library
|
||||
# context.
|
||||
case `basename "${TARGET}"` in
|
||||
libcrypto*|libfips*|*.dll) ;;
|
||||
*) case "$*" in
|
||||
*libcrypto.a*|*-lcrypto*|*fipscanister.o*) ;;
|
||||
*) exec ${CC} "$@" ;;
|
||||
esac
|
||||
esac
|
||||
|
||||
[ -n "${TARGET}" ] || { echo 'no -o specified'; exit 1; }
|
||||
|
||||
# Turn on debugging output?
|
||||
( while [ "x$1" != "x" -a "x$1" != "x-DDEBUG_FINGERPRINT_PREMAIN" ]; do shift; done;
|
||||
[ $# -ge 1 ]
|
||||
) && set -x
|
||||
|
||||
THERE="`echo $0 | sed -e 's|[^/]*$||'`"..
|
||||
|
||||
# fipscanister.o can appear in command line
|
||||
CANISTER_O=`(while [ "x$1" != "x" ]; do case "$1" in *fipscanister.o) echo $1; exit;; esac; shift; done)`
|
||||
if [ -z "${CANISTER_O}" ]; then
|
||||
# If set, FIPSLIBDIR is location of installed validated FIPS module
|
||||
if [ -n "${FIPSLIBDIR}" ]; then
|
||||
CANISTER_O="${FIPSLIBDIR}/fipscanister.o"
|
||||
elif [ -f "${THERE}/fips/fipscanister.o" ]; then
|
||||
CANISTER_O="${THERE}/fips/fipscanister.o"
|
||||
elif [ -f "${THERE}/lib/fipscanister.o" ]; then
|
||||
CANISTER_O="${THERE}/lib/fipscanister.o"
|
||||
fi
|
||||
CANISTER_O_CMD="${CANISTER_O}"
|
||||
fi
|
||||
[ -f ${CANISTER_O} ] || { echo "unable to find ${CANISTER_O}"; exit 1; }
|
||||
|
||||
PREMAIN_C=`dirname "${CANISTER_O}"`/fips_premain.c
|
||||
|
||||
HMAC_KEY="etaonrishdlcupfm"
|
||||
|
||||
case "`(uname -s) 2>/dev/null`" in
|
||||
OSF1|IRIX*) _WL_PREMAIN="-Wl,-init,FINGERPRINT_premain" ;;
|
||||
HP-UX) _WL_PREMAIN="-Wl,+init,FINGERPRINT_premain" ;;
|
||||
AIX) _WL_PREMAIN="-Wl,-binitfini:FINGERPRINT_premain,-bnoobjreorder";;
|
||||
Darwin) ( while [ "x$1" != "x" -a "x$1" != "x-dynamiclib" ]; do shift; done;
|
||||
[ $# -ge 1 ]
|
||||
) && _WL_PREMAIN="-Wl,-init,_FINGERPRINT_premain" ;;
|
||||
esac
|
||||
|
||||
case "${TARGET}" in
|
||||
[!/]*) TARGET=./${TARGET} ;;
|
||||
esac
|
||||
|
||||
case `basename "${TARGET}"` in
|
||||
lib*|*.dll) # must be linking a shared lib...
|
||||
# Shared lib creation can be taking place in the source
|
||||
# directory only, but fipscanister.o can reside elsewhere...
|
||||
FINGERTYPE="${THERE}/fips/fips_standalone_sha1"
|
||||
|
||||
# verify fipspremain.c against its detached signature...
|
||||
${FINGERTYPE} "${PREMAIN_C}" | sed "s/(.*\//(/" | \
|
||||
diff -w "${PREMAIN_C}.sha1" - || \
|
||||
{ echo "${PREMAIN_C} fingerprint mismatch"; exit 1; }
|
||||
# verify fipscanister.o against its detached signature...
|
||||
${FINGERTYPE} "${CANISTER_O}" | sed "s/(.*\//(/" | \
|
||||
diff -w "${CANISTER_O}.sha1" - || \
|
||||
{ echo "${CANISTER_O} fingerprint mismatch"; exit 1; }
|
||||
|
||||
# Temporarily remove fipscanister.o from libcrypto.a!
|
||||
# We are required to use the standalone copy...
|
||||
if [ -f "${THERE}/libcrypto.a" ]; then
|
||||
if ar d "${THERE}/libcrypto.a" fipscanister.o; then
|
||||
(ranlib "${THERE}/libcrypto.a") 2>/dev/null || :
|
||||
trap 'ar r "${THERE}/libcrypto.a" "${CANISTER_O}";
|
||||
(ranlib "${THERE}/libcrypto.a") 2>/dev/null || :;
|
||||
sleep 1;
|
||||
touch -c "${TARGET}"' 0
|
||||
fi
|
||||
fi
|
||||
|
||||
/bin/rm -f "${TARGET}"
|
||||
${CC} ${CANISTER_O_CMD:+"${CANISTER_O_CMD}"} \
|
||||
"${PREMAIN_C}" \
|
||||
${_WL_PREMAIN} "$@"
|
||||
|
||||
# generate signature...
|
||||
if [ -z "${FIPS_SIG}" ]; then
|
||||
SIG=`"${THERE}/fips/fips_premain_dso" "${TARGET}"`
|
||||
else
|
||||
SIG=`"${FIPS_SIG}" -dso "${TARGET}"`
|
||||
fi
|
||||
/bin/rm -f "${TARGET}"
|
||||
if [ -z "${SIG}" ]; then
|
||||
echo "unable to collect signature"; exit 1
|
||||
fi
|
||||
|
||||
# recompile with signature...
|
||||
${CC} ${CANISTER_O_CMD:+"${CANISTER_O_CMD}"} \
|
||||
-DHMAC_SHA1_SIG=\"${SIG}\" "${PREMAIN_C}" \
|
||||
${_WL_PREMAIN} "$@"
|
||||
;;
|
||||
|
||||
*) # must be linking statically...
|
||||
# Static linking can be taking place either in the source
|
||||
# directory or off the installed binary target destination.
|
||||
if [ -x "${THERE}/fips/fips_standalone_sha1" ]; then
|
||||
FINGERTYPE="${THERE}/fips/fips_standalone_sha1"
|
||||
else # Installed tree is expected to contain
|
||||
# lib/fipscanister.o, lib/fipscanister.o.sha1 and
|
||||
# lib/fips_premain.c [not to mention bin/openssl].
|
||||
FINGERTYPE="${THERE}/bin/openssl sha1 -hmac ${HMAC_KEY}"
|
||||
fi
|
||||
|
||||
# verify fipscanister.o against its detached signature...
|
||||
${FINGERTYPE} "${CANISTER_O}" | sed "s/(.*\//(/" | \
|
||||
diff -w "${CANISTER_O}.sha1" - || \
|
||||
{ echo "${CANISTER_O} fingerprint mismatch"; exit 1; }
|
||||
|
||||
# verify fips_premain.c against its detached signature...
|
||||
${FINGERTYPE} "${PREMAIN_C}" | sed "s/(.*\//(/" | \
|
||||
diff -w "${PREMAIN_C}.sha1" - || \
|
||||
{ echo "${PREMAIN_C} fingerprint mismatch"; exit 1; }
|
||||
|
||||
/bin/rm -f "${TARGET}"
|
||||
${CC} ${CANISTER_O_CMD:+"${CANISTER_O_CMD}"} \
|
||||
"${PREMAIN_C}" \
|
||||
${_WL_PREMAIN} "$@"
|
||||
|
||||
# generate signature...
|
||||
if [ -z "${FIPS_SIG}" ]; then
|
||||
SIG=`"${TARGET}"`
|
||||
else
|
||||
SIG=`"${FIPS_SIG}" -exe "${TARGET}"`
|
||||
fi
|
||||
/bin/rm -f "${TARGET}"
|
||||
if [ -z "${SIG}" ]; then
|
||||
echo "unable to collect signature"; exit 1
|
||||
fi
|
||||
|
||||
# recompile with signature...
|
||||
${CC} ${CANISTER_O_CMD:+"${CANISTER_O_CMD}"} \
|
||||
-DHMAC_SHA1_SIG=\"${SIG}\" "${PREMAIN_C}" \
|
||||
${_WL_PREMAIN} "$@"
|
||||
;;
|
||||
esac
|
||||
|
|
@ -1,400 +0,0 @@
|
|||
#!/bin/sh
|
||||
|
||||
# Test vector run script
|
||||
# Auto generated by mkfipsscr.pl script
|
||||
# Do not edit
|
||||
|
||||
|
||||
echo Running tests in "./testvectors/AES/req"
|
||||
rm -rf "./testvectors/AES/rsp"
|
||||
mkdir "./testvectors/AES/rsp"
|
||||
|
||||
../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CBCGFSbox128.req" "./testvectors/AES/rsp/CBCGFSbox128.rsp" || { echo "./testvectors/AES/req/CBCGFSbox128.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CBCGFSbox192.req" "./testvectors/AES/rsp/CBCGFSbox192.rsp" || { echo "./testvectors/AES/req/CBCGFSbox192.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CBCGFSbox256.req" "./testvectors/AES/rsp/CBCGFSbox256.rsp" || { echo "./testvectors/AES/req/CBCGFSbox256.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CBCKeySbox128.req" "./testvectors/AES/rsp/CBCKeySbox128.rsp" || { echo "./testvectors/AES/req/CBCKeySbox128.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CBCKeySbox192.req" "./testvectors/AES/rsp/CBCKeySbox192.rsp" || { echo "./testvectors/AES/req/CBCKeySbox192.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CBCKeySbox256.req" "./testvectors/AES/rsp/CBCKeySbox256.rsp" || { echo "./testvectors/AES/req/CBCKeySbox256.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CBCMCT128.req" "./testvectors/AES/rsp/CBCMCT128.rsp" || { echo "./testvectors/AES/req/CBCMCT128.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CBCMCT192.req" "./testvectors/AES/rsp/CBCMCT192.rsp" || { echo "./testvectors/AES/req/CBCMCT192.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CBCMCT256.req" "./testvectors/AES/rsp/CBCMCT256.rsp" || { echo "./testvectors/AES/req/CBCMCT256.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CBCMMT128.req" "./testvectors/AES/rsp/CBCMMT128.rsp" || { echo "./testvectors/AES/req/CBCMMT128.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CBCMMT192.req" "./testvectors/AES/rsp/CBCMMT192.rsp" || { echo "./testvectors/AES/req/CBCMMT192.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CBCMMT256.req" "./testvectors/AES/rsp/CBCMMT256.rsp" || { echo "./testvectors/AES/req/CBCMMT256.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CBCVarKey128.req" "./testvectors/AES/rsp/CBCVarKey128.rsp" || { echo "./testvectors/AES/req/CBCVarKey128.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CBCVarKey192.req" "./testvectors/AES/rsp/CBCVarKey192.rsp" || { echo "./testvectors/AES/req/CBCVarKey192.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CBCVarKey256.req" "./testvectors/AES/rsp/CBCVarKey256.rsp" || { echo "./testvectors/AES/req/CBCVarKey256.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CBCVarTxt128.req" "./testvectors/AES/rsp/CBCVarTxt128.rsp" || { echo "./testvectors/AES/req/CBCVarTxt128.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CBCVarTxt192.req" "./testvectors/AES/rsp/CBCVarTxt192.rsp" || { echo "./testvectors/AES/req/CBCVarTxt192.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CBCVarTxt256.req" "./testvectors/AES/rsp/CBCVarTxt256.rsp" || { echo "./testvectors/AES/req/CBCVarTxt256.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CFB128GFSbox128.req" "./testvectors/AES/rsp/CFB128GFSbox128.rsp" || { echo "./testvectors/AES/req/CFB128GFSbox128.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CFB128GFSbox192.req" "./testvectors/AES/rsp/CFB128GFSbox192.rsp" || { echo "./testvectors/AES/req/CFB128GFSbox192.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CFB128GFSbox256.req" "./testvectors/AES/rsp/CFB128GFSbox256.rsp" || { echo "./testvectors/AES/req/CFB128GFSbox256.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CFB128KeySbox128.req" "./testvectors/AES/rsp/CFB128KeySbox128.rsp" || { echo "./testvectors/AES/req/CFB128KeySbox128.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CFB128KeySbox192.req" "./testvectors/AES/rsp/CFB128KeySbox192.rsp" || { echo "./testvectors/AES/req/CFB128KeySbox192.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CFB128KeySbox256.req" "./testvectors/AES/rsp/CFB128KeySbox256.rsp" || { echo "./testvectors/AES/req/CFB128KeySbox256.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CFB128MCT128.req" "./testvectors/AES/rsp/CFB128MCT128.rsp" || { echo "./testvectors/AES/req/CFB128MCT128.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CFB128MCT192.req" "./testvectors/AES/rsp/CFB128MCT192.rsp" || { echo "./testvectors/AES/req/CFB128MCT192.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CFB128MCT256.req" "./testvectors/AES/rsp/CFB128MCT256.rsp" || { echo "./testvectors/AES/req/CFB128MCT256.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CFB128MMT128.req" "./testvectors/AES/rsp/CFB128MMT128.rsp" || { echo "./testvectors/AES/req/CFB128MMT128.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CFB128MMT192.req" "./testvectors/AES/rsp/CFB128MMT192.rsp" || { echo "./testvectors/AES/req/CFB128MMT192.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CFB128MMT256.req" "./testvectors/AES/rsp/CFB128MMT256.rsp" || { echo "./testvectors/AES/req/CFB128MMT256.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CFB128VarKey128.req" "./testvectors/AES/rsp/CFB128VarKey128.rsp" || { echo "./testvectors/AES/req/CFB128VarKey128.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CFB128VarKey192.req" "./testvectors/AES/rsp/CFB128VarKey192.rsp" || { echo "./testvectors/AES/req/CFB128VarKey192.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CFB128VarKey256.req" "./testvectors/AES/rsp/CFB128VarKey256.rsp" || { echo "./testvectors/AES/req/CFB128VarKey256.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CFB128VarTxt128.req" "./testvectors/AES/rsp/CFB128VarTxt128.rsp" || { echo "./testvectors/AES/req/CFB128VarTxt128.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CFB128VarTxt192.req" "./testvectors/AES/rsp/CFB128VarTxt192.rsp" || { echo "./testvectors/AES/req/CFB128VarTxt192.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CFB128VarTxt256.req" "./testvectors/AES/rsp/CFB128VarTxt256.rsp" || { echo "./testvectors/AES/req/CFB128VarTxt256.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CFB1GFSbox128.req" "./testvectors/AES/rsp/CFB1GFSbox128.rsp" || { echo "./testvectors/AES/req/CFB1GFSbox128.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CFB1GFSbox192.req" "./testvectors/AES/rsp/CFB1GFSbox192.rsp" || { echo "./testvectors/AES/req/CFB1GFSbox192.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CFB1GFSbox256.req" "./testvectors/AES/rsp/CFB1GFSbox256.rsp" || { echo "./testvectors/AES/req/CFB1GFSbox256.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CFB1KeySbox128.req" "./testvectors/AES/rsp/CFB1KeySbox128.rsp" || { echo "./testvectors/AES/req/CFB1KeySbox128.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CFB1KeySbox192.req" "./testvectors/AES/rsp/CFB1KeySbox192.rsp" || { echo "./testvectors/AES/req/CFB1KeySbox192.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CFB1KeySbox256.req" "./testvectors/AES/rsp/CFB1KeySbox256.rsp" || { echo "./testvectors/AES/req/CFB1KeySbox256.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CFB1MCT128.req" "./testvectors/AES/rsp/CFB1MCT128.rsp" || { echo "./testvectors/AES/req/CFB1MCT128.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CFB1MCT192.req" "./testvectors/AES/rsp/CFB1MCT192.rsp" || { echo "./testvectors/AES/req/CFB1MCT192.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CFB1MCT256.req" "./testvectors/AES/rsp/CFB1MCT256.rsp" || { echo "./testvectors/AES/req/CFB1MCT256.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CFB1MMT128.req" "./testvectors/AES/rsp/CFB1MMT128.rsp" || { echo "./testvectors/AES/req/CFB1MMT128.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CFB1MMT192.req" "./testvectors/AES/rsp/CFB1MMT192.rsp" || { echo "./testvectors/AES/req/CFB1MMT192.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CFB1MMT256.req" "./testvectors/AES/rsp/CFB1MMT256.rsp" || { echo "./testvectors/AES/req/CFB1MMT256.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CFB1VarKey128.req" "./testvectors/AES/rsp/CFB1VarKey128.rsp" || { echo "./testvectors/AES/req/CFB1VarKey128.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CFB1VarKey192.req" "./testvectors/AES/rsp/CFB1VarKey192.rsp" || { echo "./testvectors/AES/req/CFB1VarKey192.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CFB1VarKey256.req" "./testvectors/AES/rsp/CFB1VarKey256.rsp" || { echo "./testvectors/AES/req/CFB1VarKey256.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CFB1VarTxt128.req" "./testvectors/AES/rsp/CFB1VarTxt128.rsp" || { echo "./testvectors/AES/req/CFB1VarTxt128.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CFB1VarTxt192.req" "./testvectors/AES/rsp/CFB1VarTxt192.rsp" || { echo "./testvectors/AES/req/CFB1VarTxt192.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CFB1VarTxt256.req" "./testvectors/AES/rsp/CFB1VarTxt256.rsp" || { echo "./testvectors/AES/req/CFB1VarTxt256.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CFB8GFSbox128.req" "./testvectors/AES/rsp/CFB8GFSbox128.rsp" || { echo "./testvectors/AES/req/CFB8GFSbox128.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CFB8GFSbox192.req" "./testvectors/AES/rsp/CFB8GFSbox192.rsp" || { echo "./testvectors/AES/req/CFB8GFSbox192.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CFB8GFSbox256.req" "./testvectors/AES/rsp/CFB8GFSbox256.rsp" || { echo "./testvectors/AES/req/CFB8GFSbox256.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CFB8KeySbox128.req" "./testvectors/AES/rsp/CFB8KeySbox128.rsp" || { echo "./testvectors/AES/req/CFB8KeySbox128.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CFB8KeySbox192.req" "./testvectors/AES/rsp/CFB8KeySbox192.rsp" || { echo "./testvectors/AES/req/CFB8KeySbox192.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CFB8KeySbox256.req" "./testvectors/AES/rsp/CFB8KeySbox256.rsp" || { echo "./testvectors/AES/req/CFB8KeySbox256.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CFB8MCT128.req" "./testvectors/AES/rsp/CFB8MCT128.rsp" || { echo "./testvectors/AES/req/CFB8MCT128.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CFB8MCT192.req" "./testvectors/AES/rsp/CFB8MCT192.rsp" || { echo "./testvectors/AES/req/CFB8MCT192.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CFB8MCT256.req" "./testvectors/AES/rsp/CFB8MCT256.rsp" || { echo "./testvectors/AES/req/CFB8MCT256.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CFB8MMT128.req" "./testvectors/AES/rsp/CFB8MMT128.rsp" || { echo "./testvectors/AES/req/CFB8MMT128.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CFB8MMT192.req" "./testvectors/AES/rsp/CFB8MMT192.rsp" || { echo "./testvectors/AES/req/CFB8MMT192.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CFB8MMT256.req" "./testvectors/AES/rsp/CFB8MMT256.rsp" || { echo "./testvectors/AES/req/CFB8MMT256.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CFB8VarKey128.req" "./testvectors/AES/rsp/CFB8VarKey128.rsp" || { echo "./testvectors/AES/req/CFB8VarKey128.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CFB8VarKey192.req" "./testvectors/AES/rsp/CFB8VarKey192.rsp" || { echo "./testvectors/AES/req/CFB8VarKey192.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CFB8VarKey256.req" "./testvectors/AES/rsp/CFB8VarKey256.rsp" || { echo "./testvectors/AES/req/CFB8VarKey256.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CFB8VarTxt128.req" "./testvectors/AES/rsp/CFB8VarTxt128.rsp" || { echo "./testvectors/AES/req/CFB8VarTxt128.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CFB8VarTxt192.req" "./testvectors/AES/rsp/CFB8VarTxt192.rsp" || { echo "./testvectors/AES/req/CFB8VarTxt192.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/CFB8VarTxt256.req" "./testvectors/AES/rsp/CFB8VarTxt256.rsp" || { echo "./testvectors/AES/req/CFB8VarTxt256.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/ECBGFSbox128.req" "./testvectors/AES/rsp/ECBGFSbox128.rsp" || { echo "./testvectors/AES/req/ECBGFSbox128.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/ECBGFSbox192.req" "./testvectors/AES/rsp/ECBGFSbox192.rsp" || { echo "./testvectors/AES/req/ECBGFSbox192.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/ECBGFSbox256.req" "./testvectors/AES/rsp/ECBGFSbox256.rsp" || { echo "./testvectors/AES/req/ECBGFSbox256.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/ECBKeySbox128.req" "./testvectors/AES/rsp/ECBKeySbox128.rsp" || { echo "./testvectors/AES/req/ECBKeySbox128.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/ECBKeySbox192.req" "./testvectors/AES/rsp/ECBKeySbox192.rsp" || { echo "./testvectors/AES/req/ECBKeySbox192.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/ECBKeySbox256.req" "./testvectors/AES/rsp/ECBKeySbox256.rsp" || { echo "./testvectors/AES/req/ECBKeySbox256.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/ECBMCT128.req" "./testvectors/AES/rsp/ECBMCT128.rsp" || { echo "./testvectors/AES/req/ECBMCT128.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/ECBMCT192.req" "./testvectors/AES/rsp/ECBMCT192.rsp" || { echo "./testvectors/AES/req/ECBMCT192.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/ECBMCT256.req" "./testvectors/AES/rsp/ECBMCT256.rsp" || { echo "./testvectors/AES/req/ECBMCT256.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/ECBMMT128.req" "./testvectors/AES/rsp/ECBMMT128.rsp" || { echo "./testvectors/AES/req/ECBMMT128.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/ECBMMT192.req" "./testvectors/AES/rsp/ECBMMT192.rsp" || { echo "./testvectors/AES/req/ECBMMT192.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/ECBMMT256.req" "./testvectors/AES/rsp/ECBMMT256.rsp" || { echo "./testvectors/AES/req/ECBMMT256.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/ECBVarKey128.req" "./testvectors/AES/rsp/ECBVarKey128.rsp" || { echo "./testvectors/AES/req/ECBVarKey128.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/ECBVarKey192.req" "./testvectors/AES/rsp/ECBVarKey192.rsp" || { echo "./testvectors/AES/req/ECBVarKey192.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/ECBVarKey256.req" "./testvectors/AES/rsp/ECBVarKey256.rsp" || { echo "./testvectors/AES/req/ECBVarKey256.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/ECBVarTxt128.req" "./testvectors/AES/rsp/ECBVarTxt128.rsp" || { echo "./testvectors/AES/req/ECBVarTxt128.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/ECBVarTxt192.req" "./testvectors/AES/rsp/ECBVarTxt192.rsp" || { echo "./testvectors/AES/req/ECBVarTxt192.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/ECBVarTxt256.req" "./testvectors/AES/rsp/ECBVarTxt256.rsp" || { echo "./testvectors/AES/req/ECBVarTxt256.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/OFBGFSbox128.req" "./testvectors/AES/rsp/OFBGFSbox128.rsp" || { echo "./testvectors/AES/req/OFBGFSbox128.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/OFBGFSbox192.req" "./testvectors/AES/rsp/OFBGFSbox192.rsp" || { echo "./testvectors/AES/req/OFBGFSbox192.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/OFBGFSbox256.req" "./testvectors/AES/rsp/OFBGFSbox256.rsp" || { echo "./testvectors/AES/req/OFBGFSbox256.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/OFBKeySbox128.req" "./testvectors/AES/rsp/OFBKeySbox128.rsp" || { echo "./testvectors/AES/req/OFBKeySbox128.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/OFBKeySbox192.req" "./testvectors/AES/rsp/OFBKeySbox192.rsp" || { echo "./testvectors/AES/req/OFBKeySbox192.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/OFBKeySbox256.req" "./testvectors/AES/rsp/OFBKeySbox256.rsp" || { echo "./testvectors/AES/req/OFBKeySbox256.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/OFBMCT128.req" "./testvectors/AES/rsp/OFBMCT128.rsp" || { echo "./testvectors/AES/req/OFBMCT128.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/OFBMCT192.req" "./testvectors/AES/rsp/OFBMCT192.rsp" || { echo "./testvectors/AES/req/OFBMCT192.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/OFBMCT256.req" "./testvectors/AES/rsp/OFBMCT256.rsp" || { echo "./testvectors/AES/req/OFBMCT256.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/OFBMMT128.req" "./testvectors/AES/rsp/OFBMMT128.rsp" || { echo "./testvectors/AES/req/OFBMMT128.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/OFBMMT192.req" "./testvectors/AES/rsp/OFBMMT192.rsp" || { echo "./testvectors/AES/req/OFBMMT192.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/OFBMMT256.req" "./testvectors/AES/rsp/OFBMMT256.rsp" || { echo "./testvectors/AES/req/OFBMMT256.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/OFBVarKey128.req" "./testvectors/AES/rsp/OFBVarKey128.rsp" || { echo "./testvectors/AES/req/OFBVarKey128.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/OFBVarKey192.req" "./testvectors/AES/rsp/OFBVarKey192.rsp" || { echo "./testvectors/AES/req/OFBVarKey192.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/OFBVarKey256.req" "./testvectors/AES/rsp/OFBVarKey256.rsp" || { echo "./testvectors/AES/req/OFBVarKey256.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/OFBVarTxt128.req" "./testvectors/AES/rsp/OFBVarTxt128.rsp" || { echo "./testvectors/AES/req/OFBVarTxt128.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/OFBVarTxt192.req" "./testvectors/AES/rsp/OFBVarTxt192.rsp" || { echo "./testvectors/AES/req/OFBVarTxt192.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_aesavs -f "./testvectors/AES/req/OFBVarTxt256.req" "./testvectors/AES/rsp/OFBVarTxt256.rsp" || { echo "./testvectors/AES/req/OFBVarTxt256.req failure" ; exit 1
|
||||
}
|
||||
|
||||
echo Running tests in "./testvectors/DSA/req"
|
||||
rm -rf "./testvectors/DSA/rsp"
|
||||
mkdir "./testvectors/DSA/rsp"
|
||||
|
||||
../util/shlib_wrap.sh ../test/fips_dssvs keypair < "./testvectors/DSA/req/KeyPair.req" > "./testvectors/DSA/rsp/KeyPair.rsp" || { echo "./testvectors/DSA/req/KeyPair.req failure" ; exit 1; }
|
||||
../util/shlib_wrap.sh ../test/fips_dssvs pqg < "./testvectors/DSA/req/PQGGen.req" > "./testvectors/DSA/rsp/PQGGen.rsp" || { echo "./testvectors/DSA/req/PQGGen.req failure" ; exit 1; }
|
||||
../util/shlib_wrap.sh ../test/fips_dssvs siggen < "./testvectors/DSA/req/SigGen.req" > "./testvectors/DSA/rsp/SigGen.rsp" || { echo "./testvectors/DSA/req/SigGen.req failure" ; exit 1; }
|
||||
../util/shlib_wrap.sh ../test/fips_dssvs sigver < "./testvectors/DSA/req/SigVer.req" > "./testvectors/DSA/rsp/SigVer.rsp" || { echo "./testvectors/DSA/req/SigVer.req failure" ; exit 1; }
|
||||
|
||||
echo Running tests in "./testvectors/HMAC/req"
|
||||
rm -rf "./testvectors/HMAC/rsp"
|
||||
mkdir "./testvectors/HMAC/rsp"
|
||||
|
||||
../util/shlib_wrap.sh ../test/fips_hmactest < "./testvectors/HMAC/req/HMAC.req" > "./testvectors/HMAC/rsp/HMAC.rsp" || { echo "./testvectors/HMAC/req/HMAC.req failure" ; exit 1; }
|
||||
|
||||
echo Running tests in "./testvectors/RNG/req"
|
||||
rm -rf "./testvectors/RNG/rsp"
|
||||
mkdir "./testvectors/RNG/rsp"
|
||||
|
||||
../util/shlib_wrap.sh ../test/fips_rngvs mct < "./testvectors/RNG/req/ANSI931_AES128MCT.req" > "./testvectors/RNG/rsp/ANSI931_AES128MCT.rsp" || { echo "./testvectors/RNG/req/ANSI931_AES128MCT.req failure" ; exit 1; }
|
||||
../util/shlib_wrap.sh ../test/fips_rngvs vst < "./testvectors/RNG/req/ANSI931_AES128VST.req" > "./testvectors/RNG/rsp/ANSI931_AES128VST.rsp" || { echo "./testvectors/RNG/req/ANSI931_AES128VST.req failure" ; exit 1; }
|
||||
../util/shlib_wrap.sh ../test/fips_rngvs mct < "./testvectors/RNG/req/ANSI931_AES192MCT.req" > "./testvectors/RNG/rsp/ANSI931_AES192MCT.rsp" || { echo "./testvectors/RNG/req/ANSI931_AES192MCT.req failure" ; exit 1; }
|
||||
../util/shlib_wrap.sh ../test/fips_rngvs vst < "./testvectors/RNG/req/ANSI931_AES192VST.req" > "./testvectors/RNG/rsp/ANSI931_AES192VST.rsp" || { echo "./testvectors/RNG/req/ANSI931_AES192VST.req failure" ; exit 1; }
|
||||
../util/shlib_wrap.sh ../test/fips_rngvs mct < "./testvectors/RNG/req/ANSI931_AES256MCT.req" > "./testvectors/RNG/rsp/ANSI931_AES256MCT.rsp" || { echo "./testvectors/RNG/req/ANSI931_AES256MCT.req failure" ; exit 1; }
|
||||
../util/shlib_wrap.sh ../test/fips_rngvs vst < "./testvectors/RNG/req/ANSI931_AES256VST.req" > "./testvectors/RNG/rsp/ANSI931_AES256VST.rsp" || { echo "./testvectors/RNG/req/ANSI931_AES256VST.req failure" ; exit 1; }
|
||||
|
||||
echo Running tests in "./testvectors/RSA/req"
|
||||
rm -rf "./testvectors/RSA/rsp"
|
||||
mkdir "./testvectors/RSA/rsp"
|
||||
|
||||
../util/shlib_wrap.sh ../test/fips_rsagtest < "./testvectors/RSA/req/KeyGenRSA.req" > "./testvectors/RSA/rsp/KeyGenRSA.rsp" || { echo "./testvectors/RSA/req/KeyGenRSA.req failure" ; exit 1; }
|
||||
../util/shlib_wrap.sh ../test/fips_rsastest < "./testvectors/RSA/req/SigGen15.req" > "./testvectors/RSA/rsp/SigGen15.rsp" || { echo "./testvectors/RSA/req/SigGen15.req failure" ; exit 1; }
|
||||
../util/shlib_wrap.sh ../test/fips_rsastest -saltlen 0 < "./testvectors/RSA/req/SigGenPSS.req" > "./testvectors/RSA/rsp/SigGenPSS.rsp" || { echo "./testvectors/RSA/req/SigGenPSS.req failure" ; exit 1; }
|
||||
../util/shlib_wrap.sh ../test/fips_rsastest -x931 < "./testvectors/RSA/req/SigGenRSA.req" > "./testvectors/RSA/rsp/SigGenRSA.rsp" || { echo "./testvectors/RSA/req/SigGenRSA.req failure" ; exit 1; }
|
||||
../util/shlib_wrap.sh ../test/fips_rsavtest < "./testvectors/RSA/req/SigVer15.req" > "./testvectors/RSA/rsp/SigVer15.rsp" || { echo "./testvectors/RSA/req/SigVer15.req failure" ; exit 1; }
|
||||
../util/shlib_wrap.sh ../test/fips_rsavtest -saltlen 0 < "./testvectors/RSA/req/SigVerPSS.req" > "./testvectors/RSA/rsp/SigVerPSS.rsp" || { echo "./testvectors/RSA/req/SigVerPSS.req failure" ; exit 1; }
|
||||
../util/shlib_wrap.sh ../test/fips_rsavtest -x931 < "./testvectors/RSA/req/SigVerRSA.req" > "./testvectors/RSA/rsp/SigVerRSA.rsp" || { echo "./testvectors/RSA/req/SigVerRSA.req failure" ; exit 1; }
|
||||
|
||||
echo Running tests in "./testvectors/SHA/req"
|
||||
rm -rf "./testvectors/SHA/rsp"
|
||||
mkdir "./testvectors/SHA/rsp"
|
||||
|
||||
../util/shlib_wrap.sh ../test/fips_shatest < "./testvectors/SHA/req/SHA1LongMsg.req" > "./testvectors/SHA/rsp/SHA1LongMsg.rsp" || { echo "./testvectors/SHA/req/SHA1LongMsg.req failure" ; exit 1; }
|
||||
../util/shlib_wrap.sh ../test/fips_shatest < "./testvectors/SHA/req/SHA1Monte.req" > "./testvectors/SHA/rsp/SHA1Monte.rsp" || { echo "./testvectors/SHA/req/SHA1Monte.req failure" ; exit 1; }
|
||||
../util/shlib_wrap.sh ../test/fips_shatest < "./testvectors/SHA/req/SHA1ShortMsg.req" > "./testvectors/SHA/rsp/SHA1ShortMsg.rsp" || { echo "./testvectors/SHA/req/SHA1ShortMsg.req failure" ; exit 1; }
|
||||
../util/shlib_wrap.sh ../test/fips_shatest < "./testvectors/SHA/req/SHA224LongMsg.req" > "./testvectors/SHA/rsp/SHA224LongMsg.rsp" || { echo "./testvectors/SHA/req/SHA224LongMsg.req failure" ; exit 1; }
|
||||
../util/shlib_wrap.sh ../test/fips_shatest < "./testvectors/SHA/req/SHA224Monte.req" > "./testvectors/SHA/rsp/SHA224Monte.rsp" || { echo "./testvectors/SHA/req/SHA224Monte.req failure" ; exit 1; }
|
||||
../util/shlib_wrap.sh ../test/fips_shatest < "./testvectors/SHA/req/SHA224ShortMsg.req" > "./testvectors/SHA/rsp/SHA224ShortMsg.rsp" || { echo "./testvectors/SHA/req/SHA224ShortMsg.req failure" ; exit 1; }
|
||||
../util/shlib_wrap.sh ../test/fips_shatest < "./testvectors/SHA/req/SHA256LongMsg.req" > "./testvectors/SHA/rsp/SHA256LongMsg.rsp" || { echo "./testvectors/SHA/req/SHA256LongMsg.req failure" ; exit 1; }
|
||||
../util/shlib_wrap.sh ../test/fips_shatest < "./testvectors/SHA/req/SHA256Monte.req" > "./testvectors/SHA/rsp/SHA256Monte.rsp" || { echo "./testvectors/SHA/req/SHA256Monte.req failure" ; exit 1; }
|
||||
../util/shlib_wrap.sh ../test/fips_shatest < "./testvectors/SHA/req/SHA256ShortMsg.req" > "./testvectors/SHA/rsp/SHA256ShortMsg.rsp" || { echo "./testvectors/SHA/req/SHA256ShortMsg.req failure" ; exit 1; }
|
||||
../util/shlib_wrap.sh ../test/fips_shatest < "./testvectors/SHA/req/SHA384LongMsg.req" > "./testvectors/SHA/rsp/SHA384LongMsg.rsp" || { echo "./testvectors/SHA/req/SHA384LongMsg.req failure" ; exit 1; }
|
||||
../util/shlib_wrap.sh ../test/fips_shatest < "./testvectors/SHA/req/SHA384Monte.req" > "./testvectors/SHA/rsp/SHA384Monte.rsp" || { echo "./testvectors/SHA/req/SHA384Monte.req failure" ; exit 1; }
|
||||
../util/shlib_wrap.sh ../test/fips_shatest < "./testvectors/SHA/req/SHA384ShortMsg.req" > "./testvectors/SHA/rsp/SHA384ShortMsg.rsp" || { echo "./testvectors/SHA/req/SHA384ShortMsg.req failure" ; exit 1; }
|
||||
../util/shlib_wrap.sh ../test/fips_shatest < "./testvectors/SHA/req/SHA512LongMsg.req" > "./testvectors/SHA/rsp/SHA512LongMsg.rsp" || { echo "./testvectors/SHA/req/SHA512LongMsg.req failure" ; exit 1; }
|
||||
../util/shlib_wrap.sh ../test/fips_shatest < "./testvectors/SHA/req/SHA512Monte.req" > "./testvectors/SHA/rsp/SHA512Monte.rsp" || { echo "./testvectors/SHA/req/SHA512Monte.req failure" ; exit 1; }
|
||||
../util/shlib_wrap.sh ../test/fips_shatest < "./testvectors/SHA/req/SHA512ShortMsg.req" > "./testvectors/SHA/rsp/SHA512ShortMsg.rsp" || { echo "./testvectors/SHA/req/SHA512ShortMsg.req failure" ; exit 1; }
|
||||
|
||||
echo Running tests in "./testvectors/TDES/req"
|
||||
rm -rf "./testvectors/TDES/rsp"
|
||||
mkdir "./testvectors/TDES/rsp"
|
||||
|
||||
../util/shlib_wrap.sh ../test/fips_desmovs -f "./testvectors/TDES/req/TCBCinvperm.req" "./testvectors/TDES/rsp/TCBCinvperm.rsp" || { echo "./testvectors/TDES/req/TCBCinvperm.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_desmovs -f "./testvectors/TDES/req/TCBCMMT1.req" "./testvectors/TDES/rsp/TCBCMMT1.rsp" || { echo "./testvectors/TDES/req/TCBCMMT1.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_desmovs -f "./testvectors/TDES/req/TCBCMMT2.req" "./testvectors/TDES/rsp/TCBCMMT2.rsp" || { echo "./testvectors/TDES/req/TCBCMMT2.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_desmovs -f "./testvectors/TDES/req/TCBCMMT3.req" "./testvectors/TDES/rsp/TCBCMMT3.rsp" || { echo "./testvectors/TDES/req/TCBCMMT3.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_desmovs -f "./testvectors/TDES/req/TCBCMonte1.req" "./testvectors/TDES/rsp/TCBCMonte1.rsp" || { echo "./testvectors/TDES/req/TCBCMonte1.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_desmovs -f "./testvectors/TDES/req/TCBCMonte2.req" "./testvectors/TDES/rsp/TCBCMonte2.rsp" || { echo "./testvectors/TDES/req/TCBCMonte2.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_desmovs -f "./testvectors/TDES/req/TCBCMonte3.req" "./testvectors/TDES/rsp/TCBCMonte3.rsp" || { echo "./testvectors/TDES/req/TCBCMonte3.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_desmovs -f "./testvectors/TDES/req/TCBCpermop.req" "./testvectors/TDES/rsp/TCBCpermop.rsp" || { echo "./testvectors/TDES/req/TCBCpermop.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_desmovs -f "./testvectors/TDES/req/TCBCsubtab.req" "./testvectors/TDES/rsp/TCBCsubtab.rsp" || { echo "./testvectors/TDES/req/TCBCsubtab.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_desmovs -f "./testvectors/TDES/req/TCBCvarkey.req" "./testvectors/TDES/rsp/TCBCvarkey.rsp" || { echo "./testvectors/TDES/req/TCBCvarkey.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_desmovs -f "./testvectors/TDES/req/TCBCvartext.req" "./testvectors/TDES/rsp/TCBCvartext.rsp" || { echo "./testvectors/TDES/req/TCBCvartext.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_desmovs -f "./testvectors/TDES/req/TCFB64invperm.req" "./testvectors/TDES/rsp/TCFB64invperm.rsp" || { echo "./testvectors/TDES/req/TCFB64invperm.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_desmovs -f "./testvectors/TDES/req/TCFB64MMT1.req" "./testvectors/TDES/rsp/TCFB64MMT1.rsp" || { echo "./testvectors/TDES/req/TCFB64MMT1.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_desmovs -f "./testvectors/TDES/req/TCFB64MMT2.req" "./testvectors/TDES/rsp/TCFB64MMT2.rsp" || { echo "./testvectors/TDES/req/TCFB64MMT2.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_desmovs -f "./testvectors/TDES/req/TCFB64MMT3.req" "./testvectors/TDES/rsp/TCFB64MMT3.rsp" || { echo "./testvectors/TDES/req/TCFB64MMT3.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_desmovs -f "./testvectors/TDES/req/TCFB64Monte1.req" "./testvectors/TDES/rsp/TCFB64Monte1.rsp" || { echo "./testvectors/TDES/req/TCFB64Monte1.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_desmovs -f "./testvectors/TDES/req/TCFB64Monte2.req" "./testvectors/TDES/rsp/TCFB64Monte2.rsp" || { echo "./testvectors/TDES/req/TCFB64Monte2.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_desmovs -f "./testvectors/TDES/req/TCFB64Monte3.req" "./testvectors/TDES/rsp/TCFB64Monte3.rsp" || { echo "./testvectors/TDES/req/TCFB64Monte3.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_desmovs -f "./testvectors/TDES/req/TCFB64permop.req" "./testvectors/TDES/rsp/TCFB64permop.rsp" || { echo "./testvectors/TDES/req/TCFB64permop.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_desmovs -f "./testvectors/TDES/req/TCFB64subtab.req" "./testvectors/TDES/rsp/TCFB64subtab.rsp" || { echo "./testvectors/TDES/req/TCFB64subtab.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_desmovs -f "./testvectors/TDES/req/TCFB64varkey.req" "./testvectors/TDES/rsp/TCFB64varkey.rsp" || { echo "./testvectors/TDES/req/TCFB64varkey.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_desmovs -f "./testvectors/TDES/req/TCFB64vartext.req" "./testvectors/TDES/rsp/TCFB64vartext.rsp" || { echo "./testvectors/TDES/req/TCFB64vartext.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_desmovs -f "./testvectors/TDES/req/TCFB8invperm.req" "./testvectors/TDES/rsp/TCFB8invperm.rsp" || { echo "./testvectors/TDES/req/TCFB8invperm.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_desmovs -f "./testvectors/TDES/req/TCFB8MMT1.req" "./testvectors/TDES/rsp/TCFB8MMT1.rsp" || { echo "./testvectors/TDES/req/TCFB8MMT1.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_desmovs -f "./testvectors/TDES/req/TCFB8MMT2.req" "./testvectors/TDES/rsp/TCFB8MMT2.rsp" || { echo "./testvectors/TDES/req/TCFB8MMT2.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_desmovs -f "./testvectors/TDES/req/TCFB8MMT3.req" "./testvectors/TDES/rsp/TCFB8MMT3.rsp" || { echo "./testvectors/TDES/req/TCFB8MMT3.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_desmovs -f "./testvectors/TDES/req/TCFB8Monte1.req" "./testvectors/TDES/rsp/TCFB8Monte1.rsp" || { echo "./testvectors/TDES/req/TCFB8Monte1.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_desmovs -f "./testvectors/TDES/req/TCFB8Monte2.req" "./testvectors/TDES/rsp/TCFB8Monte2.rsp" || { echo "./testvectors/TDES/req/TCFB8Monte2.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_desmovs -f "./testvectors/TDES/req/TCFB8Monte3.req" "./testvectors/TDES/rsp/TCFB8Monte3.rsp" || { echo "./testvectors/TDES/req/TCFB8Monte3.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_desmovs -f "./testvectors/TDES/req/TCFB8permop.req" "./testvectors/TDES/rsp/TCFB8permop.rsp" || { echo "./testvectors/TDES/req/TCFB8permop.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_desmovs -f "./testvectors/TDES/req/TCFB8subtab.req" "./testvectors/TDES/rsp/TCFB8subtab.rsp" || { echo "./testvectors/TDES/req/TCFB8subtab.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_desmovs -f "./testvectors/TDES/req/TCFB8varkey.req" "./testvectors/TDES/rsp/TCFB8varkey.rsp" || { echo "./testvectors/TDES/req/TCFB8varkey.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_desmovs -f "./testvectors/TDES/req/TCFB8vartext.req" "./testvectors/TDES/rsp/TCFB8vartext.rsp" || { echo "./testvectors/TDES/req/TCFB8vartext.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_desmovs -f "./testvectors/TDES/req/TECBinvperm.req" "./testvectors/TDES/rsp/TECBinvperm.rsp" || { echo "./testvectors/TDES/req/TECBinvperm.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_desmovs -f "./testvectors/TDES/req/TECBMMT1.req" "./testvectors/TDES/rsp/TECBMMT1.rsp" || { echo "./testvectors/TDES/req/TECBMMT1.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_desmovs -f "./testvectors/TDES/req/TECBMMT2.req" "./testvectors/TDES/rsp/TECBMMT2.rsp" || { echo "./testvectors/TDES/req/TECBMMT2.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_desmovs -f "./testvectors/TDES/req/TECBMMT3.req" "./testvectors/TDES/rsp/TECBMMT3.rsp" || { echo "./testvectors/TDES/req/TECBMMT3.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_desmovs -f "./testvectors/TDES/req/TECBMonte1.req" "./testvectors/TDES/rsp/TECBMonte1.rsp" || { echo "./testvectors/TDES/req/TECBMonte1.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_desmovs -f "./testvectors/TDES/req/TECBMonte2.req" "./testvectors/TDES/rsp/TECBMonte2.rsp" || { echo "./testvectors/TDES/req/TECBMonte2.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_desmovs -f "./testvectors/TDES/req/TECBMonte3.req" "./testvectors/TDES/rsp/TECBMonte3.rsp" || { echo "./testvectors/TDES/req/TECBMonte3.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_desmovs -f "./testvectors/TDES/req/TECBpermop.req" "./testvectors/TDES/rsp/TECBpermop.rsp" || { echo "./testvectors/TDES/req/TECBpermop.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_desmovs -f "./testvectors/TDES/req/TECBsubtab.req" "./testvectors/TDES/rsp/TECBsubtab.rsp" || { echo "./testvectors/TDES/req/TECBsubtab.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_desmovs -f "./testvectors/TDES/req/TECBvarkey.req" "./testvectors/TDES/rsp/TECBvarkey.rsp" || { echo "./testvectors/TDES/req/TECBvarkey.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_desmovs -f "./testvectors/TDES/req/TECBvartext.req" "./testvectors/TDES/rsp/TECBvartext.rsp" || { echo "./testvectors/TDES/req/TECBvartext.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_desmovs -f "./testvectors/TDES/req/TOFBinvperm.req" "./testvectors/TDES/rsp/TOFBinvperm.rsp" || { echo "./testvectors/TDES/req/TOFBinvperm.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_desmovs -f "./testvectors/TDES/req/TOFBMMT1.req" "./testvectors/TDES/rsp/TOFBMMT1.rsp" || { echo "./testvectors/TDES/req/TOFBMMT1.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_desmovs -f "./testvectors/TDES/req/TOFBMMT2.req" "./testvectors/TDES/rsp/TOFBMMT2.rsp" || { echo "./testvectors/TDES/req/TOFBMMT2.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_desmovs -f "./testvectors/TDES/req/TOFBMMT3.req" "./testvectors/TDES/rsp/TOFBMMT3.rsp" || { echo "./testvectors/TDES/req/TOFBMMT3.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_desmovs -f "./testvectors/TDES/req/TOFBMonte1.req" "./testvectors/TDES/rsp/TOFBMonte1.rsp" || { echo "./testvectors/TDES/req/TOFBMonte1.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_desmovs -f "./testvectors/TDES/req/TOFBMonte2.req" "./testvectors/TDES/rsp/TOFBMonte2.rsp" || { echo "./testvectors/TDES/req/TOFBMonte2.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_desmovs -f "./testvectors/TDES/req/TOFBMonte3.req" "./testvectors/TDES/rsp/TOFBMonte3.rsp" || { echo "./testvectors/TDES/req/TOFBMonte3.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_desmovs -f "./testvectors/TDES/req/TOFBpermop.req" "./testvectors/TDES/rsp/TOFBpermop.rsp" || { echo "./testvectors/TDES/req/TOFBpermop.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_desmovs -f "./testvectors/TDES/req/TOFBsubtab.req" "./testvectors/TDES/rsp/TOFBsubtab.rsp" || { echo "./testvectors/TDES/req/TOFBsubtab.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_desmovs -f "./testvectors/TDES/req/TOFBvarkey.req" "./testvectors/TDES/rsp/TOFBvarkey.rsp" || { echo "./testvectors/TDES/req/TOFBvarkey.req failure" ; exit 1
|
||||
}
|
||||
../util/shlib_wrap.sh ../test/fips_desmovs -f "./testvectors/TDES/req/TOFBvartext.req" "./testvectors/TDES/rsp/TOFBvartext.rsp" || { echo "./testvectors/TDES/req/TOFBvartext.req failure" ; exit 1
|
||||
}
|
||||
|
|
@ -1,123 +0,0 @@
|
|||
#
|
||||
# OpenSSL/fips/hmac/Makefile
|
||||
#
|
||||
|
||||
DIR= hmac
|
||||
TOP= ../..
|
||||
CC= cc
|
||||
INCLUDES=
|
||||
CFLAG=-g
|
||||
INSTALL_PREFIX=
|
||||
OPENSSLDIR= /usr/local/ssl
|
||||
INSTALLTOP=/usr/local/ssl
|
||||
MAKEDEPPROG= makedepend
|
||||
MAKEDEPEND= $(TOP)/util/domd $(TOP) -MD $(MAKEDEPPROG)
|
||||
MAKEFILE= Makefile
|
||||
AR= ar r
|
||||
|
||||
CFLAGS= $(INCLUDES) $(CFLAG)
|
||||
|
||||
GENERAL=Makefile
|
||||
TEST=fips_hmactest.c
|
||||
APPS=
|
||||
|
||||
LIB=$(TOP)/libcrypto.a
|
||||
LIBSRC=fips_hmac.c fips_hmac_selftest.c
|
||||
LIBOBJ=fips_hmac.o fips_hmac_selftest.o
|
||||
|
||||
SRC= $(LIBSRC)
|
||||
|
||||
EXHEADER=
|
||||
HEADER= $(EXHEADER)
|
||||
|
||||
ALL= $(GENERAL) $(SRC) $(HEADER)
|
||||
|
||||
top:
|
||||
(cd $(TOP); $(MAKE) DIRS=fips FDIRS=$(DIR) sub_all)
|
||||
|
||||
all: lib
|
||||
|
||||
lib: $(LIBOBJ)
|
||||
@echo $(LIBOBJ) > lib
|
||||
|
||||
files:
|
||||
$(PERL) $(TOP)/util/files.pl Makefile >> $(TOP)/MINFO
|
||||
|
||||
links:
|
||||
@$(PERL) $(TOP)/util/mklink.pl $(TOP)/include/openssl $(EXHEADER)
|
||||
@$(PERL) $(TOP)/util/mklink.pl $(TOP)/test $(TEST)
|
||||
@$(PERL) $(TOP)/util/mklink.pl $(TOP)/apps $(APPS)
|
||||
|
||||
install:
|
||||
@headerlist="$(EXHEADER)"; for i in $$headerlist; \
|
||||
do \
|
||||
(cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
|
||||
chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
|
||||
done
|
||||
|
||||
tags:
|
||||
ctags $(SRC)
|
||||
|
||||
tests:
|
||||
|
||||
Q=../testvectors/hmac/req
|
||||
A=../testvectors/hmac/rsp
|
||||
|
||||
fips_test:
|
||||
-rm -rf $(A)
|
||||
mkdir $(A)
|
||||
if [ -f $(Q)/HMAC.req ]; then $(TOP)/util/shlib_wrap.sh $(TOP)/test/fips_hmactest < $(Q)/HMAC.req > $(A)/HMAC.rsp; fi
|
||||
|
||||
lint:
|
||||
lint -DLINT $(INCLUDES) $(SRC)>fluff
|
||||
|
||||
depend:
|
||||
$(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(SRC) $(TEST)
|
||||
|
||||
dclean:
|
||||
$(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
|
||||
mv -f Makefile.new $(MAKEFILE)
|
||||
|
||||
clean:
|
||||
rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
|
||||
# DO NOT DELETE THIS LINE -- make depend depends on it.
|
||||
|
||||
fips_hmac.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
|
||||
fips_hmac.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
|
||||
fips_hmac.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
|
||||
fips_hmac.o: ../../include/openssl/hmac.h ../../include/openssl/obj_mac.h
|
||||
fips_hmac.o: ../../include/openssl/objects.h
|
||||
fips_hmac.o: ../../include/openssl/opensslconf.h
|
||||
fips_hmac.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
|
||||
fips_hmac.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
|
||||
fips_hmac.o: ../../include/openssl/symhacks.h fips_hmac.c
|
||||
fips_hmac_selftest.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
|
||||
fips_hmac_selftest.o: ../../include/openssl/crypto.h
|
||||
fips_hmac_selftest.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
|
||||
fips_hmac_selftest.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
|
||||
fips_hmac_selftest.o: ../../include/openssl/hmac.h
|
||||
fips_hmac_selftest.o: ../../include/openssl/lhash.h
|
||||
fips_hmac_selftest.o: ../../include/openssl/obj_mac.h
|
||||
fips_hmac_selftest.o: ../../include/openssl/objects.h
|
||||
fips_hmac_selftest.o: ../../include/openssl/opensslconf.h
|
||||
fips_hmac_selftest.o: ../../include/openssl/opensslv.h
|
||||
fips_hmac_selftest.o: ../../include/openssl/ossl_typ.h
|
||||
fips_hmac_selftest.o: ../../include/openssl/safestack.h
|
||||
fips_hmac_selftest.o: ../../include/openssl/stack.h
|
||||
fips_hmac_selftest.o: ../../include/openssl/symhacks.h fips_hmac_selftest.c
|
||||
fips_hmactest.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
|
||||
fips_hmactest.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
|
||||
fips_hmactest.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
|
||||
fips_hmactest.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
|
||||
fips_hmactest.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
|
||||
fips_hmactest.o: ../../include/openssl/err.h ../../include/openssl/evp.h
|
||||
fips_hmactest.o: ../../include/openssl/fips.h ../../include/openssl/hmac.h
|
||||
fips_hmactest.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
|
||||
fips_hmactest.o: ../../include/openssl/objects.h
|
||||
fips_hmactest.o: ../../include/openssl/opensslconf.h
|
||||
fips_hmactest.o: ../../include/openssl/opensslv.h
|
||||
fips_hmactest.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
|
||||
fips_hmactest.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
|
||||
fips_hmactest.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
|
||||
fips_hmactest.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
|
||||
fips_hmactest.o: ../../include/openssl/x509v3.h ../fips_utl.h fips_hmactest.c
|
||||
|
|
@ -1,191 +0,0 @@
|
|||
/* crypto/hmac/hmac.c */
|
||||
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
|
||||
* All rights reserved.
|
||||
*
|
||||
* This package is an SSL implementation written
|
||||
* by Eric Young (eay@cryptsoft.com).
|
||||
* The implementation was written so as to conform with Netscapes SSL.
|
||||
*
|
||||
* This library is free for commercial and non-commercial use as long as
|
||||
* the following conditions are aheared to. The following conditions
|
||||
* apply to all code found in this distribution, be it the RC4, RSA,
|
||||
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
|
||||
* included with this distribution is covered by the same copyright terms
|
||||
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
* Copyright remains Eric Young's, and as such any Copyright notices in
|
||||
* the code are not to be removed.
|
||||
* If this package is used in a product, Eric Young should be given attribution
|
||||
* as the author of the parts of the library used.
|
||||
* This can be in the form of a textual message at program startup or
|
||||
* in documentation (online or textual) provided with the package.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* "This product includes cryptographic software written by
|
||||
* Eric Young (eay@cryptsoft.com)"
|
||||
* The word 'cryptographic' can be left out if the rouines from the library
|
||||
* being used are not cryptographic related :-).
|
||||
* 4. If you include any Windows specific code (or a derivative thereof) from
|
||||
* the apps directory (application code) you must include an acknowledgement:
|
||||
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* The licence and distribution terms for any publically available version or
|
||||
* derivative of this code cannot be changed. i.e. this code cannot simply be
|
||||
* copied and put under another distribution licence
|
||||
* [including the GNU Public Licence.]
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <openssl/hmac.h>
|
||||
#include <openssl/fips.h>
|
||||
|
||||
#ifdef OPENSSL_FIPS
|
||||
|
||||
void HMAC_Init_ex(HMAC_CTX *ctx, const void *key, int len,
|
||||
const EVP_MD *md, ENGINE *impl)
|
||||
{
|
||||
int i,j,reset=0;
|
||||
unsigned char pad[HMAC_MAX_MD_CBLOCK];
|
||||
|
||||
if (md != NULL)
|
||||
{
|
||||
reset=1;
|
||||
ctx->md=md;
|
||||
}
|
||||
else
|
||||
md=ctx->md;
|
||||
|
||||
if (key != NULL)
|
||||
{
|
||||
if (FIPS_mode() && !(md->flags & EVP_MD_FLAG_FIPS)
|
||||
&& (!(ctx->md_ctx.flags & EVP_MD_CTX_FLAG_NON_FIPS_ALLOW)
|
||||
|| !(ctx->i_ctx.flags & EVP_MD_CTX_FLAG_NON_FIPS_ALLOW)
|
||||
|| !(ctx->o_ctx.flags & EVP_MD_CTX_FLAG_NON_FIPS_ALLOW)))
|
||||
OpenSSLDie(__FILE__,__LINE__,
|
||||
"HMAC: digest not allowed in FIPS mode");
|
||||
|
||||
reset=1;
|
||||
j=M_EVP_MD_block_size(md);
|
||||
OPENSSL_assert(j <= (int)sizeof ctx->key);
|
||||
if (j < len)
|
||||
{
|
||||
EVP_DigestInit_ex(&ctx->md_ctx,md, impl);
|
||||
EVP_DigestUpdate(&ctx->md_ctx,key,len);
|
||||
EVP_DigestFinal_ex(&(ctx->md_ctx),ctx->key,
|
||||
&ctx->key_length);
|
||||
}
|
||||
else
|
||||
{
|
||||
OPENSSL_assert(len <= (int)sizeof ctx->key);
|
||||
memcpy(ctx->key,key,len);
|
||||
ctx->key_length=len;
|
||||
}
|
||||
if(ctx->key_length != HMAC_MAX_MD_CBLOCK)
|
||||
memset(&ctx->key[ctx->key_length], 0,
|
||||
HMAC_MAX_MD_CBLOCK - ctx->key_length);
|
||||
}
|
||||
|
||||
if (reset)
|
||||
{
|
||||
for (i=0; i<HMAC_MAX_MD_CBLOCK; i++)
|
||||
pad[i]=0x36^ctx->key[i];
|
||||
EVP_DigestInit_ex(&ctx->i_ctx,md, impl);
|
||||
EVP_DigestUpdate(&ctx->i_ctx,pad,M_EVP_MD_block_size(md));
|
||||
|
||||
for (i=0; i<HMAC_MAX_MD_CBLOCK; i++)
|
||||
pad[i]=0x5c^ctx->key[i];
|
||||
EVP_DigestInit_ex(&ctx->o_ctx,md, impl);
|
||||
EVP_DigestUpdate(&ctx->o_ctx,pad,M_EVP_MD_block_size(md));
|
||||
}
|
||||
EVP_MD_CTX_copy_ex(&ctx->md_ctx,&ctx->i_ctx);
|
||||
}
|
||||
|
||||
void HMAC_Init(HMAC_CTX *ctx, const void *key, int len,
|
||||
const EVP_MD *md)
|
||||
{
|
||||
if(key && md)
|
||||
HMAC_CTX_init(ctx);
|
||||
HMAC_Init_ex(ctx,key,len,md, NULL);
|
||||
}
|
||||
|
||||
void HMAC_Update(HMAC_CTX *ctx, const unsigned char *data, size_t len)
|
||||
{
|
||||
EVP_DigestUpdate(&ctx->md_ctx,data,len);
|
||||
}
|
||||
|
||||
void HMAC_Final(HMAC_CTX *ctx, unsigned char *md, unsigned int *len)
|
||||
{
|
||||
int j;
|
||||
unsigned int i;
|
||||
unsigned char buf[EVP_MAX_MD_SIZE];
|
||||
|
||||
j=M_EVP_MD_block_size(ctx->md);
|
||||
|
||||
EVP_DigestFinal_ex(&ctx->md_ctx,buf,&i);
|
||||
EVP_MD_CTX_copy_ex(&ctx->md_ctx,&ctx->o_ctx);
|
||||
EVP_DigestUpdate(&ctx->md_ctx,buf,i);
|
||||
EVP_DigestFinal_ex(&ctx->md_ctx,md,len);
|
||||
}
|
||||
|
||||
void HMAC_CTX_init(HMAC_CTX *ctx)
|
||||
{
|
||||
EVP_MD_CTX_init(&ctx->i_ctx);
|
||||
EVP_MD_CTX_init(&ctx->o_ctx);
|
||||
EVP_MD_CTX_init(&ctx->md_ctx);
|
||||
}
|
||||
|
||||
void HMAC_CTX_cleanup(HMAC_CTX *ctx)
|
||||
{
|
||||
EVP_MD_CTX_cleanup(&ctx->i_ctx);
|
||||
EVP_MD_CTX_cleanup(&ctx->o_ctx);
|
||||
EVP_MD_CTX_cleanup(&ctx->md_ctx);
|
||||
memset(ctx,0,sizeof *ctx);
|
||||
}
|
||||
|
||||
unsigned char *HMAC(const EVP_MD *evp_md, const void *key, int key_len,
|
||||
const unsigned char *d, size_t n, unsigned char *md,
|
||||
unsigned int *md_len)
|
||||
{
|
||||
HMAC_CTX c;
|
||||
static unsigned char m[EVP_MAX_MD_SIZE];
|
||||
|
||||
if (md == NULL) md=m;
|
||||
HMAC_CTX_init(&c);
|
||||
HMAC_Init(&c,key,key_len,evp_md);
|
||||
HMAC_Update(&c,d,n);
|
||||
HMAC_Final(&c,md,md_len);
|
||||
HMAC_CTX_cleanup(&c);
|
||||
return(md);
|
||||
}
|
||||
|
||||
void HMAC_CTX_set_flags(HMAC_CTX *ctx, unsigned long flags)
|
||||
{
|
||||
M_EVP_MD_CTX_set_flags(&ctx->i_ctx, flags);
|
||||
M_EVP_MD_CTX_set_flags(&ctx->o_ctx, flags);
|
||||
M_EVP_MD_CTX_set_flags(&ctx->md_ctx, flags);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue