[pkg-opensc-commit] [libp11] 02/239: initial checkin of libp11.
Eric Dorland
eric at moszumanska.debian.org
Sat Oct 17 06:21:01 UTC 2015
This is an automated email from the git hooks/post-receive script.
eric pushed a commit to branch master
in repository libp11.
commit a0cbcae75de3ce644c344d1010ee2047a89d6ab0
Author: Andreas Jellinghaus <andreas at ionisiert.de>
Date: Wed Aug 24 21:55:35 2005 +0000
initial checkin of libp11.
---
COPYING | 510 ++++++++++++++
Makefile.am | 19 +
aclocal/Makefile.am | 5 +
bootstrap | 12 +
configure.ac | 61 ++
doc/MailingLists.html | 45 ++
doc/Makefile.am | 8 +
doc/OperatingSystems.html | 11 +
doc/QuickStart.html | 44 ++
doc/README | 10 +
doc/ResourcesLinks.html | 31 +
doc/export-wiki.sh | 34 +
doc/export-wiki.xsl | 58 ++
doc/index.html | 30 +
doc/trac.css | 360 ++++++++++
rsaref/Makefile.am | 5 +
rsaref/README | 21 +
rsaref/cryptoki.h | 75 ++
rsaref/pkcs11.h | 299 ++++++++
rsaref/pkcs11f.h | 912 ++++++++++++++++++++++++
rsaref/pkcs11t.h | 1685 +++++++++++++++++++++++++++++++++++++++++++++
src/Makefile.am | 21 +
src/Makefile.mak | 20 +
src/libp11-int.h | 159 +++++
src/libp11.h | 205 ++++++
src/libp11.pc.in | 11 +
src/libpkcs11.c | 93 +++
src/makedef.pl | 33 +
src/p11_attr.c | 150 ++++
src/p11_cert.c | 258 +++++++
src/p11_err.c | 159 +++++
src/p11_key.c | 495 +++++++++++++
src/p11_load.c | 111 +++
src/p11_misc.c | 62 ++
src/p11_ops.c | 161 +++++
src/p11_rsa.c | 153 ++++
src/p11_slot.c | 383 +++++++++++
37 files changed, 6709 insertions(+)
diff --git a/COPYING b/COPYING
new file mode 100644
index 0000000..b124cf5
--- /dev/null
+++ b/COPYING
@@ -0,0 +1,510 @@
+
+ GNU LESSER GENERAL PUBLIC LICENSE
+ Version 2.1, February 1999
+
+ Copyright (C) 1991, 1999 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.
+
+[This is the first released version of the Lesser GPL. It also counts
+ as the successor of the GNU Library Public License, version 2, hence
+ the version number 2.1.]
+
+ Preamble
+
+ The licenses for most software are designed to take away your
+freedom to share and change it. By contrast, the GNU General Public
+Licenses are intended to guarantee your freedom to share and change
+free software--to make sure the software is free for all its users.
+
+ This license, the Lesser General Public License, applies to some
+specially designated software packages--typically libraries--of the
+Free Software Foundation and other authors who decide to use it. You
+can use it too, but we suggest you first think carefully about whether
+this license or the ordinary General Public License is the better
+strategy to use in any particular case, based on the explanations
+below.
+
+ When we speak of free software, we are referring to freedom of use,
+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 and use pieces of
+it in new free programs; and that you are informed that you can do
+these things.
+
+ To protect your rights, we need to make restrictions that forbid
+distributors to deny you these rights or to ask you to surrender these
+rights. These restrictions translate to certain responsibilities for
+you if you distribute copies of the library or if you modify it.
+
+ For example, if you distribute copies of the library, whether gratis
+or for a fee, you must give the recipients all the rights that we gave
+you. You must make sure that they, too, receive or can get the source
+code. If you link other code with the library, you must provide
+complete object files to the recipients, so that they can relink them
+with the library after making changes to the library and recompiling
+it. And you must show them these terms so they know their rights.
+
+ We protect your rights with a two-step method: (1) we copyright the
+library, and (2) we offer you this license, which gives you legal
+permission to copy, distribute and/or modify the library.
+
+ To protect each distributor, we want to make it very clear that
+there is no warranty for the free library. Also, if the library is
+modified by someone else and passed on, the recipients should know
+that what they have is not the original version, so that the original
+author's reputation will not be affected by problems that might be
+introduced by others.
+
+ Finally, software patents pose a constant threat to the existence of
+any free program. We wish to make sure that a company cannot
+effectively restrict the users of a free program by obtaining a
+restrictive license from a patent holder. Therefore, we insist that
+any patent license obtained for a version of the library must be
+consistent with the full freedom of use specified in this license.
+
+ Most GNU software, including some libraries, is covered by the
+ordinary GNU General Public License. This license, the GNU Lesser
+General Public License, applies to certain designated libraries, and
+is quite different from the ordinary General Public License. We use
+this license for certain libraries in order to permit linking those
+libraries into non-free programs.
+
+ When a program is linked with a library, whether statically or using
+a shared library, the combination of the two is legally speaking a
+combined work, a derivative of the original library. The ordinary
+General Public License therefore permits such linking only if the
+entire combination fits its criteria of freedom. The Lesser General
+Public License permits more lax criteria for linking other code with
+the library.
+
+ We call this license the "Lesser" General Public License because it
+does Less to protect the user's freedom than the ordinary General
+Public License. It also provides other free software developers Less
+of an advantage over competing non-free programs. These disadvantages
+are the reason we use the ordinary General Public License for many
+libraries. However, the Lesser license provides advantages in certain
+special circumstances.
+
+ For example, on rare occasions, there may be a special need to
+encourage the widest possible use of a certain library, so that it
+becomes a de-facto standard. To achieve this, non-free programs must
+be allowed to use the library. A more frequent case is that a free
+library does the same job as widely used non-free libraries. In this
+case, there is little to gain by limiting the free library to free
+software only, so we use the Lesser General Public License.
+
+ In other cases, permission to use a particular library in non-free
+programs enables a greater number of people to use a large body of
+free software. For example, permission to use the GNU C Library in
+non-free programs enables many more people to use the whole GNU
+operating system, as well as its variant, the GNU/Linux operating
+system.
+
+ Although the Lesser General Public License is Less protective of the
+users' freedom, it does ensure that the user of a program that is
+linked with the Library has the freedom and the wherewithal to run
+that program using a modified version of the Library.
+
+ The precise terms and conditions for copying, distribution and
+modification follow. Pay close attention to the difference between a
+"work based on the library" and a "work that uses the library". The
+former contains code derived from the library, whereas the latter must
+be combined with the library in order to run.
+
+ GNU LESSER GENERAL PUBLIC LICENSE
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+ 0. This License Agreement applies to any software library or other
+program which contains a notice placed by the copyright holder or
+other authorized party saying it may be distributed under the terms of
+this Lesser General Public License (also called "this License").
+Each licensee is addressed as "you".
+
+ A "library" means a collection of software functions and/or data
+prepared so as to be conveniently linked with application programs
+(which use some of those functions and data) to form executables.
+
+ The "Library", below, refers to any such software library or work
+which has been distributed under these terms. A "work based on the
+Library" means either the Library or any derivative work under
+copyright law: that is to say, a work containing the Library or a
+portion of it, either verbatim or with modifications and/or translated
+straightforwardly into another language. (Hereinafter, translation is
+included without limitation in the term "modification".)
+
+ "Source code" for a work means the preferred form of the work for
+making modifications to it. For a library, 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 library.
+
+ Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope. The act of
+running a program using the Library is not restricted, and output from
+such a program is covered only if its contents constitute a work based
+on the Library (independent of the use of the Library in a tool for
+writing it). Whether that is true depends on what the Library does
+and what the program that uses the Library does.
+
+ 1. You may copy and distribute verbatim copies of the Library's
+complete 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 distribute a copy of this License along with the
+Library.
+
+ 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 Library or any portion
+of it, thus forming a work based on the Library, 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) The modified work must itself be a software library.
+
+ b) You must cause the files modified to carry prominent notices
+ stating that you changed the files and the date of any change.
+
+ c) You must cause the whole of the work to be licensed at no
+ charge to all third parties under the terms of this License.
+
+ d) If a facility in the modified Library refers to a function or a
+ table of data to be supplied by an application program that uses
+ the facility, other than as an argument passed when the facility
+ is invoked, then you must make a good faith effort to ensure that,
+ in the event an application does not supply such function or
+ table, the facility still operates, and performs whatever part of
+ its purpose remains meaningful.
+
+ (For example, a function in a library to compute square roots has
+ a purpose that is entirely well-defined independent of the
+ application. Therefore, Subsection 2d requires that any
+ application-supplied function or table used by this function must
+ be optional: if the application does not supply it, the square
+ root function must still compute square roots.)
+
+These requirements apply to the modified work as a whole. If
+identifiable sections of that work are not derived from the Library,
+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 Library, 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 Library.
+
+In addition, mere aggregation of another work not based on the Library
+with the Library (or with a work based on the Library) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+ 3. You may opt to apply the terms of the ordinary GNU General Public
+License instead of this License to a given copy of the Library. To do
+this, you must alter all the notices that refer to this License, so
+that they refer to the ordinary GNU General Public License, version 2,
+instead of to this License. (If a newer version than version 2 of the
+ordinary GNU General Public License has appeared, then you can specify
+that version instead if you wish.) Do not make any other change in
+these notices.
+
+ Once this change is made in a given copy, it is irreversible for
+that copy, so the ordinary GNU General Public License applies to all
+subsequent copies and derivative works made from that copy.
+
+ This option is useful when you wish to copy part of the code of
+the Library into a program that is not a library.
+
+ 4. You may copy and distribute the Library (or a portion or
+derivative of it, under Section 2) in object code or executable form
+under the terms of Sections 1 and 2 above provided that you 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.
+
+ If distribution of 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 satisfies the requirement to
+distribute the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+ 5. A program that contains no derivative of any portion of the
+Library, but is designed to work with the Library by being compiled or
+linked with it, is called a "work that uses the Library". Such a
+work, in isolation, is not a derivative work of the Library, and
+therefore falls outside the scope of this License.
+
+ However, linking a "work that uses the Library" with the Library
+creates an executable that is a derivative of the Library (because it
+contains portions of the Library), rather than a "work that uses the
+library". The executable is therefore covered by this License.
+Section 6 states terms for distribution of such executables.
+
+ When a "work that uses the Library" uses material from a header file
+that is part of the Library, the object code for the work may be a
+derivative work of the Library even though the source code is not.
+Whether this is true is especially significant if the work can be
+linked without the Library, or if the work is itself a library. The
+threshold for this to be true is not precisely defined by law.
+
+ If such an object file uses only numerical parameters, data
+structure layouts and accessors, and small macros and small inline
+functions (ten lines or less in length), then the use of the object
+file is unrestricted, regardless of whether it is legally a derivative
+work. (Executables containing this object code plus portions of the
+Library will still fall under Section 6.)
+
+ Otherwise, if the work is a derivative of the Library, you may
+distribute the object code for the work under the terms of Section 6.
+Any executables containing that work also fall under Section 6,
+whether or not they are linked directly with the Library itself.
+
+ 6. As an exception to the Sections above, you may also combine or
+link a "work that uses the Library" with the Library to produce a
+work containing portions of the Library, and distribute that work
+under terms of your choice, provided that the terms permit
+modification of the work for the customer's own use and reverse
+engineering for debugging such modifications.
+
+ You must give prominent notice with each copy of the work that the
+Library is used in it and that the Library and its use are covered by
+this License. You must supply a copy of this License. If the work
+during execution displays copyright notices, you must include the
+copyright notice for the Library among them, as well as a reference
+directing the user to the copy of this License. Also, you must do one
+of these things:
+
+ a) Accompany the work with the complete corresponding
+ machine-readable source code for the Library including whatever
+ changes were used in the work (which must be distributed under
+ Sections 1 and 2 above); and, if the work is an executable linked
+ with the Library, with the complete machine-readable "work that
+ uses the Library", as object code and/or source code, so that the
+ user can modify the Library and then relink to produce a modified
+ executable containing the modified Library. (It is understood
+ that the user who changes the contents of definitions files in the
+ Library will not necessarily be able to recompile the application
+ to use the modified definitions.)
+
+ b) Use a suitable shared library mechanism for linking with the
+ Library. A suitable mechanism is one that (1) uses at run time a
+ copy of the library already present on the user's computer system,
+ rather than copying library functions into the executable, and (2)
+ will operate properly with a modified version of the library, if
+ the user installs one, as long as the modified version is
+ interface-compatible with the version that the work was made with.
+
+ c) Accompany the work with a written offer, valid for at least
+ three years, to give the same user the materials specified in
+ Subsection 6a, above, for a charge no more than the cost of
+ performing this distribution.
+
+ d) If distribution of the work is made by offering access to copy
+ from a designated place, offer equivalent access to copy the above
+ specified materials from the same place.
+
+ e) Verify that the user has already received a copy of these
+ materials or that you have already sent this user a copy.
+
+ For an executable, the required form of the "work that uses the
+Library" must include any data and utility programs needed for
+reproducing the executable from it. However, as a special exception,
+the materials to be 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.
+
+ It may happen that this requirement contradicts the license
+restrictions of other proprietary libraries that do not normally
+accompany the operating system. Such a contradiction means you cannot
+use both them and the Library together in an executable that you
+distribute.
+
+ 7. You may place library facilities that are a work based on the
+Library side-by-side in a single library together with other library
+facilities not covered by this License, and distribute such a combined
+library, provided that the separate distribution of the work based on
+the Library and of the other library facilities is otherwise
+permitted, and provided that you do these two things:
+
+ a) Accompany the combined library with a copy of the same work
+ based on the Library, uncombined with any other library
+ facilities. This must be distributed under the terms of the
+ Sections above.
+
+ b) Give prominent notice with the combined library of the fact
+ that part of it is a work based on the Library, and explaining
+ where to find the accompanying uncombined form of the same work.
+
+ 8. You may not copy, modify, sublicense, link with, or distribute
+the Library except as expressly provided under this License. Any
+attempt otherwise to copy, modify, sublicense, link with, or
+distribute the Library 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.
+
+ 9. 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 Library or its derivative works. These actions are
+prohibited by law if you do not accept this License. Therefore, by
+modifying or distributing the Library (or any work based on the
+Library), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Library or works based on it.
+
+ 10. Each time you redistribute the Library (or any work based on the
+Library), the recipient automatically receives a license from the
+original licensor to copy, distribute, link with or modify the Library
+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 with
+this License.
+
+ 11. 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 Library at all. For example, if a patent
+license would not permit royalty-free redistribution of the Library 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 Library.
+
+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.
+
+ 12. If the distribution and/or use of the Library is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Library 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.
+
+ 13. The Free Software Foundation may publish revised and/or new
+versions of the Lesser 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 Library
+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 Library does not specify a
+license version number, you may choose any version ever published by
+the Free Software Foundation.
+
+ 14. If you wish to incorporate parts of the Library into other free
+programs whose distribution conditions are incompatible with these,
+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
+
+ 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
+WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
+EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
+OTHER PARTIES PROVIDE THE LIBRARY "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
+LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
+THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+ 16. 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 LIBRARY 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
+LIBRARY (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 LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), 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 Libraries
+
+ If you develop a new library, and you want it to be of the greatest
+possible use to the public, we recommend making it free software that
+everyone can redistribute and change. You can do so by permitting
+redistribution under these terms (or, alternatively, under the terms
+of the ordinary General Public License).
+
+ To apply these terms, attach the following notices to the library.
+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 library's name and a brief idea of what it does.>
+ Copyright (C) <year> <name of author>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; 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.
+
+You should also get your employer (if you work as a programmer) or
+your school, if any, to sign a "copyright disclaimer" for the library,
+if necessary. Here is a sample; alter the names:
+
+ Yoyodyne, Inc., hereby disclaims all copyright interest in the
+ library `Frob' (a library for tweaking knobs) written by James
+ Random Hacker.
+
+ <signature of Ty Coon>, 1 April 1990
+ Ty Coon, President of Vice
+
+That's all there is to it!
+
+
diff --git a/Makefile.am b/Makefile.am
new file mode 100644
index 0000000..c40ad2e
--- /dev/null
+++ b/Makefile.am
@@ -0,0 +1,19 @@
+# Process this file with automake to create Makefile.in
+
+SUBDIRS = aclocal doc libltdl src rsaref .
+
+EXTRA_DIST = ANNOUNCE CodingStyle QUICKSTART README \
+ bootstrap Makefile.mak depcomp
+
+MAINTAINERCLEANFILES = \
+ Makefile.in config.h.in configure \
+ install-sh ltmain.sh missing mkinstalldirs \
+ compile depcomp config.log config.status \
+ config.guess config.sub acinclude.m4 aclocal.m4
+
+DEPCLEANFILES = config.log configure
+
+AUTOMAKE_OPTIONS = foreign 1.5
+
+maintainer-clean-local:
+ rm -rf libltdl
diff --git a/aclocal/Makefile.am b/aclocal/Makefile.am
new file mode 100644
index 0000000..79206e7
--- /dev/null
+++ b/aclocal/Makefile.am
@@ -0,0 +1,5 @@
+# Process this file with automake to create Makefile.in
+
+MAINTAINERCLEANFILES = Makefile.in
+
+EXTRA_DIST =
diff --git a/bootstrap b/bootstrap
new file mode 100755
index 0000000..45c06c6
--- /dev/null
+++ b/bootstrap
@@ -0,0 +1,12 @@
+#!/bin/sh
+
+set -e
+set -x
+if test -f Makefile; then
+ make distclean
+fi
+rm -rf *.cache *.m4 config.guess config.log \
+config.status config.sub depcomp ltmain.sh libltdl
+(cat aclocal/*.m4 > acinclude.m4 2> /dev/null)
+libtoolize --ltdl --copy
+autoreconf --verbose --install
diff --git a/configure.ac b/configure.ac
new file mode 100644
index 0000000..cfd2459
--- /dev/null
+++ b/configure.ac
@@ -0,0 +1,61 @@
+dnl -*- mode: m4; -*-
+dnl Process this file with autoconf to produce a configure script.
+
+# Require autoconf 2.52
+AC_PREREQ(2.52)
+
+AC_INIT(libp11, 0.0)
+AM_INIT_AUTOMAKE
+
+AC_CONFIG_SRCDIR(src/libp11.h)
+
+# LT Version numbers, remember to change them just *before* a release.
+# (Code changed: REVISION++)
+# (Interfaces added/removed/changed: CURRENT++, REVISION=0)
+# (Interfaces added: AGE++)
+# (Interfaces removed: AGE=0)
+LIBP11_VERSION=0:1:0
+
+AC_SUBST(LIBP11_VERSION)
+
+AC_CANONICAL_HOST
+AC_PROG_CC
+AC_C_BIGENDIAN
+
+dnl Options
+AM_MAINTAINER_MODE
+
+dnl Checks for programs.
+AC_PROG_CPP
+AC_PROG_INSTALL
+
+dnl use ltdl
+AC_LIBLTDL_INSTALLABLE
+AC_SUBST(LTDLINCL)
+AC_SUBST(LIBLTDL)
+dnl and make sure libtool knows, too
+AC_LIBTOOL_DLOPEN
+
+dnl Add libtool support.
+AM_PROG_LIBTOOL
+dnl Automatically update the libtool script if it becomes out-of-date.
+dnl AC_SUBST(LIBTOOL_DEPS)
+
+dnl configure libltdl
+AC_CONFIG_SUBDIRS(libltdl)
+
+dnl Checks for header files.
+AC_HEADER_STDC
+AC_HEADER_SYS_WAIT
+AC_CHECK_HEADERS([errno.h fcntl.h malloc.h stdlib.h inttypes.h string.h strings.h sys/time.h unistd.h locale.h getopt.h dlfcn.h utmp.h])
+
+PKG_CHECK_MODULES([OPENSSL], [openssl])
+
+AC_OUTPUT([
+Makefile
+aclocal/Makefile
+doc/Makefile
+rsaref/Makefile
+src/Makefile
+src/libp11.pc
+])
diff --git a/doc/MailingLists.html b/doc/MailingLists.html
new file mode 100644
index 0000000..88966c6
--- /dev/null
+++ b/doc/MailingLists.html
@@ -0,0 +1,45 @@
+<html xmlns="http://www.w3.org/1999/xhtml" xmlns:html="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+<title>MailingLists - Library to make using PKCS#11 implementations easy - Trac</title><style type="text/css">
+ @import url(trac.css);
+ </style></head><body><div class="wikipage">
+ <div id="searchable"><h1>Mailing lists</h1>
+<ul><li>opensc-annouce - Announcements of new releases, bugfixes and security warnings
+</li><li>opensc-devel - Discussion of developement issues for OpenSC, OpenCT and SCB
+</li><li>opensc-user - Discussion of end-user questions for OpenSC, OpenCT and SCB
+</li><li>opensc-commits - commit notifications for all projects hosted at opensc.org
+</li></ul><p>
+To subscribe, unsubscribe or browse the archive, please visit
+our <a class="ext-link" title="http://www.opensc.org/cgi-bin/mailman/listinfo" href="http://www.opensc.org/cgi-bin/mailman/listinfo" shape="rect">mailing list manager</a>.
+</p>
+<p>
+Please:
+</p>
+<ul><li>Post to one of these mailing list.
+</li><li>Do not post to several lists, one is enough, we read all of them.
+</li><li>Do not send carbon copies to the developers. We read all postings on the mailing list.
+</li><li>Do not mail developers directly, we read all the mailing lists and the bugs address.
+</li></ul><p>
+Direct email is more work for us. Also see
+<a class="ext-link" title="http://www.eyrie.org/~eagle/faqs/questions.html" href="http://www.eyrie.org/~eagle/faqs/questions.html" shape="rect">this faq</a> for explanations why.
+</p>
+<p>
+If you are subscribed to the mailing list, your posting will be distributed
+immideatly. If you are not subscribed, it will be put on hold, till someone has
+reviewed it so we can filter spam. We usualy review postings at least once a day,
+so be patient. You can also cancel the posting, subscribe to the mailing list
+and post again.
+</p>
+<h2>Bug reports</h2>
+<p>
+Please file bug reports using the <a class="ext-link" title="http://www.opensc.org/libp11/newticket" href="http://www.opensc.org/libp11/newticket" shape="rect">new ticket</a> link.
+You can also send bug reports to bugs at opensc.org via email.
+</p>
+<h2>Greylisting</h2>
+<p>
+The opensc.org and lists.opensc.org mail servers are protected from spam by using a mechanism
+called greylisting. Usualy this only causes a short delay for the first mail we receive from
+you, and no trouble at all. Still if for whatever reason you cannot send mail to opensc.org,
+please contact Andreas Jellinghaus at aj at dungeon.inka.de. Thanks.
+</p>
+</div>
+ </div><div class="footer"><hr></hr><p><a href="index.html">Back to Index</a></p></div></body></html>
diff --git a/doc/Makefile.am b/doc/Makefile.am
new file mode 100644
index 0000000..f37a5c2
--- /dev/null
+++ b/doc/Makefile.am
@@ -0,0 +1,8 @@
+# Process this file with automake to create Makefile.in
+
+MAINTAINERCLEANFILES = Makefile.in
+
+EXTRA_DIST = README export-wiki.sh export-wiki.xsl $(HTML)
+
+HTML= MailingLists.html OperatingSystems.html QuickStart.html \
+ ResourcesLinks.html index.html trac.css
diff --git a/doc/OperatingSystems.html b/doc/OperatingSystems.html
new file mode 100644
index 0000000..2591a27
--- /dev/null
+++ b/doc/OperatingSystems.html
@@ -0,0 +1,11 @@
+<html xmlns="http://www.w3.org/1999/xhtml" xmlns:html="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+<title>OperatingSystems - Library to make using PKCS#11 implementations easy - Trac</title><style type="text/css">
+ @import url(trac.css);
+ </style></head><body><div class="wikipage">
+ <div id="searchable"><h1>Operating Systems</h1>
+<p>
+Libp11 is still under development, once it works we will add each operating system here.
+So far libp11 is not part of any linux distribution.
+</p>
+</div>
+ </div><div class="footer"><hr></hr><p><a href="index.html">Back to Index</a></p></div></body></html>
diff --git a/doc/QuickStart.html b/doc/QuickStart.html
new file mode 100644
index 0000000..5cc476a
--- /dev/null
+++ b/doc/QuickStart.html
@@ -0,0 +1,44 @@
+<html xmlns="http://www.w3.org/1999/xhtml" xmlns:html="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+<title>QuickStart - Library to make using PKCS#11 implementations easy - Trac</title><style type="text/css">
+ @import url(trac.css);
+ </style></head><body><div class="wikipage">
+ <div id="searchable"><h1>Installing libp11</h1>
+<p>
+Installation is quite easy:
+</p>
+<pre class="wiki" xml:space="preserve">wget http://www.opensc.org/files/libp11-0.1.tar.gz
+tar xfvz libp11-0.1.tar.gz
+cd libp11-0.1
+./configure --prefix=/usr
+make
+make install
+</pre><p>
+is all you need. Libp11 depends on pkg-config and openssl.
+If you don't have pkg-config installed, please do so and try again.
+If pkg-config is not found, please change your PATH environment setting.
+If openssl is not installed, please do so. If openssl is not found, please
+change your PKG_CONFIG_PATH environment setting to include the directory
+with "openssl.pc" file. Some linux distributions split openssl into a
+runtime package and a development package, you need to install both.
+</p>
+<h1>Using libp11</h1>
+<p>
+To use libp11 in your application: in the source code add
+</p>
+<pre class="wiki" xml:space="preserve">#include <libp11.h>
+</pre><p>
+and in your Makefile add
+</p>
+<pre class="wiki" xml:space="preserve">CFLAGS=$(shell pkg-config --cflags libp11)
+LDLFLAGS=$(shell pkg-config --libs libp11)
+</pre><p>
+or if you are using autoconf/automake, you can add this to configure.ac
+</p>
+<pre class="wiki" xml:space="preserve">PKG_CHECK_MODULES([LIBP11], [libp11])
+</pre><p>
+and edit your Makefile.am to include
+</p>
+<pre class="wiki" xml:space="preserve">myapplication_INCLUDES = @LIBP11_CFLAGS@
+myapplication_LIBADD = @LIBP11_LIBS@
+</pre></div>
+ </div><div class="footer"><hr></hr><p><a href="index.html">Back to Index</a></p></div></body></html>
diff --git a/doc/README b/doc/README
new file mode 100644
index 0000000..27a08a0
--- /dev/null
+++ b/doc/README
@@ -0,0 +1,10 @@
+This directory contains a snapshot of the LibP11 Wiki
+=====================================================
+
+The original wiki page is at http://www.opensc.org/libp11/
+and includes a bug tracker and source browser.
+
+The wiki was transformed to html using the export-wiki shell
+script and xsl style sheet. The original version is at
+ http://www.twdata.org/trac-howto/
+
diff --git a/doc/ResourcesLinks.html b/doc/ResourcesLinks.html
new file mode 100644
index 0000000..ae3dbc8
--- /dev/null
+++ b/doc/ResourcesLinks.html
@@ -0,0 +1,31 @@
+<html xmlns="http://www.w3.org/1999/xhtml" xmlns:html="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+<title>ResourcesLinks - Library to make using PKCS#11 implementations easy - Trac</title><style type="text/css">
+ @import url(trac.css);
+ </style></head><body><div class="wikipage">
+ <div id="searchable"><h1>Resources, Links</h1>
+<p>
+<a class="ext-link" title="http://www.rsasecurity.com/rsalabs/" href="http://www.rsasecurity.com/rsalabs/" shape="rect">RSA Labs</a> defined the Public Key Cryptography Standards (PKCS).
+</p>
+<p>
+<a class="ext-link" title="http://www.rsasecurity.com/rsalabs/node.asp?id=2133" href="http://www.rsasecurity.com/rsalabs/node.asp?id=2133" shape="rect">PKCS#11</a> defines an API to use software modules
+that give access to cryptographic token hardware.
+</p>
+<p>
+We think PKCS#11 is not easy to use, libp11 has the goal to make it easier.
+</p>
+<p>
+Libp11 is tested with <a class="ext-link" title="http://www.opensc.org/opensc/" href="http://www.opensc.org/opensc/" shape="rect">OpenSC</a>, but should work fine
+with other implementations of PKCS#11, too.
+</p>
+<p>
+Software using libp11:
+</p>
+<ul><li><a class="ext-link" title="http://www.opensc.org/pam_p11/" href="http://www.opensc.org/pam_p11/" shape="rect">Pam_p11</a> is a simple pam module that allows login via smart card.
+To use pam_p11 you need to store the certificates allowed for login in a file, either in pem format
+or the public keys in ssh format in your .ssh/authorized_keys file. Pam_p11 is very simple, it has
+no config file, no options, does not know about certificate chains, certificate authorities, revocation
+lists or OCSP. Perfect for the small installation with no frills.
+</li><li><a class="ext-link" title="http://www.opensc.org/engine_pkcs11/" href="http://www.opensc.org/engine_pkcs11/" shape="rect">Engine_pkcs11</a> is an Engine for OpenSSL, a loadable module that
+allows you to use openssl, but redirect crypto operations to your smart card hardware.
+</li></ul></div>
+ </div><div class="footer"><hr></hr><p><a href="index.html">Back to Index</a></p></div></body></html>
diff --git a/doc/export-wiki.sh b/doc/export-wiki.sh
new file mode 100644
index 0000000..a611d8a
--- /dev/null
+++ b/doc/export-wiki.sh
@@ -0,0 +1,34 @@
+#!/bin/bash
+
+set -e
+
+export SERVER=http://www.opensc.org
+export WIKI=libp11/wiki
+export XSL=export-wiki.xsl
+
+test -f `basename $0`
+
+rm -rf *.html *.css
+
+wget $SERVER/$WIKI/TitleIndex -O TitleIndex.tmp
+
+grep "\"/$WIKI/[^\"]*\"" TitleIndex.tmp \
+ |sed -e "s#.*\"/$WIKI/\([^\"]*\)\".*#\1#g" \
+ > WikiWords.tmp
+sed -e /^Trac/d -e /^Wiki/d -e /^TitleIndex/d -e /^RecentChanges/d \
+ -e /^CamelCase/d -e /^SandBox/d -i WikiWords.tmp
+
+for A in WikiStart `cat WikiWords.tmp`
+do
+ F=`echo $A|sed -e 's/\//_/g'`
+ wget $SERVER/$WIKI/$A -O $F.tmp
+ xsltproc --output $F.html $XSL $F.tmp
+ sed -e "s#<a href=\"/$WIKI/\([^\"]*\)\"#<a href=\"\1.html\"#g" \
+ -i $F.html
+done
+
+mv WikiStart.html index.html
+
+wget http://www.opensc.org/trac/css/trac.css
+
+rm *.tmp
diff --git a/doc/export-wiki.xsl b/doc/export-wiki.xsl
new file mode 100644
index 0000000..145befb
--- /dev/null
+++ b/doc/export-wiki.xsl
@@ -0,0 +1,58 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xsl:stylesheet version="1.0"
+xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+xmlns="http://www.w3.org/1999/xhtml"
+xmlns:html="http://www.w3.org/1999/xhtml">
+ <xsl:output method="html" indent="yes"/>
+
+ <xsl:template match="/">
+ <xsl:apply-templates />
+ </xsl:template>
+
+ <xsl:template match="/html:html">
+ <html>
+ <head>
+ <title><xsl:value-of select="/html:html/html:head/html:title" /></title>
+ <style type="text/css">
+ @import url(trac.css);
+ </style>
+ </head>
+ <body>
+ <xsl:apply-templates select="//html:div[@class='wikipage']" />
+ <div class="footer">
+ <hr />
+ <p><a href="index.html">Back to Index</a></p>
+ </div>
+ </body>
+ </html>
+ </xsl:template>
+
+ <xsl:template match="/pages">
+ <html>
+ <head>
+ <title>Wiki Index</title>
+ <style type="text/css">
+ @import url(trac.css);
+ </style>
+ </head>
+ <body>
+ <h1>Index of Wiki Pages</h1>
+ <ul>
+ <xsl:apply-templates select="page" />
+ </ul>
+ </body>
+ </html>
+ </xsl:template>
+
+ <xsl:template match="page">
+ <li><a href="{.}.html"><xsl:value-of select="." /></a></li>
+ </xsl:template>
+
+ <xsl:template match="node()|@*" priority="-1">
+ <xsl:copy>
+ <xsl:apply-templates select="@*|node()"/>
+ </xsl:copy>
+ </xsl:template>
+
+</xsl:stylesheet>
+
diff --git a/doc/index.html b/doc/index.html
new file mode 100644
index 0000000..c8af75e
--- /dev/null
+++ b/doc/index.html
@@ -0,0 +1,30 @@
+<html xmlns="http://www.w3.org/1999/xhtml" xmlns:html="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+<title>Library to make using PKCS#11 implementations easy - Trac</title><style type="text/css">
+ @import url(trac.css);
+ </style></head><body><div class="wikipage">
+ <div id="searchable"><h1>Welcome to libp11</h1>
+<p>
+Libp11 is a library implementing a small layer on to of PKCS#11 API
+to make using PKCS#11 implementations easier.
+</p>
+<p>
+The official name for PKCS#11 is
+"RSA Security Inc. PKCS <a class="missing" href="/libp11/ticket/11" shape="rect">#11</a> Cryptographic Token Interface (Cryptoki)".
+Libp11 source code include the official header files (version 2.20) and
+thus is "derived from the RSA Security Inc. PKCS <a class="missing" href="/libp11/ticket/11" shape="rect">#11</a>
+Cryptographic Token Interface (Cryptoki)".
+</p>
+<p>
+Libp11 is Open Source software licensed under the LGPL license.
+</p>
+<p>
+Libp11 was written by Andreas Jellinghaus, Kevin Stefanik, Ludovic Rousseau,
+Nils Larsch, Olaf Kirch and Stef Hoeben .
+</p>
+<h2>Starting Points</h2>
+<ul><li><a href="OperatingSystems.html" shape="rect">OperatingSystems</a> -- Libp11 should work on Linux, BSD, Mac OS X and Windows. See here for details.
+</li><li><a href="QuickStart.html" shape="rect">QuickStart</a> -- How to install libp11 and how to use it in your applications.
+</li><li><a href="MailingLists.html" shape="rect">MailingLists</a> -- How to contact us.
+</li><li><a href="ResourcesLinks.html" shape="rect">ResourcesLinks</a> -- Standards, Documents, etc.
+</li></ul></div>
+ </div><div class="footer"><hr></hr><p><a href="index.html">Back to Index</a></p></div></body></html>
diff --git a/doc/trac.css b/doc/trac.css
new file mode 100644
index 0000000..8d9604d
--- /dev/null
+++ b/doc/trac.css
@@ -0,0 +1,360 @@
+/* Trac CSS */
+body {
+ background: #fff;
+ color: #000;
+ margin: 10px;
+}
+body, th, td {
+ font: normal 13px verdana,arial,'Bitstream Vera Sans',helvetica,sans-serif;
+}
+h1, h2, h3, h4 {
+ font-family: arial,verdana,'Bitstream Vera Sans',helvetica,sans-serif;
+ font-weight: bold;
+ letter-spacing: -0.018em;
+}
+h1 { font-size: 19px; margin: .15em 1em 0 0 }
+h2 { font-size: 16px }
+h3 { font-size: 14px }
+hr { border: none; border-top: 1px solid #ccb; margin: 2em 0 }
+address { font-style: normal }
+img { border: none }
+
+.underline { text-decoration: underline; }
+ol.loweralpha { list-style-type: lower-alpha }
+ol.upperalpha { list-style-type: upper-alpha }
+ol.lowerroman { list-style-type: lower-roman }
+ol.upperroman { list-style-type: upper-roman }
+ol.arabic { list-style-type: decimal }
+
+/* Link styles */
+:link, :visited {
+ text-decoration: none;
+ color: #b00;
+ border-bottom: 1px dotted #bbb;
+}
+:link:hover, :visited:hover {
+ background-color: #eee;
+ color: #555;
+}
+h1 :link, h1 :visited ,h2 :link, h2 :visited, h3 :link, h3 :visited,
+h4 :link, h4 :visited, h5 :link, h5 :visited, h6 :link, h6 :visited {
+ color: inherit;
+}
+
+.ext-link { background: url(../extlink.gif) no-repeat 0 58%; padding-left: 16px }
+* html .ext-link { background-position: 0 .35em } /* IE hack, see #937 */
+
+/* Forms */
+input, textarea, select { margin: 2px }
+input, select { vertical-align: middle }
+input[type=submit], input[type=reset] {
+ background: #eee;
+ color: #222;
+ border: 1px outset #ccc;
+ padding: .1em .5em;
+}
+input[type=submit]:hover, input[type=reset]:hover { background: #ccb }
+input[type=text], input.textwidget, textarea {
+ background: #fff;
+ color: #000;
+ border: 1px solid #d7d7d7;
+}
+input[type=text], input.textwidget { padding: .25em .5em }
+input[type=text]:focus, textarea:focus { border: 1px solid #886 }
+option { border-bottom: 1px dotted #d7d7d7 }
+fieldset { border: 1px solid #d7d7d7; padding: .5em; margin: 0 }
+fieldset.iefix { border: none; padding: 0; margin: 0 }
+* html fieldset.iefix { width: 98% }
+fieldset.iefix p { margin: 0 }
+legend { color: #999; padding: 0 .25em; font-size: 90%; font-weight: bold }
+label.disabled { color: #d7d7d7 }
+.buttons { margin: .5em .5em .5em 0 }
+.buttons form, .buttons form div { display: inline }
+.buttons input { margin: 1em .5em .1em 0 }
+
+/* Header */
+#header hr { display: none }
+#header img { border: none; margin: 0 0 -3em }
+#header :link, #header :visited, #header :link:hover, #header :visited:hover {
+ background: transparent;
+ margin-bottom: 2px;
+ border: none;
+}
+
+/* Quick search */
+#search {
+ clear: both;
+ font-size: 10px;
+ height: 2.2em;
+ margin: 0 0 1em;
+ text-align: right;
+}
+#search input { font-size: 10px }
+#search label { display: none }
+
+/* Navigation */
+.nav h2, .nav hr { display: none }
+.nav ul { font-size: 10px; list-style: none; margin: 0; text-align: right }
+.nav li {
+ border-right: 1px solid #d7d7d7;
+ display: inline;
+ padding: 0 .75em;
+ white-space: nowrap;
+}
+.nav li.last { border-right: none }
+
+/* Main navigation bar */
+#mainnav {
+ background: #f7f7f7 url(../topbar_gradient.png) 0 0;
+ border: 1px solid #000;
+ font: normal 10px verdana,'Bitstream Vera Sans',helvetica,arial,sans-serif;
+ margin: .66em 0 .33em;
+ padding: .2em 0;
+}
+#mainnav li { border-right: none; padding: .25em 0 }
+#mainnav :link, #mainnav :visited {
+ background: url(../dots.gif) 0 0 no-repeat;
+ border-right: 1px solid #fff;
+ border-bottom: none;
+ border-left: 1px solid #555;
+ color: #000;
+ padding: .2em 20px;
+}
+* html #mainnav :link, * html #mainnav :visited { background-position: 1px 0 }
+#mainnav :link:hover, #mainnav :visited:hover {
+ background-color: #ccc;
+ border-right: 1px solid #ddd;
+}
+#mainnav .active:link, #mainnav .active:visited {
+ background: #333 url(../topbar_gradient2.png) 0 0 repeat-x;
+ border-top: none;
+ border-right: 1px solid #000;
+ color: #eee;
+ font-weight: bold;
+}
+#mainnav .active:link:hover, #mainnav .active:visited:hover {
+ border-right: 1px solid #000;
+}
+
+/* Context-dependent navigation links */
+#ctxtnav { height: 1em }
+#ctxtnav li ul {
+ background: #f7f7f7;
+ color: #ccc;
+ border: 1px solid;
+ padding: 0;
+ display: inline;
+ margin: 0;
+}
+#ctxtnav li li { padding: 0; }
+#ctxtnav li li :link, #ctxtnav li li :visited { padding: 0 1em }
+#ctxtnav li li :link:hover, #ctxtnav li li :visited:hover {
+ background: #bba;
+ color: #fff;
+}
+
+/* Alternate links */
+#altlinks { clear: both; text-align: center }
+#altlinks h3 { font-size: 12px; letter-spacing: normal; margin: 0 }
+#altlinks ul { list-style: none; margin: 0; padding: 0 0 1em }
+#altlinks li {
+ border-right: 1px solid #d7d7d7;
+ display: inline;
+ font-size: 11px;
+ line-height: 16px;
+ padding: 0 1em;
+ white-space: nowrap;
+}
+#altlinks li.last { border-right: none }
+#altlinks li :link, #altlinks li :visited {
+ background-position: 0 -1px;
+ background-repeat: no-repeat;
+ border: none;
+}
+#altlinks li a.ics { background-image: url(../ics.png); padding-left: 22px }
+#altlinks li a.rss { background-image: url(../xml.png); padding-left: 42px }
+
+/* Footer */
+#footer {
+ clear: both;
+ color: #bbb;
+ font-size: 10px;
+ border-top: 1px solid;
+ height: 31px;
+ padding: .25em 0;
+}
+#footer :link, #footer :visited { color: #bbb; }
+#footer hr { display: none }
+#footer #tracpowered { border: 0; float: left }
+#footer #tracpowered:hover { background: transparent }
+#footer p { margin: 0 }
+#footer p.left {
+ float: left;
+ margin-left: 1em;
+ padding: 0 1em;
+ border-left: 1px solid #d7d7d7;
+ border-right: 1px solid #d7d7d7;
+}
+#footer p.right {
+ float: right;
+ text-align: right;
+}
+
+#content { padding-bottom: 2em; position: relative }
+
+#help {
+ clear: both;
+ color: #999;
+ font-size: 90%;
+ margin: 1em;
+ text-align: right;
+}
+#help :link, #help :visited { cursor: help }
+#help hr { display: none }
+
+/* Page preferences form */
+#prefs {
+ background: #f7f7f0;
+ border: 1px outset #998;
+ float: right;
+ font-size: 9px;
+ padding: .8em;
+ position: relative;
+ margin: 0 1em 1em;
+}
+* html #prefs { width: 26em } /* Set width only for IE */
+#prefs input, #prefs select { font-size: 9px; vertical-align: middle }
+#prefs fieldset { border: none; margin: .5em; padding: 0 }
+#prefs fieldset legend {
+ background: transparent;
+ color: #000;
+ font-size: 9px;
+ font-weight: normal;
+ margin: 0 0 0 -1.5em;
+ padding: 0;
+}
+#prefs .buttons { text-align: right }
+
+/* Wiki */
+a.missing:link,a.missing:visited { background: #fafaf0; color: #998 }
+a.missing:hover { color: #000; }
+
+#content.wiki { line-height: 140% }
+.wikitoolbar {
+ border: solid #d7d7d7;
+ border-width: 1px 1px 1px 0;
+ float: left;
+ height: 18px;
+}
+.wikitoolbar :link, .wikitoolbar :visited {
+ background: transparent url(../edit_toolbar.png) no-repeat;
+ border: 1px solid #fff;
+ border-left-color: #d7d7d7;
+ cursor: default;
+ display: block;
+ float: left;
+ width: 24px;
+ height: 16px;
+}
+.wikitoolbar :link:hover, .wikitoolbar :visited:hover {
+ background-color: transparent;
+ border: 1px solid #fb2;
+}
+.wikitoolbar a#em { background-position: 0 0 }
+.wikitoolbar a#strong { background-position: 0 -16px }
+.wikitoolbar a#heading { background-position: 0 -32px }
+.wikitoolbar a#link { background-position: 0 -48px }
+.wikitoolbar a#code { background-position: 0 -64px }
+.wikitoolbar a#hr { background-position: 0 -80px }
+
+/* Styles for the form for adding attachments. */
+#attachment .field { margin-top: 1.3em }
+#attachment label { padding-left: .2em }
+#attachment fieldset { margin-top: 2em }
+#attachment fieldset .field { float: left; margin: 0 1em .5em 0 }
+#attachment br { clear: left }
+
+/* Styles for tabular listings such as those used for displaying directory
+ contents and report results. */
+table.listing {
+ clear: both;
+ border-bottom: 1px solid #d7d7d7;
+ border-collapse: collapse;
+ border-spacing: 0;
+ margin-top: 1em;
+ width: 100%;
+}
+table.listing th { text-align: left; padding: 0 1em .1em 0; font-size: 12px }
+table.listing thead { background: #f7f7f0 }
+table.listing thead th {
+ border: 1px solid #d7d7d7;
+ border-bottom-color: #999;
+ font-size: 11px;
+ font-weight: bold;
+ padding: 2px .5em;
+ vertical-align: bottom;
+}
+table.listing thead th :link:hover, table.listing thead th :visited:hover {
+ background-color: transparent;
+}
+table.listing thead th a { border: none; padding-right: 12px }
+table.listing th.asc a, table.listing th.desc a { font-weight: bold }
+table.listing th.asc a, table.listing th.desc a {
+ background-position: 100% 50%;
+ background-repeat: no-repeat;
+}
+table.listing th.asc a { background-image: url(../asc.png) }
+table.listing th.desc a { background-image: url(../desc.png) }
+table.listing tbody td, table.listing tbody th {
+ border: 1px dotted #ddd;
+ padding: .33em .5em;
+ vertical-align: top;
+}
+table.listing tbody td a:hover, table.listing tbody th a:hover {
+ background-color: transparent;
+}
+table.listing tbody tr { border-top: 1px solid #ddd }
+table.listing tbody tr.even { background-color: #fcfcfc }
+table.listing tbody tr.odd { background-color: #f7f7f7 }
+table.listing tbody tr:hover { background: #eed !important }
+
+.wikipage p { margin-left: 1em }
+pre.wiki, pre.literal-block {
+ background: #f7f7f7;
+ border: 1px solid #d7d7d7;
+ margin: 1em 1.75em;
+ padding: .25em;
+ overflow: auto;
+}
+table.wiki {
+ border: 2px solid #ccc;
+ border-collapse: collapse;
+ border-spacing: 0;
+}
+table.wiki td { border: 1px solid #ccc; padding: .1em .25em; }
+
+/* Styles for the error page (and rst errors) */
+#content.error .message, div.system-message {
+ background: #fdc;
+ border: 2px solid #d00;
+ color: #500;
+ padding: .5em;
+ margin: 1em 0;
+}
+#content.error pre, div.system-message pre { margin-left: 1em; overflow: auto }
+div.system-message p { margin: 0; }
+div.system-message p.system-message-title { font-weight: bold; }
+
+/* Styles for search word highlighting */
+ at media screen {
+ .searchword0 { background: #ff9 }
+ .searchword1 { background: #cfc }
+ .searchword2 { background: #cff }
+ .searchword3 { background: #ccf }
+ .searchword4 { background: #fcf }
+}
+
+ at media print {
+ #header, #altlinks, #footer { display: none }
+ .nav, form, .buttons form { display: none }
+}
diff --git a/rsaref/Makefile.am b/rsaref/Makefile.am
new file mode 100644
index 0000000..3905311
--- /dev/null
+++ b/rsaref/Makefile.am
@@ -0,0 +1,5 @@
+# Process this file with automake to create Makefile.in
+
+MAINTAINERCLEANFILES = Makefile.in
+
+EXTRA_DIST = README cryptoki.h pkcs11.h pkcs11f.h pkcs11t.h
diff --git a/rsaref/README b/rsaref/README
new file mode 100644
index 0000000..c7ff563
--- /dev/null
+++ b/rsaref/README
@@ -0,0 +1,21 @@
+These files have been downloaded from
+http://www.rsasecurity.com/rsalabs/node.asp?id=2133
+
+They were marked version 2.20.
+This note was linked to the files:
+
+Regarding the header / include files:
+
+License to copy and use this software is granted provided that it is identified
+as "RSA Security Inc. PKCS #11 Cryptographic Token Interface (Cryptoki)" in all
+material mentioning or referencing this software or this function.
+
+License is also granted to make and use derivative works provided that such
+works are identified as "derived from the RSA Security Inc. PKCS #11
+Cryptographic Token Interface (Cryptoki)" in all material mentioning or
+referencing the derived work.
+
+This software is provided AS IS and RSA Security, Inc. disclaims all warranties
+including but not limited to the implied warranty of merchantability, fitness
+for a particular purpose, and noninfringement.
+
diff --git a/rsaref/cryptoki.h b/rsaref/cryptoki.h
new file mode 100644
index 0000000..a484e2e
--- /dev/null
+++ b/rsaref/cryptoki.h
@@ -0,0 +1,75 @@
+/* cryptoki.h include file for PKCS #11. */
+/* $Revision: 1.4 $ */
+
+/* License to copy and use this software is granted provided that it is
+ * identified as "RSA Security Inc. PKCS #11 Cryptographic Token Interface
+ * (Cryptoki)" in all material mentioning or referencing this software.
+
+ * License is also granted to make and use derivative works provided that
+ * such works are identified as "derived from the RSA Security Inc. PKCS #11
+ * Cryptographic Token Interface (Cryptoki)" in all material mentioning or
+ * referencing the derived work.
+
+ * RSA Security Inc. makes no representations concerning either the
+ * merchantability of this software or the suitability of this software for
+ * any particular purpose. It is provided "as is" without express or implied
+ * warranty of any kind.
+ */
+
+/* This is a sample file containing the top level include directives
+ * for building Win32 Cryptoki libraries and applications.
+ */
+
+#ifndef ___CRYPTOKI_H_INC___
+#define ___CRYPTOKI_H_INC___
+
+#pragma pack(push, cryptoki, 1)
+
+#ifndef _WIN32
+#define CK_IMPORT_SPEC
+#define CK_EXPORT_SPEC
+#define CK_CALL_SPEC
+
+#else
+
+/* Specifies that the function is a DLL entry point. */
+#define CK_IMPORT_SPEC __declspec(dllimport)
+
+/* Define CRYPTOKI_EXPORTS during the build of cryptoki libraries. Do
+ * not define it in applications.
+ */
+#ifdef CRYPTOKI_EXPORTS
+/* Specified that the function is an exported DLL entry point. */
+#define CK_EXPORT_SPEC __declspec(dllexport)
+#else
+#define CK_EXPORT_SPEC CK_IMPORT_SPEC
+#endif
+
+/* Ensures the calling convention for Win32 builds */
+#define CK_CALL_SPEC __cdecl
+
+#endif
+
+#define CK_PTR *
+
+#define CK_DEFINE_FUNCTION(returnType, name) \
+ returnType CK_EXPORT_SPEC CK_CALL_SPEC name
+
+#define CK_DECLARE_FUNCTION(returnType, name) \
+ returnType CK_EXPORT_SPEC CK_CALL_SPEC name
+
+#define CK_DECLARE_FUNCTION_POINTER(returnType, name) \
+ returnType CK_IMPORT_SPEC (CK_CALL_SPEC CK_PTR name)
+
+#define CK_CALLBACK_FUNCTION(returnType, name) \
+ returnType (CK_CALL_SPEC CK_PTR name)
+
+#ifndef NULL_PTR
+#define NULL_PTR 0
+#endif
+
+#include "pkcs11.h"
+
+#pragma pack(pop, cryptoki)
+
+#endif /* ___CRYPTOKI_H_INC___ */
diff --git a/rsaref/pkcs11.h b/rsaref/pkcs11.h
new file mode 100644
index 0000000..5afbb7a
--- /dev/null
+++ b/rsaref/pkcs11.h
@@ -0,0 +1,299 @@
+/* pkcs11.h include file for PKCS #11. */
+/* $Revision: 1.4 $ */
+
+/* License to copy and use this software is granted provided that it is
+ * identified as "RSA Security Inc. PKCS #11 Cryptographic Token Interface
+ * (Cryptoki)" in all material mentioning or referencing this software.
+
+ * License is also granted to make and use derivative works provided that
+ * such works are identified as "derived from the RSA Security Inc. PKCS #11
+ * Cryptographic Token Interface (Cryptoki)" in all material mentioning or
+ * referencing the derived work.
+
+ * RSA Security Inc. makes no representations concerning either the
+ * merchantability of this software or the suitability of this software for
+ * any particular purpose. It is provided "as is" without express or implied
+ * warranty of any kind.
+ */
+
+#ifndef _PKCS11_H_
+#define _PKCS11_H_ 1
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Before including this file (pkcs11.h) (or pkcs11t.h by
+ * itself), 6 platform-specific macros must be defined. These
+ * macros are described below, and typical definitions for them
+ * are also given. Be advised that these definitions can depend
+ * on both the platform and the compiler used (and possibly also
+ * on whether a Cryptoki library is linked statically or
+ * dynamically).
+ *
+ * In addition to defining these 6 macros, the packing convention
+ * for Cryptoki structures should be set. The Cryptoki
+ * convention on packing is that structures should be 1-byte
+ * aligned.
+ *
+ * If you're using Microsoft Developer Studio 5.0 to produce
+ * Win32 stuff, this might be done by using the following
+ * preprocessor directive before including pkcs11.h or pkcs11t.h:
+ *
+ * #pragma pack(push, cryptoki, 1)
+ *
+ * and using the following preprocessor directive after including
+ * pkcs11.h or pkcs11t.h:
+ *
+ * #pragma pack(pop, cryptoki)
+ *
+ * If you're using an earlier version of Microsoft Developer
+ * Studio to produce Win16 stuff, this might be done by using
+ * the following preprocessor directive before including
+ * pkcs11.h or pkcs11t.h:
+ *
+ * #pragma pack(1)
+ *
+ * In a UNIX environment, you're on your own for this. You might
+ * not need to do (or be able to do!) anything.
+ *
+ *
+ * Now for the macros:
+ *
+ *
+ * 1. CK_PTR: The indirection string for making a pointer to an
+ * object. It can be used like this:
+ *
+ * typedef CK_BYTE CK_PTR CK_BYTE_PTR;
+ *
+ * If you're using Microsoft Developer Studio 5.0 to produce
+ * Win32 stuff, it might be defined by:
+ *
+ * #define CK_PTR *
+ *
+ * If you're using an earlier version of Microsoft Developer
+ * Studio to produce Win16 stuff, it might be defined by:
+ *
+ * #define CK_PTR far *
+ *
+ * In a typical UNIX environment, it might be defined by:
+ *
+ * #define CK_PTR *
+ *
+ *
+ * 2. CK_DEFINE_FUNCTION(returnType, name): A macro which makes
+ * an exportable Cryptoki library function definition out of a
+ * return type and a function name. It should be used in the
+ * following fashion to define the exposed Cryptoki functions in
+ * a Cryptoki library:
+ *
+ * CK_DEFINE_FUNCTION(CK_RV, C_Initialize)(
+ * CK_VOID_PTR pReserved
+ * )
+ * {
+ * ...
+ * }
+ *
+ * If you're using Microsoft Developer Studio 5.0 to define a
+ * function in a Win32 Cryptoki .dll, it might be defined by:
+ *
+ * #define CK_DEFINE_FUNCTION(returnType, name) \
+ * returnType __declspec(dllexport) name
+ *
+ * If you're using an earlier version of Microsoft Developer
+ * Studio to define a function in a Win16 Cryptoki .dll, it
+ * might be defined by:
+ *
+ * #define CK_DEFINE_FUNCTION(returnType, name) \
+ * returnType __export _far _pascal name
+ *
+ * In a UNIX environment, it might be defined by:
+ *
+ * #define CK_DEFINE_FUNCTION(returnType, name) \
+ * returnType name
+ *
+ *
+ * 3. CK_DECLARE_FUNCTION(returnType, name): A macro which makes
+ * an importable Cryptoki library function declaration out of a
+ * return type and a function name. It should be used in the
+ * following fashion:
+ *
+ * extern CK_DECLARE_FUNCTION(CK_RV, C_Initialize)(
+ * CK_VOID_PTR pReserved
+ * );
+ *
+ * If you're using Microsoft Developer Studio 5.0 to declare a
+ * function in a Win32 Cryptoki .dll, it might be defined by:
+ *
+ * #define CK_DECLARE_FUNCTION(returnType, name) \
+ * returnType __declspec(dllimport) name
+ *
+ * If you're using an earlier version of Microsoft Developer
+ * Studio to declare a function in a Win16 Cryptoki .dll, it
+ * might be defined by:
+ *
+ * #define CK_DECLARE_FUNCTION(returnType, name) \
+ * returnType __export _far _pascal name
+ *
+ * In a UNIX environment, it might be defined by:
+ *
+ * #define CK_DECLARE_FUNCTION(returnType, name) \
+ * returnType name
+ *
+ *
+ * 4. CK_DECLARE_FUNCTION_POINTER(returnType, name): A macro
+ * which makes a Cryptoki API function pointer declaration or
+ * function pointer type declaration out of a return type and a
+ * function name. It should be used in the following fashion:
+ *
+ * // Define funcPtr to be a pointer to a Cryptoki API function
+ * // taking arguments args and returning CK_RV.
+ * CK_DECLARE_FUNCTION_POINTER(CK_RV, funcPtr)(args);
+ *
+ * or
+ *
+ * // Define funcPtrType to be the type of a pointer to a
+ * // Cryptoki API function taking arguments args and returning
+ * // CK_RV, and then define funcPtr to be a variable of type
+ * // funcPtrType.
+ * typedef CK_DECLARE_FUNCTION_POINTER(CK_RV, funcPtrType)(args);
+ * funcPtrType funcPtr;
+ *
+ * If you're using Microsoft Developer Studio 5.0 to access
+ * functions in a Win32 Cryptoki .dll, in might be defined by:
+ *
+ * #define CK_DECLARE_FUNCTION_POINTER(returnType, name) \
+ * returnType __declspec(dllimport) (* name)
+ *
+ * If you're using an earlier version of Microsoft Developer
+ * Studio to access functions in a Win16 Cryptoki .dll, it might
+ * be defined by:
+ *
+ * #define CK_DECLARE_FUNCTION_POINTER(returnType, name) \
+ * returnType __export _far _pascal (* name)
+ *
+ * In a UNIX environment, it might be defined by:
+ *
+ * #define CK_DECLARE_FUNCTION_POINTER(returnType, name) \
+ * returnType (* name)
+ *
+ *
+ * 5. CK_CALLBACK_FUNCTION(returnType, name): A macro which makes
+ * a function pointer type for an application callback out of
+ * a return type for the callback and a name for the callback.
+ * It should be used in the following fashion:
+ *
+ * CK_CALLBACK_FUNCTION(CK_RV, myCallback)(args);
+ *
+ * to declare a function pointer, myCallback, to a callback
+ * which takes arguments args and returns a CK_RV. It can also
+ * be used like this:
+ *
+ * typedef CK_CALLBACK_FUNCTION(CK_RV, myCallbackType)(args);
+ * myCallbackType myCallback;
+ *
+ * If you're using Microsoft Developer Studio 5.0 to do Win32
+ * Cryptoki development, it might be defined by:
+ *
+ * #define CK_CALLBACK_FUNCTION(returnType, name) \
+ * returnType (* name)
+ *
+ * If you're using an earlier version of Microsoft Developer
+ * Studio to do Win16 development, it might be defined by:
+ *
+ * #define CK_CALLBACK_FUNCTION(returnType, name) \
+ * returnType _far _pascal (* name)
+ *
+ * In a UNIX environment, it might be defined by:
+ *
+ * #define CK_CALLBACK_FUNCTION(returnType, name) \
+ * returnType (* name)
+ *
+ *
+ * 6. NULL_PTR: This macro is the value of a NULL pointer.
+ *
+ * In any ANSI/ISO C environment (and in many others as well),
+ * this should best be defined by
+ *
+ * #ifndef NULL_PTR
+ * #define NULL_PTR 0
+ * #endif
+ */
+
+
+/* All the various Cryptoki types and #define'd values are in the
+ * file pkcs11t.h. */
+#include "pkcs11t.h"
+
+#define __PASTE(x,y) x##y
+
+
+/* ==============================================================
+ * Define the "extern" form of all the entry points.
+ * ==============================================================
+ */
+
+#define CK_NEED_ARG_LIST 1
+#define CK_PKCS11_FUNCTION_INFO(name) \
+ extern CK_DECLARE_FUNCTION(CK_RV, name)
+
+/* pkcs11f.h has all the information about the Cryptoki
+ * function prototypes. */
+#include "pkcs11f.h"
+
+#undef CK_NEED_ARG_LIST
+#undef CK_PKCS11_FUNCTION_INFO
+
+
+/* ==============================================================
+ * Define the typedef form of all the entry points. That is, for
+ * each Cryptoki function C_XXX, define a type CK_C_XXX which is
+ * a pointer to that kind of function.
+ * ==============================================================
+ */
+
+#define CK_NEED_ARG_LIST 1
+#define CK_PKCS11_FUNCTION_INFO(name) \
+ typedef CK_DECLARE_FUNCTION_POINTER(CK_RV, __PASTE(CK_,name))
+
+/* pkcs11f.h has all the information about the Cryptoki
+ * function prototypes. */
+#include "pkcs11f.h"
+
+#undef CK_NEED_ARG_LIST
+#undef CK_PKCS11_FUNCTION_INFO
+
+
+/* ==============================================================
+ * Define structed vector of entry points. A CK_FUNCTION_LIST
+ * contains a CK_VERSION indicating a library's Cryptoki version
+ * and then a whole slew of function pointers to the routines in
+ * the library. This type was declared, but not defined, in
+ * pkcs11t.h.
+ * ==============================================================
+ */
+
+#define CK_PKCS11_FUNCTION_INFO(name) \
+ __PASTE(CK_,name) name;
+
+struct CK_FUNCTION_LIST {
+
+ CK_VERSION version; /* Cryptoki version */
+
+/* Pile all the function pointers into the CK_FUNCTION_LIST. */
+/* pkcs11f.h has all the information about the Cryptoki
+ * function prototypes. */
+#include "pkcs11f.h"
+
+};
+
+#undef CK_PKCS11_FUNCTION_INFO
+
+
+#undef __PASTE
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/rsaref/pkcs11f.h b/rsaref/pkcs11f.h
new file mode 100644
index 0000000..3009753
--- /dev/null
+++ b/rsaref/pkcs11f.h
@@ -0,0 +1,912 @@
+/* pkcs11f.h include file for PKCS #11. */
+/* $Revision: 1.4 $ */
+
+/* License to copy and use this software is granted provided that it is
+ * identified as "RSA Security Inc. PKCS #11 Cryptographic Token Interface
+ * (Cryptoki)" in all material mentioning or referencing this software.
+
+ * License is also granted to make and use derivative works provided that
+ * such works are identified as "derived from the RSA Security Inc. PKCS #11
+ * Cryptographic Token Interface (Cryptoki)" in all material mentioning or
+ * referencing the derived work.
+
+ * RSA Security Inc. makes no representations concerning either the
+ * merchantability of this software or the suitability of this software for
+ * any particular purpose. It is provided "as is" without express or implied
+ * warranty of any kind.
+ */
+
+/* This header file contains pretty much everything about all the */
+/* Cryptoki function prototypes. Because this information is */
+/* used for more than just declaring function prototypes, the */
+/* order of the functions appearing herein is important, and */
+/* should not be altered. */
+
+/* General-purpose */
+
+/* C_Initialize initializes the Cryptoki library. */
+CK_PKCS11_FUNCTION_INFO(C_Initialize)
+#ifdef CK_NEED_ARG_LIST
+(
+ CK_VOID_PTR pInitArgs /* if this is not NULL_PTR, it gets
+ * cast to CK_C_INITIALIZE_ARGS_PTR
+ * and dereferenced */
+);
+#endif
+
+
+/* C_Finalize indicates that an application is done with the
+ * Cryptoki library. */
+CK_PKCS11_FUNCTION_INFO(C_Finalize)
+#ifdef CK_NEED_ARG_LIST
+(
+ CK_VOID_PTR pReserved /* reserved. Should be NULL_PTR */
+);
+#endif
+
+
+/* C_GetInfo returns general information about Cryptoki. */
+CK_PKCS11_FUNCTION_INFO(C_GetInfo)
+#ifdef CK_NEED_ARG_LIST
+(
+ CK_INFO_PTR pInfo /* location that receives information */
+);
+#endif
+
+
+/* C_GetFunctionList returns the function list. */
+CK_PKCS11_FUNCTION_INFO(C_GetFunctionList)
+#ifdef CK_NEED_ARG_LIST
+(
+ CK_FUNCTION_LIST_PTR_PTR ppFunctionList /* receives pointer to
+ * function list */
+);
+#endif
+
+
+
+/* Slot and token management */
+
+/* C_GetSlotList obtains a list of slots in the system. */
+CK_PKCS11_FUNCTION_INFO(C_GetSlotList)
+#ifdef CK_NEED_ARG_LIST
+(
+ CK_BBOOL tokenPresent, /* only slots with tokens? */
+ CK_SLOT_ID_PTR pSlotList, /* receives array of slot IDs */
+ CK_ULONG_PTR pulCount /* receives number of slots */
+);
+#endif
+
+
+/* C_GetSlotInfo obtains information about a particular slot in
+ * the system. */
+CK_PKCS11_FUNCTION_INFO(C_GetSlotInfo)
+#ifdef CK_NEED_ARG_LIST
+(
+ CK_SLOT_ID slotID, /* the ID of the slot */
+ CK_SLOT_INFO_PTR pInfo /* receives the slot information */
+);
+#endif
+
+
+/* C_GetTokenInfo obtains information about a particular token
+ * in the system. */
+CK_PKCS11_FUNCTION_INFO(C_GetTokenInfo)
+#ifdef CK_NEED_ARG_LIST
+(
+ CK_SLOT_ID slotID, /* ID of the token's slot */
+ CK_TOKEN_INFO_PTR pInfo /* receives the token information */
+);
+#endif
+
+
+/* C_GetMechanismList obtains a list of mechanism types
+ * supported by a token. */
+CK_PKCS11_FUNCTION_INFO(C_GetMechanismList)
+#ifdef CK_NEED_ARG_LIST
+(
+ CK_SLOT_ID slotID, /* ID of token's slot */
+ CK_MECHANISM_TYPE_PTR pMechanismList, /* gets mech. array */
+ CK_ULONG_PTR pulCount /* gets # of mechs. */
+);
+#endif
+
+
+/* C_GetMechanismInfo obtains information about a particular
+ * mechanism possibly supported by a token. */
+CK_PKCS11_FUNCTION_INFO(C_GetMechanismInfo)
+#ifdef CK_NEED_ARG_LIST
+(
+ CK_SLOT_ID slotID, /* ID of the token's slot */
+ CK_MECHANISM_TYPE type, /* type of mechanism */
+ CK_MECHANISM_INFO_PTR pInfo /* receives mechanism info */
+);
+#endif
+
+
+/* C_InitToken initializes a token. */
+CK_PKCS11_FUNCTION_INFO(C_InitToken)
+#ifdef CK_NEED_ARG_LIST
+/* pLabel changed from CK_CHAR_PTR to CK_UTF8CHAR_PTR for v2.10 */
+(
+ CK_SLOT_ID slotID, /* ID of the token's slot */
+ CK_UTF8CHAR_PTR pPin, /* the SO's initial PIN */
+ CK_ULONG ulPinLen, /* length in bytes of the PIN */
+ CK_UTF8CHAR_PTR pLabel /* 32-byte token label (blank padded) */
+);
+#endif
+
+
+/* C_InitPIN initializes the normal user's PIN. */
+CK_PKCS11_FUNCTION_INFO(C_InitPIN)
+#ifdef CK_NEED_ARG_LIST
+(
+ CK_SESSION_HANDLE hSession, /* the session's handle */
+ CK_UTF8CHAR_PTR pPin, /* the normal user's PIN */
+ CK_ULONG ulPinLen /* length in bytes of the PIN */
+);
+#endif
+
+
+/* C_SetPIN modifies the PIN of the user who is logged in. */
+CK_PKCS11_FUNCTION_INFO(C_SetPIN)
+#ifdef CK_NEED_ARG_LIST
+(
+ CK_SESSION_HANDLE hSession, /* the session's handle */
+ CK_UTF8CHAR_PTR pOldPin, /* the old PIN */
+ CK_ULONG ulOldLen, /* length of the old PIN */
+ CK_UTF8CHAR_PTR pNewPin, /* the new PIN */
+ CK_ULONG ulNewLen /* length of the new PIN */
+);
+#endif
+
+
+
+/* Session management */
+
+/* C_OpenSession opens a session between an application and a
+ * token. */
+CK_PKCS11_FUNCTION_INFO(C_OpenSession)
+#ifdef CK_NEED_ARG_LIST
+(
+ CK_SLOT_ID slotID, /* the slot's ID */
+ CK_FLAGS flags, /* from CK_SESSION_INFO */
+ CK_VOID_PTR pApplication, /* passed to callback */
+ CK_NOTIFY Notify, /* callback function */
+ CK_SESSION_HANDLE_PTR phSession /* gets session handle */
+);
+#endif
+
+
+/* C_CloseSession closes a session between an application and a
+ * token. */
+CK_PKCS11_FUNCTION_INFO(C_CloseSession)
+#ifdef CK_NEED_ARG_LIST
+(
+ CK_SESSION_HANDLE hSession /* the session's handle */
+);
+#endif
+
+
+/* C_CloseAllSessions closes all sessions with a token. */
+CK_PKCS11_FUNCTION_INFO(C_CloseAllSessions)
+#ifdef CK_NEED_ARG_LIST
+(
+ CK_SLOT_ID slotID /* the token's slot */
+);
+#endif
+
+
+/* C_GetSessionInfo obtains information about the session. */
+CK_PKCS11_FUNCTION_INFO(C_GetSessionInfo)
+#ifdef CK_NEED_ARG_LIST
+(
+ CK_SESSION_HANDLE hSession, /* the session's handle */
+ CK_SESSION_INFO_PTR pInfo /* receives session info */
+);
+#endif
+
+
+/* C_GetOperationState obtains the state of the cryptographic operation
+ * in a session. */
+CK_PKCS11_FUNCTION_INFO(C_GetOperationState)
+#ifdef CK_NEED_ARG_LIST
+(
+ CK_SESSION_HANDLE hSession, /* session's handle */
+ CK_BYTE_PTR pOperationState, /* gets state */
+ CK_ULONG_PTR pulOperationStateLen /* gets state length */
+);
+#endif
+
+
+/* C_SetOperationState restores the state of the cryptographic
+ * operation in a session. */
+CK_PKCS11_FUNCTION_INFO(C_SetOperationState)
+#ifdef CK_NEED_ARG_LIST
+(
+ CK_SESSION_HANDLE hSession, /* session's handle */
+ CK_BYTE_PTR pOperationState, /* holds state */
+ CK_ULONG ulOperationStateLen, /* holds state length */
+ CK_OBJECT_HANDLE hEncryptionKey, /* en/decryption key */
+ CK_OBJECT_HANDLE hAuthenticationKey /* sign/verify key */
+);
+#endif
+
+
+/* C_Login logs a user into a token. */
+CK_PKCS11_FUNCTION_INFO(C_Login)
+#ifdef CK_NEED_ARG_LIST
+(
+ CK_SESSION_HANDLE hSession, /* the session's handle */
+ CK_USER_TYPE userType, /* the user type */
+ CK_UTF8CHAR_PTR pPin, /* the user's PIN */
+ CK_ULONG ulPinLen /* the length of the PIN */
+);
+#endif
+
+
+/* C_Logout logs a user out from a token. */
+CK_PKCS11_FUNCTION_INFO(C_Logout)
+#ifdef CK_NEED_ARG_LIST
+(
+ CK_SESSION_HANDLE hSession /* the session's handle */
+);
+#endif
+
+
+
+/* Object management */
+
+/* C_CreateObject creates a new object. */
+CK_PKCS11_FUNCTION_INFO(C_CreateObject)
+#ifdef CK_NEED_ARG_LIST
+(
+ CK_SESSION_HANDLE hSession, /* the session's handle */
+ CK_ATTRIBUTE_PTR pTemplate, /* the object's template */
+ CK_ULONG ulCount, /* attributes in template */
+ CK_OBJECT_HANDLE_PTR phObject /* gets new object's handle. */
+);
+#endif
+
+
+/* C_CopyObject copies an object, creating a new object for the
+ * copy. */
+CK_PKCS11_FUNCTION_INFO(C_CopyObject)
+#ifdef CK_NEED_ARG_LIST
+(
+ CK_SESSION_HANDLE hSession, /* the session's handle */
+ CK_OBJECT_HANDLE hObject, /* the object's handle */
+ CK_ATTRIBUTE_PTR pTemplate, /* template for new object */
+ CK_ULONG ulCount, /* attributes in template */
+ CK_OBJECT_HANDLE_PTR phNewObject /* receives handle of copy */
+);
+#endif
+
+
+/* C_DestroyObject destroys an object. */
+CK_PKCS11_FUNCTION_INFO(C_DestroyObject)
+#ifdef CK_NEED_ARG_LIST
+(
+ CK_SESSION_HANDLE hSession, /* the session's handle */
+ CK_OBJECT_HANDLE hObject /* the object's handle */
+);
+#endif
+
+
+/* C_GetObjectSize gets the size of an object in bytes. */
+CK_PKCS11_FUNCTION_INFO(C_GetObjectSize)
+#ifdef CK_NEED_ARG_LIST
+(
+ CK_SESSION_HANDLE hSession, /* the session's handle */
+ CK_OBJECT_HANDLE hObject, /* the object's handle */
+ CK_ULONG_PTR pulSize /* receives size of object */
+);
+#endif
+
+
+/* C_GetAttributeValue obtains the value of one or more object
+ * attributes. */
+CK_PKCS11_FUNCTION_INFO(C_GetAttributeValue)
+#ifdef CK_NEED_ARG_LIST
+(
+ CK_SESSION_HANDLE hSession, /* the session's handle */
+ CK_OBJECT_HANDLE hObject, /* the object's handle */
+ CK_ATTRIBUTE_PTR pTemplate, /* specifies attrs; gets vals */
+ CK_ULONG ulCount /* attributes in template */
+);
+#endif
+
+
+/* C_SetAttributeValue modifies the value of one or more object
+ * attributes */
+CK_PKCS11_FUNCTION_INFO(C_SetAttributeValue)
+#ifdef CK_NEED_ARG_LIST
+(
+ CK_SESSION_HANDLE hSession, /* the session's handle */
+ CK_OBJECT_HANDLE hObject, /* the object's handle */
+ CK_ATTRIBUTE_PTR pTemplate, /* specifies attrs and values */
+ CK_ULONG ulCount /* attributes in template */
+);
+#endif
+
+
+/* C_FindObjectsInit initializes a search for token and session
+ * objects that match a template. */
+CK_PKCS11_FUNCTION_INFO(C_FindObjectsInit)
+#ifdef CK_NEED_ARG_LIST
+(
+ CK_SESSION_HANDLE hSession, /* the session's handle */
+ CK_ATTRIBUTE_PTR pTemplate, /* attribute values to match */
+ CK_ULONG ulCount /* attrs in search template */
+);
+#endif
+
+
+/* C_FindObjects continues a search for token and session
+ * objects that match a template, obtaining additional object
+ * handles. */
+CK_PKCS11_FUNCTION_INFO(C_FindObjects)
+#ifdef CK_NEED_ARG_LIST
+(
+ CK_SESSION_HANDLE hSession, /* session's handle */
+ CK_OBJECT_HANDLE_PTR phObject, /* gets obj. handles */
+ CK_ULONG ulMaxObjectCount, /* max handles to get */
+ CK_ULONG_PTR pulObjectCount /* actual # returned */
+);
+#endif
+
+
+/* C_FindObjectsFinal finishes a search for token and session
+ * objects. */
+CK_PKCS11_FUNCTION_INFO(C_FindObjectsFinal)
+#ifdef CK_NEED_ARG_LIST
+(
+ CK_SESSION_HANDLE hSession /* the session's handle */
+);
+#endif
+
+
+
+/* Encryption and decryption */
+
+/* C_EncryptInit initializes an encryption operation. */
+CK_PKCS11_FUNCTION_INFO(C_EncryptInit)
+#ifdef CK_NEED_ARG_LIST
+(
+ CK_SESSION_HANDLE hSession, /* the session's handle */
+ CK_MECHANISM_PTR pMechanism, /* the encryption mechanism */
+ CK_OBJECT_HANDLE hKey /* handle of encryption key */
+);
+#endif
+
+
+/* C_Encrypt encrypts single-part data. */
+CK_PKCS11_FUNCTION_INFO(C_Encrypt)
+#ifdef CK_NEED_ARG_LIST
+(
+ CK_SESSION_HANDLE hSession, /* session's handle */
+ CK_BYTE_PTR pData, /* the plaintext data */
+ CK_ULONG ulDataLen, /* bytes of plaintext */
+ CK_BYTE_PTR pEncryptedData, /* gets ciphertext */
+ CK_ULONG_PTR pulEncryptedDataLen /* gets c-text size */
+);
+#endif
+
+
+/* C_EncryptUpdate continues a multiple-part encryption
+ * operation. */
+CK_PKCS11_FUNCTION_INFO(C_EncryptUpdate)
+#ifdef CK_NEED_ARG_LIST
+(
+ CK_SESSION_HANDLE hSession, /* session's handle */
+ CK_BYTE_PTR pPart, /* the plaintext data */
+ CK_ULONG ulPartLen, /* plaintext data len */
+ CK_BYTE_PTR pEncryptedPart, /* gets ciphertext */
+ CK_ULONG_PTR pulEncryptedPartLen /* gets c-text size */
+);
+#endif
+
+
+/* C_EncryptFinal finishes a multiple-part encryption
+ * operation. */
+CK_PKCS11_FUNCTION_INFO(C_EncryptFinal)
+#ifdef CK_NEED_ARG_LIST
+(
+ CK_SESSION_HANDLE hSession, /* session handle */
+ CK_BYTE_PTR pLastEncryptedPart, /* last c-text */
+ CK_ULONG_PTR pulLastEncryptedPartLen /* gets last size */
+);
+#endif
+
+
+/* C_DecryptInit initializes a decryption operation. */
+CK_PKCS11_FUNCTION_INFO(C_DecryptInit)
+#ifdef CK_NEED_ARG_LIST
+(
+ CK_SESSION_HANDLE hSession, /* the session's handle */
+ CK_MECHANISM_PTR pMechanism, /* the decryption mechanism */
+ CK_OBJECT_HANDLE hKey /* handle of decryption key */
+);
+#endif
+
+
+/* C_Decrypt decrypts encrypted data in a single part. */
+CK_PKCS11_FUNCTION_INFO(C_Decrypt)
+#ifdef CK_NEED_ARG_LIST
+(
+ CK_SESSION_HANDLE hSession, /* session's handle */
+ CK_BYTE_PTR pEncryptedData, /* ciphertext */
+ CK_ULONG ulEncryptedDataLen, /* ciphertext length */
+ CK_BYTE_PTR pData, /* gets plaintext */
+ CK_ULONG_PTR pulDataLen /* gets p-text size */
+);
+#endif
+
+
+/* C_DecryptUpdate continues a multiple-part decryption
+ * operation. */
+CK_PKCS11_FUNCTION_INFO(C_DecryptUpdate)
+#ifdef CK_NEED_ARG_LIST
+(
+ CK_SESSION_HANDLE hSession, /* session's handle */
+ CK_BYTE_PTR pEncryptedPart, /* encrypted data */
+ CK_ULONG ulEncryptedPartLen, /* input length */
+ CK_BYTE_PTR pPart, /* gets plaintext */
+ CK_ULONG_PTR pulPartLen /* p-text size */
+);
+#endif
+
+
+/* C_DecryptFinal finishes a multiple-part decryption
+ * operation. */
+CK_PKCS11_FUNCTION_INFO(C_DecryptFinal)
+#ifdef CK_NEED_ARG_LIST
+(
+ CK_SESSION_HANDLE hSession, /* the session's handle */
+ CK_BYTE_PTR pLastPart, /* gets plaintext */
+ CK_ULONG_PTR pulLastPartLen /* p-text size */
+);
+#endif
+
+
+
+/* Message digesting */
+
+/* C_DigestInit initializes a message-digesting operation. */
+CK_PKCS11_FUNCTION_INFO(C_DigestInit)
+#ifdef CK_NEED_ARG_LIST
+(
+ CK_SESSION_HANDLE hSession, /* the session's handle */
+ CK_MECHANISM_PTR pMechanism /* the digesting mechanism */
+);
+#endif
+
+
+/* C_Digest digests data in a single part. */
+CK_PKCS11_FUNCTION_INFO(C_Digest)
+#ifdef CK_NEED_ARG_LIST
+(
+ CK_SESSION_HANDLE hSession, /* the session's handle */
+ CK_BYTE_PTR pData, /* data to be digested */
+ CK_ULONG ulDataLen, /* bytes of data to digest */
+ CK_BYTE_PTR pDigest, /* gets the message digest */
+ CK_ULONG_PTR pulDigestLen /* gets digest length */
+);
+#endif
+
+
+/* C_DigestUpdate continues a multiple-part message-digesting
+ * operation. */
+CK_PKCS11_FUNCTION_INFO(C_DigestUpdate)
+#ifdef CK_NEED_ARG_LIST
+(
+ CK_SESSION_HANDLE hSession, /* the session's handle */
+ CK_BYTE_PTR pPart, /* data to be digested */
+ CK_ULONG ulPartLen /* bytes of data to be digested */
+);
+#endif
+
+
+/* C_DigestKey continues a multi-part message-digesting
+ * operation, by digesting the value of a secret key as part of
+ * the data already digested. */
+CK_PKCS11_FUNCTION_INFO(C_DigestKey)
+#ifdef CK_NEED_ARG_LIST
+(
+ CK_SESSION_HANDLE hSession, /* the session's handle */
+ CK_OBJECT_HANDLE hKey /* secret key to digest */
+);
+#endif
+
+
+/* C_DigestFinal finishes a multiple-part message-digesting
+ * operation. */
+CK_PKCS11_FUNCTION_INFO(C_DigestFinal)
+#ifdef CK_NEED_ARG_LIST
+(
+ CK_SESSION_HANDLE hSession, /* the session's handle */
+ CK_BYTE_PTR pDigest, /* gets the message digest */
+ CK_ULONG_PTR pulDigestLen /* gets byte count of digest */
+);
+#endif
+
+
+
+/* Signing and MACing */
+
+/* C_SignInit initializes a signature (private key encryption)
+ * operation, where the signature is (will be) an appendix to
+ * the data, and plaintext cannot be recovered from the
+ *signature. */
+CK_PKCS11_FUNCTION_INFO(C_SignInit)
+#ifdef CK_NEED_ARG_LIST
+(
+ CK_SESSION_HANDLE hSession, /* the session's handle */
+ CK_MECHANISM_PTR pMechanism, /* the signature mechanism */
+ CK_OBJECT_HANDLE hKey /* handle of signature key */
+);
+#endif
+
+
+/* C_Sign signs (encrypts with private key) data in a single
+ * part, where the signature is (will be) an appendix to the
+ * data, and plaintext cannot be recovered from the signature. */
+CK_PKCS11_FUNCTION_INFO(C_Sign)
+#ifdef CK_NEED_ARG_LIST
+(
+ CK_SESSION_HANDLE hSession, /* the session's handle */
+ CK_BYTE_PTR pData, /* the data to sign */
+ CK_ULONG ulDataLen, /* count of bytes to sign */
+ CK_BYTE_PTR pSignature, /* gets the signature */
+ CK_ULONG_PTR pulSignatureLen /* gets signature length */
+);
+#endif
+
+
+/* C_SignUpdate continues a multiple-part signature operation,
+ * where the signature is (will be) an appendix to the data,
+ * and plaintext cannot be recovered from the signature. */
+CK_PKCS11_FUNCTION_INFO(C_SignUpdate)
+#ifdef CK_NEED_ARG_LIST
+(
+ CK_SESSION_HANDLE hSession, /* the session's handle */
+ CK_BYTE_PTR pPart, /* the data to sign */
+ CK_ULONG ulPartLen /* count of bytes to sign */
+);
+#endif
+
+
+/* C_SignFinal finishes a multiple-part signature operation,
+ * returning the signature. */
+CK_PKCS11_FUNCTION_INFO(C_SignFinal)
+#ifdef CK_NEED_ARG_LIST
+(
+ CK_SESSION_HANDLE hSession, /* the session's handle */
+ CK_BYTE_PTR pSignature, /* gets the signature */
+ CK_ULONG_PTR pulSignatureLen /* gets signature length */
+);
+#endif
+
+
+/* C_SignRecoverInit initializes a signature operation, where
+ * the data can be recovered from the signature. */
+CK_PKCS11_FUNCTION_INFO(C_SignRecoverInit)
+#ifdef CK_NEED_ARG_LIST
+(
+ CK_SESSION_HANDLE hSession, /* the session's handle */
+ CK_MECHANISM_PTR pMechanism, /* the signature mechanism */
+ CK_OBJECT_HANDLE hKey /* handle of the signature key */
+);
+#endif
+
+
+/* C_SignRecover signs data in a single operation, where the
+ * data can be recovered from the signature. */
+CK_PKCS11_FUNCTION_INFO(C_SignRecover)
+#ifdef CK_NEED_ARG_LIST
+(
+ CK_SESSION_HANDLE hSession, /* the session's handle */
+ CK_BYTE_PTR pData, /* the data to sign */
+ CK_ULONG ulDataLen, /* count of bytes to sign */
+ CK_BYTE_PTR pSignature, /* gets the signature */
+ CK_ULONG_PTR pulSignatureLen /* gets signature length */
+);
+#endif
+
+
+
+/* Verifying signatures and MACs */
+
+/* C_VerifyInit initializes a verification operation, where the
+ * signature is an appendix to the data, and plaintext cannot
+ * cannot be recovered from the signature (e.g. DSA). */
+CK_PKCS11_FUNCTION_INFO(C_VerifyInit)
+#ifdef CK_NEED_ARG_LIST
+(
+ CK_SESSION_HANDLE hSession, /* the session's handle */
+ CK_MECHANISM_PTR pMechanism, /* the verification mechanism */
+ CK_OBJECT_HANDLE hKey /* verification key */
+);
+#endif
+
+
+/* C_Verify verifies a signature in a single-part operation,
+ * where the signature is an appendix to the data, and plaintext
+ * cannot be recovered from the signature. */
+CK_PKCS11_FUNCTION_INFO(C_Verify)
+#ifdef CK_NEED_ARG_LIST
+(
+ CK_SESSION_HANDLE hSession, /* the session's handle */
+ CK_BYTE_PTR pData, /* signed data */
+ CK_ULONG ulDataLen, /* length of signed data */
+ CK_BYTE_PTR pSignature, /* signature */
+ CK_ULONG ulSignatureLen /* signature length*/
+);
+#endif
+
+
+/* C_VerifyUpdate continues a multiple-part verification
+ * operation, where the signature is an appendix to the data,
+ * and plaintext cannot be recovered from the signature. */
+CK_PKCS11_FUNCTION_INFO(C_VerifyUpdate)
+#ifdef CK_NEED_ARG_LIST
+(
+ CK_SESSION_HANDLE hSession, /* the session's handle */
+ CK_BYTE_PTR pPart, /* signed data */
+ CK_ULONG ulPartLen /* length of signed data */
+);
+#endif
+
+
+/* C_VerifyFinal finishes a multiple-part verification
+ * operation, checking the signature. */
+CK_PKCS11_FUNCTION_INFO(C_VerifyFinal)
+#ifdef CK_NEED_ARG_LIST
+(
+ CK_SESSION_HANDLE hSession, /* the session's handle */
+ CK_BYTE_PTR pSignature, /* signature to verify */
+ CK_ULONG ulSignatureLen /* signature length */
+);
+#endif
+
+
+/* C_VerifyRecoverInit initializes a signature verification
+ * operation, where the data is recovered from the signature. */
+CK_PKCS11_FUNCTION_INFO(C_VerifyRecoverInit)
+#ifdef CK_NEED_ARG_LIST
+(
+ CK_SESSION_HANDLE hSession, /* the session's handle */
+ CK_MECHANISM_PTR pMechanism, /* the verification mechanism */
+ CK_OBJECT_HANDLE hKey /* verification key */
+);
+#endif
+
+
+/* C_VerifyRecover verifies a signature in a single-part
+ * operation, where the data is recovered from the signature. */
+CK_PKCS11_FUNCTION_INFO(C_VerifyRecover)
+#ifdef CK_NEED_ARG_LIST
+(
+ CK_SESSION_HANDLE hSession, /* the session's handle */
+ CK_BYTE_PTR pSignature, /* signature to verify */
+ CK_ULONG ulSignatureLen, /* signature length */
+ CK_BYTE_PTR pData, /* gets signed data */
+ CK_ULONG_PTR pulDataLen /* gets signed data len */
+);
+#endif
+
+
+
+/* Dual-function cryptographic operations */
+
+/* C_DigestEncryptUpdate continues a multiple-part digesting
+ * and encryption operation. */
+CK_PKCS11_FUNCTION_INFO(C_DigestEncryptUpdate)
+#ifdef CK_NEED_ARG_LIST
+(
+ CK_SESSION_HANDLE hSession, /* session's handle */
+ CK_BYTE_PTR pPart, /* the plaintext data */
+ CK_ULONG ulPartLen, /* plaintext length */
+ CK_BYTE_PTR pEncryptedPart, /* gets ciphertext */
+ CK_ULONG_PTR pulEncryptedPartLen /* gets c-text length */
+);
+#endif
+
+
+/* C_DecryptDigestUpdate continues a multiple-part decryption and
+ * digesting operation. */
+CK_PKCS11_FUNCTION_INFO(C_DecryptDigestUpdate)
+#ifdef CK_NEED_ARG_LIST
+(
+ CK_SESSION_HANDLE hSession, /* session's handle */
+ CK_BYTE_PTR pEncryptedPart, /* ciphertext */
+ CK_ULONG ulEncryptedPartLen, /* ciphertext length */
+ CK_BYTE_PTR pPart, /* gets plaintext */
+ CK_ULONG_PTR pulPartLen /* gets plaintext len */
+);
+#endif
+
+
+/* C_SignEncryptUpdate continues a multiple-part signing and
+ * encryption operation. */
+CK_PKCS11_FUNCTION_INFO(C_SignEncryptUpdate)
+#ifdef CK_NEED_ARG_LIST
+(
+ CK_SESSION_HANDLE hSession, /* session's handle */
+ CK_BYTE_PTR pPart, /* the plaintext data */
+ CK_ULONG ulPartLen, /* plaintext length */
+ CK_BYTE_PTR pEncryptedPart, /* gets ciphertext */
+ CK_ULONG_PTR pulEncryptedPartLen /* gets c-text length */
+);
+#endif
+
+
+/* C_DecryptVerifyUpdate continues a multiple-part decryption and
+ * verify operation. */
+CK_PKCS11_FUNCTION_INFO(C_DecryptVerifyUpdate)
+#ifdef CK_NEED_ARG_LIST
+(
+ CK_SESSION_HANDLE hSession, /* session's handle */
+ CK_BYTE_PTR pEncryptedPart, /* ciphertext */
+ CK_ULONG ulEncryptedPartLen, /* ciphertext length */
+ CK_BYTE_PTR pPart, /* gets plaintext */
+ CK_ULONG_PTR pulPartLen /* gets p-text length */
+);
+#endif
+
+
+
+/* Key management */
+
+/* C_GenerateKey generates a secret key, creating a new key
+ * object. */
+CK_PKCS11_FUNCTION_INFO(C_GenerateKey)
+#ifdef CK_NEED_ARG_LIST
+(
+ CK_SESSION_HANDLE hSession, /* the session's handle */
+ CK_MECHANISM_PTR pMechanism, /* key generation mech. */
+ CK_ATTRIBUTE_PTR pTemplate, /* template for new key */
+ CK_ULONG ulCount, /* # of attrs in template */
+ CK_OBJECT_HANDLE_PTR phKey /* gets handle of new key */
+);
+#endif
+
+
+/* C_GenerateKeyPair generates a public-key/private-key pair,
+ * creating new key objects. */
+CK_PKCS11_FUNCTION_INFO(C_GenerateKeyPair)
+#ifdef CK_NEED_ARG_LIST
+(
+ CK_SESSION_HANDLE hSession, /* session
+ * handle */
+ CK_MECHANISM_PTR pMechanism, /* key-gen
+ * mech. */
+ CK_ATTRIBUTE_PTR pPublicKeyTemplate, /* template
+ * for pub.
+ * key */
+ CK_ULONG ulPublicKeyAttributeCount, /* # pub.
+ * attrs. */
+ CK_ATTRIBUTE_PTR pPrivateKeyTemplate, /* template
+ * for priv.
+ * key */
+ CK_ULONG ulPrivateKeyAttributeCount, /* # priv.
+ * attrs. */
+ CK_OBJECT_HANDLE_PTR phPublicKey, /* gets pub.
+ * key
+ * handle */
+ CK_OBJECT_HANDLE_PTR phPrivateKey /* gets
+ * priv. key
+ * handle */
+);
+#endif
+
+
+/* C_WrapKey wraps (i.e., encrypts) a key. */
+CK_PKCS11_FUNCTION_INFO(C_WrapKey)
+#ifdef CK_NEED_ARG_LIST
+(
+ CK_SESSION_HANDLE hSession, /* the session's handle */
+ CK_MECHANISM_PTR pMechanism, /* the wrapping mechanism */
+ CK_OBJECT_HANDLE hWrappingKey, /* wrapping key */
+ CK_OBJECT_HANDLE hKey, /* key to be wrapped */
+ CK_BYTE_PTR pWrappedKey, /* gets wrapped key */
+ CK_ULONG_PTR pulWrappedKeyLen /* gets wrapped key size */
+);
+#endif
+
+
+/* C_UnwrapKey unwraps (decrypts) a wrapped key, creating a new
+ * key object. */
+CK_PKCS11_FUNCTION_INFO(C_UnwrapKey)
+#ifdef CK_NEED_ARG_LIST
+(
+ CK_SESSION_HANDLE hSession, /* session's handle */
+ CK_MECHANISM_PTR pMechanism, /* unwrapping mech. */
+ CK_OBJECT_HANDLE hUnwrappingKey, /* unwrapping key */
+ CK_BYTE_PTR pWrappedKey, /* the wrapped key */
+ CK_ULONG ulWrappedKeyLen, /* wrapped key len */
+ CK_ATTRIBUTE_PTR pTemplate, /* new key template */
+ CK_ULONG ulAttributeCount, /* template length */
+ CK_OBJECT_HANDLE_PTR phKey /* gets new handle */
+);
+#endif
+
+
+/* C_DeriveKey derives a key from a base key, creating a new key
+ * object. */
+CK_PKCS11_FUNCTION_INFO(C_DeriveKey)
+#ifdef CK_NEED_ARG_LIST
+(
+ CK_SESSION_HANDLE hSession, /* session's handle */
+ CK_MECHANISM_PTR pMechanism, /* key deriv. mech. */
+ CK_OBJECT_HANDLE hBaseKey, /* base key */
+ CK_ATTRIBUTE_PTR pTemplate, /* new key template */
+ CK_ULONG ulAttributeCount, /* template length */
+ CK_OBJECT_HANDLE_PTR phKey /* gets new handle */
+);
+#endif
+
+
+
+/* Random number generation */
+
+/* C_SeedRandom mixes additional seed material into the token's
+ * random number generator. */
+CK_PKCS11_FUNCTION_INFO(C_SeedRandom)
+#ifdef CK_NEED_ARG_LIST
+(
+ CK_SESSION_HANDLE hSession, /* the session's handle */
+ CK_BYTE_PTR pSeed, /* the seed material */
+ CK_ULONG ulSeedLen /* length of seed material */
+);
+#endif
+
+
+/* C_GenerateRandom generates random data. */
+CK_PKCS11_FUNCTION_INFO(C_GenerateRandom)
+#ifdef CK_NEED_ARG_LIST
+(
+ CK_SESSION_HANDLE hSession, /* the session's handle */
+ CK_BYTE_PTR RandomData, /* receives the random data */
+ CK_ULONG ulRandomLen /* # of bytes to generate */
+);
+#endif
+
+
+
+/* Parallel function management */
+
+/* C_GetFunctionStatus is a legacy function; it obtains an
+ * updated status of a function running in parallel with an
+ * application. */
+CK_PKCS11_FUNCTION_INFO(C_GetFunctionStatus)
+#ifdef CK_NEED_ARG_LIST
+(
+ CK_SESSION_HANDLE hSession /* the session's handle */
+);
+#endif
+
+
+/* C_CancelFunction is a legacy function; it cancels a function
+ * running in parallel. */
+CK_PKCS11_FUNCTION_INFO(C_CancelFunction)
+#ifdef CK_NEED_ARG_LIST
+(
+ CK_SESSION_HANDLE hSession /* the session's handle */
+);
+#endif
+
+
+
+/* Functions added in for Cryptoki Version 2.01 or later */
+
+/* C_WaitForSlotEvent waits for a slot event (token insertion,
+ * removal, etc.) to occur. */
+CK_PKCS11_FUNCTION_INFO(C_WaitForSlotEvent)
+#ifdef CK_NEED_ARG_LIST
+(
+ CK_FLAGS flags, /* blocking/nonblocking flag */
+ CK_SLOT_ID_PTR pSlot, /* location that receives the slot ID */
+ CK_VOID_PTR pRserved /* reserved. Should be NULL_PTR */
+);
+#endif
diff --git a/rsaref/pkcs11t.h b/rsaref/pkcs11t.h
new file mode 100644
index 0000000..a3c07c8
--- /dev/null
+++ b/rsaref/pkcs11t.h
@@ -0,0 +1,1685 @@
+/* pkcs11t.h include file for PKCS #11. */
+/* $Revision: 1.6 $ */
+
+/* License to copy and use this software is granted provided that it is
+ * identified as "RSA Security Inc. PKCS #11 Cryptographic Token Interface
+ * (Cryptoki)" in all material mentioning or referencing this software.
+
+ * License is also granted to make and use derivative works provided that
+ * such works are identified as "derived from the RSA Security Inc. PKCS #11
+ * Cryptographic Token Interface (Cryptoki)" in all material mentioning or
+ * referencing the derived work.
+
+ * RSA Security Inc. makes no representations concerning either the
+ * merchantability of this software or the suitability of this software for
+ * any particular purpose. It is provided "as is" without express or implied
+ * warranty of any kind.
+ */
+
+/* See top of pkcs11.h for information about the macros that
+ * must be defined and the structure-packing conventions that
+ * must be set before including this file. */
+
+#ifndef _PKCS11T_H_
+#define _PKCS11T_H_ 1
+
+#define CK_TRUE 1
+#define CK_FALSE 0
+
+#ifndef CK_DISABLE_TRUE_FALSE
+#ifndef FALSE
+#define FALSE CK_FALSE
+#endif
+
+#ifndef TRUE
+#define TRUE CK_TRUE
+#endif
+#endif
+
+/* an unsigned 8-bit value */
+typedef unsigned char CK_BYTE;
+
+/* an unsigned 8-bit character */
+typedef CK_BYTE CK_CHAR;
+
+/* an 8-bit UTF-8 character */
+typedef CK_BYTE CK_UTF8CHAR;
+
+/* a BYTE-sized Boolean flag */
+typedef CK_BYTE CK_BBOOL;
+
+/* an unsigned value, at least 32 bits long */
+typedef unsigned long int CK_ULONG;
+
+/* a signed value, the same size as a CK_ULONG */
+/* CK_LONG is new for v2.0 */
+typedef long int CK_LONG;
+
+/* at least 32 bits; each bit is a Boolean flag */
+typedef CK_ULONG CK_FLAGS;
+
+
+/* some special values for certain CK_ULONG variables */
+#define CK_UNAVAILABLE_INFORMATION (~0UL)
+#define CK_EFFECTIVELY_INFINITE 0
+
+
+typedef CK_BYTE CK_PTR CK_BYTE_PTR;
+typedef CK_CHAR CK_PTR CK_CHAR_PTR;
+typedef CK_UTF8CHAR CK_PTR CK_UTF8CHAR_PTR;
+typedef CK_ULONG CK_PTR CK_ULONG_PTR;
+typedef void CK_PTR CK_VOID_PTR;
+
+/* Pointer to a CK_VOID_PTR-- i.e., pointer to pointer to void */
+typedef CK_VOID_PTR CK_PTR CK_VOID_PTR_PTR;
+
+
+/* The following value is always invalid if used as a session */
+/* handle or object handle */
+#define CK_INVALID_HANDLE 0
+
+
+typedef struct CK_VERSION {
+ CK_BYTE major; /* integer portion of version number */
+ CK_BYTE minor; /* 1/100ths portion of version number */
+} CK_VERSION;
+
+typedef CK_VERSION CK_PTR CK_VERSION_PTR;
+
+
+typedef struct CK_INFO {
+ /* manufacturerID and libraryDecription have been changed from
+ * CK_CHAR to CK_UTF8CHAR for v2.10 */
+ CK_VERSION cryptokiVersion; /* Cryptoki interface ver */
+ CK_UTF8CHAR manufacturerID[32]; /* blank padded */
+ CK_FLAGS flags; /* must be zero */
+
+ /* libraryDescription and libraryVersion are new for v2.0 */
+ CK_UTF8CHAR libraryDescription[32]; /* blank padded */
+ CK_VERSION libraryVersion; /* version of library */
+} CK_INFO;
+
+typedef CK_INFO CK_PTR CK_INFO_PTR;
+
+
+/* CK_NOTIFICATION enumerates the types of notifications that
+ * Cryptoki provides to an application */
+/* CK_NOTIFICATION has been changed from an enum to a CK_ULONG
+ * for v2.0 */
+typedef CK_ULONG CK_NOTIFICATION;
+#define CKN_SURRENDER 0
+
+
+typedef CK_ULONG CK_SLOT_ID;
+
+typedef CK_SLOT_ID CK_PTR CK_SLOT_ID_PTR;
+
+
+/* CK_SLOT_INFO provides information about a slot */
+typedef struct CK_SLOT_INFO {
+ /* slotDescription and manufacturerID have been changed from
+ * CK_CHAR to CK_UTF8CHAR for v2.10 */
+ CK_UTF8CHAR slotDescription[64]; /* blank padded */
+ CK_UTF8CHAR manufacturerID[32]; /* blank padded */
+ CK_FLAGS flags;
+
+ /* hardwareVersion and firmwareVersion are new for v2.0 */
+ CK_VERSION hardwareVersion; /* version of hardware */
+ CK_VERSION firmwareVersion; /* version of firmware */
+} CK_SLOT_INFO;
+
+/* flags: bit flags that provide capabilities of the slot
+ * Bit Flag Mask Meaning
+ */
+#define CKF_TOKEN_PRESENT 0x00000001 /* a token is there */
+#define CKF_REMOVABLE_DEVICE 0x00000002 /* removable devices*/
+#define CKF_HW_SLOT 0x00000004 /* hardware slot */
+
+typedef CK_SLOT_INFO CK_PTR CK_SLOT_INFO_PTR;
+
+
+/* CK_TOKEN_INFO provides information about a token */
+typedef struct CK_TOKEN_INFO {
+ /* label, manufacturerID, and model have been changed from
+ * CK_CHAR to CK_UTF8CHAR for v2.10 */
+ CK_UTF8CHAR label[32]; /* blank padded */
+ CK_UTF8CHAR manufacturerID[32]; /* blank padded */
+ CK_UTF8CHAR model[16]; /* blank padded */
+ CK_CHAR serialNumber[16]; /* blank padded */
+ CK_FLAGS flags; /* see below */
+
+ /* ulMaxSessionCount, ulSessionCount, ulMaxRwSessionCount,
+ * ulRwSessionCount, ulMaxPinLen, and ulMinPinLen have all been
+ * changed from CK_USHORT to CK_ULONG for v2.0 */
+ CK_ULONG ulMaxSessionCount; /* max open sessions */
+ CK_ULONG ulSessionCount; /* sess. now open */
+ CK_ULONG ulMaxRwSessionCount; /* max R/W sessions */
+ CK_ULONG ulRwSessionCount; /* R/W sess. now open */
+ CK_ULONG ulMaxPinLen; /* in bytes */
+ CK_ULONG ulMinPinLen; /* in bytes */
+ CK_ULONG ulTotalPublicMemory; /* in bytes */
+ CK_ULONG ulFreePublicMemory; /* in bytes */
+ CK_ULONG ulTotalPrivateMemory; /* in bytes */
+ CK_ULONG ulFreePrivateMemory; /* in bytes */
+
+ /* hardwareVersion, firmwareVersion, and time are new for
+ * v2.0 */
+ CK_VERSION hardwareVersion; /* version of hardware */
+ CK_VERSION firmwareVersion; /* version of firmware */
+ CK_CHAR utcTime[16]; /* time */
+} CK_TOKEN_INFO;
+
+/* The flags parameter is defined as follows:
+ * Bit Flag Mask Meaning
+ */
+#define CKF_RNG 0x00000001 /* has random #
+ * generator */
+#define CKF_WRITE_PROTECTED 0x00000002 /* token is
+ * write-
+ * protected */
+#define CKF_LOGIN_REQUIRED 0x00000004 /* user must
+ * login */
+#define CKF_USER_PIN_INITIALIZED 0x00000008 /* normal user's
+ * PIN is set */
+
+/* CKF_RESTORE_KEY_NOT_NEEDED is new for v2.0. If it is set,
+ * that means that *every* time the state of cryptographic
+ * operations of a session is successfully saved, all keys
+ * needed to continue those operations are stored in the state */
+#define CKF_RESTORE_KEY_NOT_NEEDED 0x00000020
+
+/* CKF_CLOCK_ON_TOKEN is new for v2.0. If it is set, that means
+ * that the token has some sort of clock. The time on that
+ * clock is returned in the token info structure */
+#define CKF_CLOCK_ON_TOKEN 0x00000040
+
+/* CKF_PROTECTED_AUTHENTICATION_PATH is new for v2.0. If it is
+ * set, that means that there is some way for the user to login
+ * without sending a PIN through the Cryptoki library itself */
+#define CKF_PROTECTED_AUTHENTICATION_PATH 0x00000100
+
+/* CKF_DUAL_CRYPTO_OPERATIONS is new for v2.0. If it is true,
+ * that means that a single session with the token can perform
+ * dual simultaneous cryptographic operations (digest and
+ * encrypt; decrypt and digest; sign and encrypt; and decrypt
+ * and sign) */
+#define CKF_DUAL_CRYPTO_OPERATIONS 0x00000200
+
+/* CKF_TOKEN_INITIALIZED if new for v2.10. If it is true, the
+ * token has been initialized using C_InitializeToken or an
+ * equivalent mechanism outside the scope of PKCS #11.
+ * Calling C_InitializeToken when this flag is set will cause
+ * the token to be reinitialized. */
+#define CKF_TOKEN_INITIALIZED 0x00000400
+
+/* CKF_SECONDARY_AUTHENTICATION if new for v2.10. If it is
+ * true, the token supports secondary authentication for
+ * private key objects. This flag is deprecated in v2.11 and
+ onwards. */
+#define CKF_SECONDARY_AUTHENTICATION 0x00000800
+
+/* CKF_USER_PIN_COUNT_LOW if new for v2.10. If it is true, an
+ * incorrect user login PIN has been entered at least once
+ * since the last successful authentication. */
+#define CKF_USER_PIN_COUNT_LOW 0x00010000
+
+/* CKF_USER_PIN_FINAL_TRY if new for v2.10. If it is true,
+ * supplying an incorrect user PIN will it to become locked. */
+#define CKF_USER_PIN_FINAL_TRY 0x00020000
+
+/* CKF_USER_PIN_LOCKED if new for v2.10. If it is true, the
+ * user PIN has been locked. User login to the token is not
+ * possible. */
+#define CKF_USER_PIN_LOCKED 0x00040000
+
+/* CKF_USER_PIN_TO_BE_CHANGED if new for v2.10. If it is true,
+ * the user PIN value is the default value set by token
+ * initialization or manufacturing, or the PIN has been
+ * expired by the card. */
+#define CKF_USER_PIN_TO_BE_CHANGED 0x00080000
+
+/* CKF_SO_PIN_COUNT_LOW if new for v2.10. If it is true, an
+ * incorrect SO login PIN has been entered at least once since
+ * the last successful authentication. */
+#define CKF_SO_PIN_COUNT_LOW 0x00100000
+
+/* CKF_SO_PIN_FINAL_TRY if new for v2.10. If it is true,
+ * supplying an incorrect SO PIN will it to become locked. */
+#define CKF_SO_PIN_FINAL_TRY 0x00200000
+
+/* CKF_SO_PIN_LOCKED if new for v2.10. If it is true, the SO
+ * PIN has been locked. SO login to the token is not possible.
+ */
+#define CKF_SO_PIN_LOCKED 0x00400000
+
+/* CKF_SO_PIN_TO_BE_CHANGED if new for v2.10. If it is true,
+ * the SO PIN value is the default value set by token
+ * initialization or manufacturing, or the PIN has been
+ * expired by the card. */
+#define CKF_SO_PIN_TO_BE_CHANGED 0x00800000
+
+typedef CK_TOKEN_INFO CK_PTR CK_TOKEN_INFO_PTR;
+
+
+/* CK_SESSION_HANDLE is a Cryptoki-assigned value that
+ * identifies a session */
+typedef CK_ULONG CK_SESSION_HANDLE;
+
+typedef CK_SESSION_HANDLE CK_PTR CK_SESSION_HANDLE_PTR;
+
+
+/* CK_USER_TYPE enumerates the types of Cryptoki users */
+/* CK_USER_TYPE has been changed from an enum to a CK_ULONG for
+ * v2.0 */
+typedef CK_ULONG CK_USER_TYPE;
+/* Security Officer */
+#define CKU_SO 0
+/* Normal user */
+#define CKU_USER 1
+/* Context specific (added in v2.20) */
+#define CKU_CONTEXT_SPECIFIC 2
+
+/* CK_STATE enumerates the session states */
+/* CK_STATE has been changed from an enum to a CK_ULONG for
+ * v2.0 */
+typedef CK_ULONG CK_STATE;
+#define CKS_RO_PUBLIC_SESSION 0
+#define CKS_RO_USER_FUNCTIONS 1
+#define CKS_RW_PUBLIC_SESSION 2
+#define CKS_RW_USER_FUNCTIONS 3
+#define CKS_RW_SO_FUNCTIONS 4
+
+
+/* CK_SESSION_INFO provides information about a session */
+typedef struct CK_SESSION_INFO {
+ CK_SLOT_ID slotID;
+ CK_STATE state;
+ CK_FLAGS flags; /* see below */
+
+ /* ulDeviceError was changed from CK_USHORT to CK_ULONG for
+ * v2.0 */
+ CK_ULONG ulDeviceError; /* device-dependent error code */
+} CK_SESSION_INFO;
+
+/* The flags are defined in the following table:
+ * Bit Flag Mask Meaning
+ */
+#define CKF_RW_SESSION 0x00000002 /* session is r/w */
+#define CKF_SERIAL_SESSION 0x00000004 /* no parallel */
+
+typedef CK_SESSION_INFO CK_PTR CK_SESSION_INFO_PTR;
+
+
+/* CK_OBJECT_HANDLE is a token-specific identifier for an
+ * object */
+typedef CK_ULONG CK_OBJECT_HANDLE;
+
+typedef CK_OBJECT_HANDLE CK_PTR CK_OBJECT_HANDLE_PTR;
+
+
+/* CK_OBJECT_CLASS is a value that identifies the classes (or
+ * types) of objects that Cryptoki recognizes. It is defined
+ * as follows: */
+/* CK_OBJECT_CLASS was changed from CK_USHORT to CK_ULONG for
+ * v2.0 */
+typedef CK_ULONG CK_OBJECT_CLASS;
+
+/* The following classes of objects are defined: */
+/* CKO_HW_FEATURE is new for v2.10 */
+/* CKO_DOMAIN_PARAMETERS is new for v2.11 */
+/* CKO_MECHANISM is new for v2.20 */
+#define CKO_DATA 0x00000000
+#define CKO_CERTIFICATE 0x00000001
+#define CKO_PUBLIC_KEY 0x00000002
+#define CKO_PRIVATE_KEY 0x00000003
+#define CKO_SECRET_KEY 0x00000004
+#define CKO_HW_FEATURE 0x00000005
+#define CKO_DOMAIN_PARAMETERS 0x00000006
+#define CKO_MECHANISM 0x00000007
+#define CKO_VENDOR_DEFINED 0x80000000
+
+typedef CK_OBJECT_CLASS CK_PTR CK_OBJECT_CLASS_PTR;
+
+/* CK_HW_FEATURE_TYPE is new for v2.10. CK_HW_FEATURE_TYPE is a
+ * value that identifies the hardware feature type of an object
+ * with CK_OBJECT_CLASS equal to CKO_HW_FEATURE. */
+typedef CK_ULONG CK_HW_FEATURE_TYPE;
+
+/* The following hardware feature types are defined */
+/* CKH_USER_INTERFACE is new for v2.20 */
+#define CKH_MONOTONIC_COUNTER 0x00000001
+#define CKH_CLOCK 0x00000002
+#define CKH_USER_INTERFACE 0x00000003
+#define CKH_VENDOR_DEFINED 0x80000000
+
+/* CK_KEY_TYPE is a value that identifies a key type */
+/* CK_KEY_TYPE was changed from CK_USHORT to CK_ULONG for v2.0 */
+typedef CK_ULONG CK_KEY_TYPE;
+
+/* the following key types are defined: */
+#define CKK_RSA 0x00000000
+#define CKK_DSA 0x00000001
+#define CKK_DH 0x00000002
+
+/* CKK_ECDSA and CKK_KEA are new for v2.0 */
+/* CKK_ECDSA is deprecated in v2.11, CKK_EC is preferred. */
+#define CKK_ECDSA 0x00000003
+#define CKK_EC 0x00000003
+#define CKK_X9_42_DH 0x00000004
+#define CKK_KEA 0x00000005
+
+#define CKK_GENERIC_SECRET 0x00000010
+#define CKK_RC2 0x00000011
+#define CKK_RC4 0x00000012
+#define CKK_DES 0x00000013
+#define CKK_DES2 0x00000014
+#define CKK_DES3 0x00000015
+
+/* all these key types are new for v2.0 */
+#define CKK_CAST 0x00000016
+#define CKK_CAST3 0x00000017
+/* CKK_CAST5 is deprecated in v2.11, CKK_CAST128 is preferred. */
+#define CKK_CAST5 0x00000018
+#define CKK_CAST128 0x00000018
+#define CKK_RC5 0x00000019
+#define CKK_IDEA 0x0000001A
+#define CKK_SKIPJACK 0x0000001B
+#define CKK_BATON 0x0000001C
+#define CKK_JUNIPER 0x0000001D
+#define CKK_CDMF 0x0000001E
+#define CKK_AES 0x0000001F
+
+/* BlowFish and TwoFish are new for v2.20 */
+#define CKK_BLOWFISH 0x00000020
+#define CKK_TWOFISH 0x00000021
+
+#define CKK_VENDOR_DEFINED 0x80000000
+
+
+/* CK_CERTIFICATE_TYPE is a value that identifies a certificate
+ * type */
+/* CK_CERTIFICATE_TYPE was changed from CK_USHORT to CK_ULONG
+ * for v2.0 */
+typedef CK_ULONG CK_CERTIFICATE_TYPE;
+
+/* The following certificate types are defined: */
+/* CKC_X_509_ATTR_CERT is new for v2.10 */
+/* CKC_WTLS is new for v2.20 */
+#define CKC_X_509 0x00000000
+#define CKC_X_509_ATTR_CERT 0x00000001
+#define CKC_WTLS 0x00000002
+#define CKC_VENDOR_DEFINED 0x80000000
+
+
+/* CK_ATTRIBUTE_TYPE is a value that identifies an attribute
+ * type */
+/* CK_ATTRIBUTE_TYPE was changed from CK_USHORT to CK_ULONG for
+ * v2.0 */
+typedef CK_ULONG CK_ATTRIBUTE_TYPE;
+
+/* The CKF_ARRAY_ATTRIBUTE flag identifies an attribute which
+ consists of an array of values. */
+#define CKF_ARRAY_ATTRIBUTE 0x40000000
+
+/* The following attribute types are defined: */
+#define CKA_CLASS 0x00000000
+#define CKA_TOKEN 0x00000001
+#define CKA_PRIVATE 0x00000002
+#define CKA_LABEL 0x00000003
+#define CKA_APPLICATION 0x00000010
+#define CKA_VALUE 0x00000011
+
+/* CKA_OBJECT_ID is new for v2.10 */
+#define CKA_OBJECT_ID 0x00000012
+
+#define CKA_CERTIFICATE_TYPE 0x00000080
+#define CKA_ISSUER 0x00000081
+#define CKA_SERIAL_NUMBER 0x00000082
+
+/* CKA_AC_ISSUER, CKA_OWNER, and CKA_ATTR_TYPES are new
+ * for v2.10 */
+#define CKA_AC_ISSUER 0x00000083
+#define CKA_OWNER 0x00000084
+#define CKA_ATTR_TYPES 0x00000085
+
+/* CKA_TRUSTED is new for v2.11 */
+#define CKA_TRUSTED 0x00000086
+
+/* CKA_CERTIFICATE_CATEGORY ...
+ * CKA_CHECK_VALUE are new for v2.20 */
+#define CKA_CERTIFICATE_CATEGORY 0x00000087
+#define CKA_JAVA_MIDP_SECURITY_DOMAIN 0x00000088
+#define CKA_URL 0x00000089
+#define CKA_HASH_OF_SUBJECT_PUBLIC_KEY 0x0000008A
+#define CKA_HASH_OF_ISSUER_PUBLIC_KEY 0x0000008B
+#define CKA_CHECK_VALUE 0x00000090
+
+#define CKA_KEY_TYPE 0x00000100
+#define CKA_SUBJECT 0x00000101
+#define CKA_ID 0x00000102
+#define CKA_SENSITIVE 0x00000103
+#define CKA_ENCRYPT 0x00000104
+#define CKA_DECRYPT 0x00000105
+#define CKA_WRAP 0x00000106
+#define CKA_UNWRAP 0x00000107
+#define CKA_SIGN 0x00000108
+#define CKA_SIGN_RECOVER 0x00000109
+#define CKA_VERIFY 0x0000010A
+#define CKA_VERIFY_RECOVER 0x0000010B
+#define CKA_DERIVE 0x0000010C
+#define CKA_START_DATE 0x00000110
+#define CKA_END_DATE 0x00000111
+#define CKA_MODULUS 0x00000120
+#define CKA_MODULUS_BITS 0x00000121
+#define CKA_PUBLIC_EXPONENT 0x00000122
+#define CKA_PRIVATE_EXPONENT 0x00000123
+#define CKA_PRIME_1 0x00000124
+#define CKA_PRIME_2 0x00000125
+#define CKA_EXPONENT_1 0x00000126
+#define CKA_EXPONENT_2 0x00000127
+#define CKA_COEFFICIENT 0x00000128
+#define CKA_PRIME 0x00000130
+#define CKA_SUBPRIME 0x00000131
+#define CKA_BASE 0x00000132
+
+/* CKA_PRIME_BITS and CKA_SUB_PRIME_BITS are new for v2.11 */
+#define CKA_PRIME_BITS 0x00000133
+#define CKA_SUBPRIME_BITS 0x00000134
+#define CKA_SUB_PRIME_BITS CKA_SUBPRIME_BITS
+/* (To retain backwards-compatibility) */
+
+#define CKA_VALUE_BITS 0x00000160
+#define CKA_VALUE_LEN 0x00000161
+
+/* CKA_EXTRACTABLE, CKA_LOCAL, CKA_NEVER_EXTRACTABLE,
+ * CKA_ALWAYS_SENSITIVE, CKA_MODIFIABLE, CKA_ECDSA_PARAMS,
+ * and CKA_EC_POINT are new for v2.0 */
+#define CKA_EXTRACTABLE 0x00000162
+#define CKA_LOCAL 0x00000163
+#define CKA_NEVER_EXTRACTABLE 0x00000164
+#define CKA_ALWAYS_SENSITIVE 0x00000165
+
+/* CKA_KEY_GEN_MECHANISM is new for v2.11 */
+#define CKA_KEY_GEN_MECHANISM 0x00000166
+
+#define CKA_MODIFIABLE 0x00000170
+
+/* CKA_ECDSA_PARAMS is deprecated in v2.11,
+ * CKA_EC_PARAMS is preferred. */
+#define CKA_ECDSA_PARAMS 0x00000180
+#define CKA_EC_PARAMS 0x00000180
+
+#define CKA_EC_POINT 0x00000181
+
+/* CKA_SECONDARY_AUTH, CKA_AUTH_PIN_FLAGS,
+ * are new for v2.10. Deprecated in v2.11 and onwards. */
+#define CKA_SECONDARY_AUTH 0x00000200
+#define CKA_AUTH_PIN_FLAGS 0x00000201
+
+/* CKA_ALWAYS_AUTHENTICATE ...
+ * CKA_UNWRAP_TEMPLATE are new for v2.20 */
+#define CKA_ALWAYS_AUTHENTICATE 0x00000202
+
+#define CKA_WRAP_WITH_TRUSTED 0x00000210
+#define CKA_WRAP_TEMPLATE (CKF_ARRAY_ATTRIBUTE|0x00000211)
+#define CKA_UNWRAP_TEMPLATE (CKF_ARRAY_ATTRIBUTE|0x00000212)
+
+/* CKA_HW_FEATURE_TYPE, CKA_RESET_ON_INIT, and CKA_HAS_RESET
+ * are new for v2.10 */
+#define CKA_HW_FEATURE_TYPE 0x00000300
+#define CKA_RESET_ON_INIT 0x00000301
+#define CKA_HAS_RESET 0x00000302
+
+/* The following attributes are new for v2.20 */
+#define CKA_PIXEL_X 0x00000400
+#define CKA_PIXEL_Y 0x00000401
+#define CKA_RESOLUTION 0x00000402
+#define CKA_CHAR_ROWS 0x00000403
+#define CKA_CHAR_COLUMNS 0x00000404
+#define CKA_COLOR 0x00000405
+#define CKA_BITS_PER_PIXEL 0x00000406
+#define CKA_CHAR_SETS 0x00000480
+#define CKA_ENCODING_METHODS 0x00000481
+#define CKA_MIME_TYPES 0x00000482
+#define CKA_MECHANISM_TYPE 0x00000500
+#define CKA_REQUIRED_CMS_ATTRIBUTES 0x00000501
+#define CKA_DEFAULT_CMS_ATTRIBUTES 0x00000502
+#define CKA_SUPPORTED_CMS_ATTRIBUTES 0x00000503
+#define CKA_ALLOWED_MECHANISMS (CKF_ARRAY_ATTRIBUTE|0x00000600)
+
+#define CKA_VENDOR_DEFINED 0x80000000
+
+
+/* CK_ATTRIBUTE is a structure that includes the type, length
+ * and value of an attribute */
+typedef struct CK_ATTRIBUTE {
+ CK_ATTRIBUTE_TYPE type;
+ CK_VOID_PTR pValue;
+
+ /* ulValueLen went from CK_USHORT to CK_ULONG for v2.0 */
+ CK_ULONG ulValueLen; /* in bytes */
+} CK_ATTRIBUTE;
+
+typedef CK_ATTRIBUTE CK_PTR CK_ATTRIBUTE_PTR;
+
+
+/* CK_DATE is a structure that defines a date */
+typedef struct CK_DATE{
+ CK_CHAR year[4]; /* the year ("1900" - "9999") */
+ CK_CHAR month[2]; /* the month ("01" - "12") */
+ CK_CHAR day[2]; /* the day ("01" - "31") */
+} CK_DATE;
+
+
+/* CK_MECHANISM_TYPE is a value that identifies a mechanism
+ * type */
+/* CK_MECHANISM_TYPE was changed from CK_USHORT to CK_ULONG for
+ * v2.0 */
+typedef CK_ULONG CK_MECHANISM_TYPE;
+
+/* the following mechanism types are defined: */
+#define CKM_RSA_PKCS_KEY_PAIR_GEN 0x00000000
+#define CKM_RSA_PKCS 0x00000001
+#define CKM_RSA_9796 0x00000002
+#define CKM_RSA_X_509 0x00000003
+
+/* CKM_MD2_RSA_PKCS, CKM_MD5_RSA_PKCS, and CKM_SHA1_RSA_PKCS
+ * are new for v2.0. They are mechanisms which hash and sign */
+#define CKM_MD2_RSA_PKCS 0x00000004
+#define CKM_MD5_RSA_PKCS 0x00000005
+#define CKM_SHA1_RSA_PKCS 0x00000006
+
+/* CKM_RIPEMD128_RSA_PKCS, CKM_RIPEMD160_RSA_PKCS, and
+ * CKM_RSA_PKCS_OAEP are new for v2.10 */
+#define CKM_RIPEMD128_RSA_PKCS 0x00000007
+#define CKM_RIPEMD160_RSA_PKCS 0x00000008
+#define CKM_RSA_PKCS_OAEP 0x00000009
+
+/* CKM_RSA_X9_31_KEY_PAIR_GEN, CKM_RSA_X9_31, CKM_SHA1_RSA_X9_31,
+ * CKM_RSA_PKCS_PSS, and CKM_SHA1_RSA_PKCS_PSS are new for v2.11 */
+#define CKM_RSA_X9_31_KEY_PAIR_GEN 0x0000000A
+#define CKM_RSA_X9_31 0x0000000B
+#define CKM_SHA1_RSA_X9_31 0x0000000C
+#define CKM_RSA_PKCS_PSS 0x0000000D
+#define CKM_SHA1_RSA_PKCS_PSS 0x0000000E
+
+#define CKM_DSA_KEY_PAIR_GEN 0x00000010
+#define CKM_DSA 0x00000011
+#define CKM_DSA_SHA1 0x00000012
+#define CKM_DH_PKCS_KEY_PAIR_GEN 0x00000020
+#define CKM_DH_PKCS_DERIVE 0x00000021
+
+/* CKM_X9_42_DH_KEY_PAIR_GEN, CKM_X9_42_DH_DERIVE,
+ * CKM_X9_42_DH_HYBRID_DERIVE, and CKM_X9_42_MQV_DERIVE are new for
+ * v2.11 */
+#define CKM_X9_42_DH_KEY_PAIR_GEN 0x00000030
+#define CKM_X9_42_DH_DERIVE 0x00000031
+#define CKM_X9_42_DH_HYBRID_DERIVE 0x00000032
+#define CKM_X9_42_MQV_DERIVE 0x00000033
+
+/* CKM_SHA256/384/512 are new for v2.20 */
+#define CKM_SHA256_RSA_PKCS 0x00000040
+#define CKM_SHA384_RSA_PKCS 0x00000041
+#define CKM_SHA512_RSA_PKCS 0x00000042
+#define CKM_SHA256_RSA_PKCS_PSS 0x00000043
+#define CKM_SHA384_RSA_PKCS_PSS 0x00000044
+#define CKM_SHA512_RSA_PKCS_PSS 0x00000045
+
+#define CKM_RC2_KEY_GEN 0x00000100
+#define CKM_RC2_ECB 0x00000101
+#define CKM_RC2_CBC 0x00000102
+#define CKM_RC2_MAC 0x00000103
+
+/* CKM_RC2_MAC_GENERAL and CKM_RC2_CBC_PAD are new for v2.0 */
+#define CKM_RC2_MAC_GENERAL 0x00000104
+#define CKM_RC2_CBC_PAD 0x00000105
+
+#define CKM_RC4_KEY_GEN 0x00000110
+#define CKM_RC4 0x00000111
+#define CKM_DES_KEY_GEN 0x00000120
+#define CKM_DES_ECB 0x00000121
+#define CKM_DES_CBC 0x00000122
+#define CKM_DES_MAC 0x00000123
+
+/* CKM_DES_MAC_GENERAL and CKM_DES_CBC_PAD are new for v2.0 */
+#define CKM_DES_MAC_GENERAL 0x00000124
+#define CKM_DES_CBC_PAD 0x00000125
+
+#define CKM_DES2_KEY_GEN 0x00000130
+#define CKM_DES3_KEY_GEN 0x00000131
+#define CKM_DES3_ECB 0x00000132
+#define CKM_DES3_CBC 0x00000133
+#define CKM_DES3_MAC 0x00000134
+
+/* CKM_DES3_MAC_GENERAL, CKM_DES3_CBC_PAD, CKM_CDMF_KEY_GEN,
+ * CKM_CDMF_ECB, CKM_CDMF_CBC, CKM_CDMF_MAC,
+ * CKM_CDMF_MAC_GENERAL, and CKM_CDMF_CBC_PAD are new for v2.0 */
+#define CKM_DES3_MAC_GENERAL 0x00000135
+#define CKM_DES3_CBC_PAD 0x00000136
+#define CKM_CDMF_KEY_GEN 0x00000140
+#define CKM_CDMF_ECB 0x00000141
+#define CKM_CDMF_CBC 0x00000142
+#define CKM_CDMF_MAC 0x00000143
+#define CKM_CDMF_MAC_GENERAL 0x00000144
+#define CKM_CDMF_CBC_PAD 0x00000145
+
+/* the following four DES mechanisms are new for v2.20 */
+#define CKM_DES_OFB64 0x00000150
+#define CKM_DES_OFB8 0x00000151
+#define CKM_DES_CFB64 0x00000152
+#define CKM_DES_CFB8 0x00000153
+
+#define CKM_MD2 0x00000200
+
+/* CKM_MD2_HMAC and CKM_MD2_HMAC_GENERAL are new for v2.0 */
+#define CKM_MD2_HMAC 0x00000201
+#define CKM_MD2_HMAC_GENERAL 0x00000202
+
+#define CKM_MD5 0x00000210
+
+/* CKM_MD5_HMAC and CKM_MD5_HMAC_GENERAL are new for v2.0 */
+#define CKM_MD5_HMAC 0x00000211
+#define CKM_MD5_HMAC_GENERAL 0x00000212
+
+#define CKM_SHA_1 0x00000220
+
+/* CKM_SHA_1_HMAC and CKM_SHA_1_HMAC_GENERAL are new for v2.0 */
+#define CKM_SHA_1_HMAC 0x00000221
+#define CKM_SHA_1_HMAC_GENERAL 0x00000222
+
+/* CKM_RIPEMD128, CKM_RIPEMD128_HMAC,
+ * CKM_RIPEMD128_HMAC_GENERAL, CKM_RIPEMD160, CKM_RIPEMD160_HMAC,
+ * and CKM_RIPEMD160_HMAC_GENERAL are new for v2.10 */
+#define CKM_RIPEMD128 0x00000230
+#define CKM_RIPEMD128_HMAC 0x00000231
+#define CKM_RIPEMD128_HMAC_GENERAL 0x00000232
+#define CKM_RIPEMD160 0x00000240
+#define CKM_RIPEMD160_HMAC 0x00000241
+#define CKM_RIPEMD160_HMAC_GENERAL 0x00000242
+
+/* CKM_SHA256/384/512 are new for v2.20 */
+#define CKM_SHA256 0x00000250
+#define CKM_SHA256_HMAC 0x00000251
+#define CKM_SHA256_HMAC_GENERAL 0x00000252
+#define CKM_SHA384 0x00000260
+#define CKM_SHA384_HMAC 0x00000261
+#define CKM_SHA384_HMAC_GENERAL 0x00000262
+#define CKM_SHA512 0x00000270
+#define CKM_SHA512_HMAC 0x00000271
+#define CKM_SHA512_HMAC_GENERAL 0x00000272
+
+/* All of the following mechanisms are new for v2.0 */
+/* Note that CAST128 and CAST5 are the same algorithm */
+#define CKM_CAST_KEY_GEN 0x00000300
+#define CKM_CAST_ECB 0x00000301
+#define CKM_CAST_CBC 0x00000302
+#define CKM_CAST_MAC 0x00000303
+#define CKM_CAST_MAC_GENERAL 0x00000304
+#define CKM_CAST_CBC_PAD 0x00000305
+#define CKM_CAST3_KEY_GEN 0x00000310
+#define CKM_CAST3_ECB 0x00000311
+#define CKM_CAST3_CBC 0x00000312
+#define CKM_CAST3_MAC 0x00000313
+#define CKM_CAST3_MAC_GENERAL 0x00000314
+#define CKM_CAST3_CBC_PAD 0x00000315
+#define CKM_CAST5_KEY_GEN 0x00000320
+#define CKM_CAST128_KEY_GEN 0x00000320
+#define CKM_CAST5_ECB 0x00000321
+#define CKM_CAST128_ECB 0x00000321
+#define CKM_CAST5_CBC 0x00000322
+#define CKM_CAST128_CBC 0x00000322
+#define CKM_CAST5_MAC 0x00000323
+#define CKM_CAST128_MAC 0x00000323
+#define CKM_CAST5_MAC_GENERAL 0x00000324
+#define CKM_CAST128_MAC_GENERAL 0x00000324
+#define CKM_CAST5_CBC_PAD 0x00000325
+#define CKM_CAST128_CBC_PAD 0x00000325
+#define CKM_RC5_KEY_GEN 0x00000330
+#define CKM_RC5_ECB 0x00000331
+#define CKM_RC5_CBC 0x00000332
+#define CKM_RC5_MAC 0x00000333
+#define CKM_RC5_MAC_GENERAL 0x00000334
+#define CKM_RC5_CBC_PAD 0x00000335
+#define CKM_IDEA_KEY_GEN 0x00000340
+#define CKM_IDEA_ECB 0x00000341
+#define CKM_IDEA_CBC 0x00000342
+#define CKM_IDEA_MAC 0x00000343
+#define CKM_IDEA_MAC_GENERAL 0x00000344
+#define CKM_IDEA_CBC_PAD 0x00000345
+#define CKM_GENERIC_SECRET_KEY_GEN 0x00000350
+#define CKM_CONCATENATE_BASE_AND_KEY 0x00000360
+#define CKM_CONCATENATE_BASE_AND_DATA 0x00000362
+#define CKM_CONCATENATE_DATA_AND_BASE 0x00000363
+#define CKM_XOR_BASE_AND_DATA 0x00000364
+#define CKM_EXTRACT_KEY_FROM_KEY 0x00000365
+#define CKM_SSL3_PRE_MASTER_KEY_GEN 0x00000370
+#define CKM_SSL3_MASTER_KEY_DERIVE 0x00000371
+#define CKM_SSL3_KEY_AND_MAC_DERIVE 0x00000372
+
+/* CKM_SSL3_MASTER_KEY_DERIVE_DH, CKM_TLS_PRE_MASTER_KEY_GEN,
+ * CKM_TLS_MASTER_KEY_DERIVE, CKM_TLS_KEY_AND_MAC_DERIVE, and
+ * CKM_TLS_MASTER_KEY_DERIVE_DH are new for v2.11 */
+#define CKM_SSL3_MASTER_KEY_DERIVE_DH 0x00000373
+#define CKM_TLS_PRE_MASTER_KEY_GEN 0x00000374
+#define CKM_TLS_MASTER_KEY_DERIVE 0x00000375
+#define CKM_TLS_KEY_AND_MAC_DERIVE 0x00000376
+#define CKM_TLS_MASTER_KEY_DERIVE_DH 0x00000377
+
+/* CKM_TLS_PRF is new for v2.20 */
+#define CKM_TLS_PRF 0x00000378
+
+#define CKM_SSL3_MD5_MAC 0x00000380
+#define CKM_SSL3_SHA1_MAC 0x00000381
+#define CKM_MD5_KEY_DERIVATION 0x00000390
+#define CKM_MD2_KEY_DERIVATION 0x00000391
+#define CKM_SHA1_KEY_DERIVATION 0x00000392
+
+/* CKM_SHA256/384/512 are new for v2.20 */
+#define CKM_SHA256_KEY_DERIVATION 0x00000393
+#define CKM_SHA384_KEY_DERIVATION 0x00000394
+#define CKM_SHA512_KEY_DERIVATION 0x00000395
+
+#define CKM_PBE_MD2_DES_CBC 0x000003A0
+#define CKM_PBE_MD5_DES_CBC 0x000003A1
+#define CKM_PBE_MD5_CAST_CBC 0x000003A2
+#define CKM_PBE_MD5_CAST3_CBC 0x000003A3
+#define CKM_PBE_MD5_CAST5_CBC 0x000003A4
+#define CKM_PBE_MD5_CAST128_CBC 0x000003A4
+#define CKM_PBE_SHA1_CAST5_CBC 0x000003A5
+#define CKM_PBE_SHA1_CAST128_CBC 0x000003A5
+#define CKM_PBE_SHA1_RC4_128 0x000003A6
+#define CKM_PBE_SHA1_RC4_40 0x000003A7
+#define CKM_PBE_SHA1_DES3_EDE_CBC 0x000003A8
+#define CKM_PBE_SHA1_DES2_EDE_CBC 0x000003A9
+#define CKM_PBE_SHA1_RC2_128_CBC 0x000003AA
+#define CKM_PBE_SHA1_RC2_40_CBC 0x000003AB
+
+/* CKM_PKCS5_PBKD2 is new for v2.10 */
+#define CKM_PKCS5_PBKD2 0x000003B0
+
+#define CKM_PBA_SHA1_WITH_SHA1_HMAC 0x000003C0
+
+/* WTLS mechanisms are new for v2.20 */
+#define CKM_WTLS_PRE_MASTER_KEY_GEN 0x000003D0
+#define CKM_WTLS_MASTER_KEY_DERIVE 0x000003D1
+#define CKM_WTLS_MASTER_KEY_DERIVE_DH_ECC 0x000003D2
+#define CKM_WTLS_PRF 0x000003D3
+#define CKM_WTLS_SERVER_KEY_AND_MAC_DERIVE 0x000003D4
+#define CKM_WTLS_CLIENT_KEY_AND_MAC_DERIVE 0x000003D5
+
+#define CKM_KEY_WRAP_LYNKS 0x00000400
+#define CKM_KEY_WRAP_SET_OAEP 0x00000401
+
+/* CKM_CMS_SIG is new for v2.20 */
+#define CKM_CMS_SIG 0x00000500
+
+/* Fortezza mechanisms */
+#define CKM_SKIPJACK_KEY_GEN 0x00001000
+#define CKM_SKIPJACK_ECB64 0x00001001
+#define CKM_SKIPJACK_CBC64 0x00001002
+#define CKM_SKIPJACK_OFB64 0x00001003
+#define CKM_SKIPJACK_CFB64 0x00001004
+#define CKM_SKIPJACK_CFB32 0x00001005
+#define CKM_SKIPJACK_CFB16 0x00001006
+#define CKM_SKIPJACK_CFB8 0x00001007
+#define CKM_SKIPJACK_WRAP 0x00001008
+#define CKM_SKIPJACK_PRIVATE_WRAP 0x00001009
+#define CKM_SKIPJACK_RELAYX 0x0000100a
+#define CKM_KEA_KEY_PAIR_GEN 0x00001010
+#define CKM_KEA_KEY_DERIVE 0x00001011
+#define CKM_FORTEZZA_TIMESTAMP 0x00001020
+#define CKM_BATON_KEY_GEN 0x00001030
+#define CKM_BATON_ECB128 0x00001031
+#define CKM_BATON_ECB96 0x00001032
+#define CKM_BATON_CBC128 0x00001033
+#define CKM_BATON_COUNTER 0x00001034
+#define CKM_BATON_SHUFFLE 0x00001035
+#define CKM_BATON_WRAP 0x00001036
+
+/* CKM_ECDSA_KEY_PAIR_GEN is deprecated in v2.11,
+ * CKM_EC_KEY_PAIR_GEN is preferred */
+#define CKM_ECDSA_KEY_PAIR_GEN 0x00001040
+#define CKM_EC_KEY_PAIR_GEN 0x00001040
+
+#define CKM_ECDSA 0x00001041
+#define CKM_ECDSA_SHA1 0x00001042
+
+/* CKM_ECDH1_DERIVE, CKM_ECDH1_COFACTOR_DERIVE, and CKM_ECMQV_DERIVE
+ * are new for v2.11 */
+#define CKM_ECDH1_DERIVE 0x00001050
+#define CKM_ECDH1_COFACTOR_DERIVE 0x00001051
+#define CKM_ECMQV_DERIVE 0x00001052
+
+#define CKM_JUNIPER_KEY_GEN 0x00001060
+#define CKM_JUNIPER_ECB128 0x00001061
+#define CKM_JUNIPER_CBC128 0x00001062
+#define CKM_JUNIPER_COUNTER 0x00001063
+#define CKM_JUNIPER_SHUFFLE 0x00001064
+#define CKM_JUNIPER_WRAP 0x00001065
+#define CKM_FASTHASH 0x00001070
+
+/* CKM_AES_KEY_GEN, CKM_AES_ECB, CKM_AES_CBC, CKM_AES_MAC,
+ * CKM_AES_MAC_GENERAL, CKM_AES_CBC_PAD, CKM_DSA_PARAMETER_GEN,
+ * CKM_DH_PKCS_PARAMETER_GEN, and CKM_X9_42_DH_PARAMETER_GEN are
+ * new for v2.11 */
+#define CKM_AES_KEY_GEN 0x00001080
+#define CKM_AES_ECB 0x00001081
+#define CKM_AES_CBC 0x00001082
+#define CKM_AES_MAC 0x00001083
+#define CKM_AES_MAC_GENERAL 0x00001084
+#define CKM_AES_CBC_PAD 0x00001085
+
+/* BlowFish and TwoFish are new for v2.20 */
+#define CKM_BLOWFISH_KEY_GEN 0x00001090
+#define CKM_BLOWFISH_CBC 0x00001091
+#define CKM_TWOFISH_KEY_GEN 0x00001092
+#define CKM_TWOFISH_CBC 0x00001093
+
+
+/* CKM_xxx_ENCRYPT_DATA mechanisms are new for v2.20 */
+#define CKM_DES_ECB_ENCRYPT_DATA 0x00001100
+#define CKM_DES_CBC_ENCRYPT_DATA 0x00001101
+#define CKM_DES3_ECB_ENCRYPT_DATA 0x00001102
+#define CKM_DES3_CBC_ENCRYPT_DATA 0x00001103
+#define CKM_AES_ECB_ENCRYPT_DATA 0x00001104
+#define CKM_AES_CBC_ENCRYPT_DATA 0x00001105
+
+#define CKM_DSA_PARAMETER_GEN 0x00002000
+#define CKM_DH_PKCS_PARAMETER_GEN 0x00002001
+#define CKM_X9_42_DH_PARAMETER_GEN 0x00002002
+
+#define CKM_VENDOR_DEFINED 0x80000000
+
+typedef CK_MECHANISM_TYPE CK_PTR CK_MECHANISM_TYPE_PTR;
+
+
+/* CK_MECHANISM is a structure that specifies a particular
+ * mechanism */
+typedef struct CK_MECHANISM {
+ CK_MECHANISM_TYPE mechanism;
+ CK_VOID_PTR pParameter;
+
+ /* ulParameterLen was changed from CK_USHORT to CK_ULONG for
+ * v2.0 */
+ CK_ULONG ulParameterLen; /* in bytes */
+} CK_MECHANISM;
+
+typedef CK_MECHANISM CK_PTR CK_MECHANISM_PTR;
+
+
+/* CK_MECHANISM_INFO provides information about a particular
+ * mechanism */
+typedef struct CK_MECHANISM_INFO {
+ CK_ULONG ulMinKeySize;
+ CK_ULONG ulMaxKeySize;
+ CK_FLAGS flags;
+} CK_MECHANISM_INFO;
+
+/* The flags are defined as follows:
+ * Bit Flag Mask Meaning */
+#define CKF_HW 0x00000001 /* performed by HW */
+
+/* The flags CKF_ENCRYPT, CKF_DECRYPT, CKF_DIGEST, CKF_SIGN,
+ * CKG_SIGN_RECOVER, CKF_VERIFY, CKF_VERIFY_RECOVER,
+ * CKF_GENERATE, CKF_GENERATE_KEY_PAIR, CKF_WRAP, CKF_UNWRAP,
+ * and CKF_DERIVE are new for v2.0. They specify whether or not
+ * a mechanism can be used for a particular task */
+#define CKF_ENCRYPT 0x00000100
+#define CKF_DECRYPT 0x00000200
+#define CKF_DIGEST 0x00000400
+#define CKF_SIGN 0x00000800
+#define CKF_SIGN_RECOVER 0x00001000
+#define CKF_VERIFY 0x00002000
+#define CKF_VERIFY_RECOVER 0x00004000
+#define CKF_GENERATE 0x00008000
+#define CKF_GENERATE_KEY_PAIR 0x00010000
+#define CKF_WRAP 0x00020000
+#define CKF_UNWRAP 0x00040000
+#define CKF_DERIVE 0x00080000
+
+/* CKF_EC_F_P, CKF_EC_F_2M, CKF_EC_ECPARAMETERS, CKF_EC_NAMEDCURVE,
+ * CKF_EC_UNCOMPRESS, and CKF_EC_COMPRESS are new for v2.11. They
+ * describe a token's EC capabilities not available in mechanism
+ * information. */
+#define CKF_EC_F_P 0x00100000
+#define CKF_EC_F_2M 0x00200000
+#define CKF_EC_ECPARAMETERS 0x00400000
+#define CKF_EC_NAMEDCURVE 0x00800000
+#define CKF_EC_UNCOMPRESS 0x01000000
+#define CKF_EC_COMPRESS 0x02000000
+
+#define CKF_EXTENSION 0x80000000 /* FALSE for this version */
+
+typedef CK_MECHANISM_INFO CK_PTR CK_MECHANISM_INFO_PTR;
+
+
+/* CK_RV is a value that identifies the return value of a
+ * Cryptoki function */
+/* CK_RV was changed from CK_USHORT to CK_ULONG for v2.0 */
+typedef CK_ULONG CK_RV;
+
+#define CKR_OK 0x00000000
+#define CKR_CANCEL 0x00000001
+#define CKR_HOST_MEMORY 0x00000002
+#define CKR_SLOT_ID_INVALID 0x00000003
+
+/* CKR_FLAGS_INVALID was removed for v2.0 */
+
+/* CKR_GENERAL_ERROR and CKR_FUNCTION_FAILED are new for v2.0 */
+#define CKR_GENERAL_ERROR 0x00000005
+#define CKR_FUNCTION_FAILED 0x00000006
+
+/* CKR_ARGUMENTS_BAD, CKR_NO_EVENT, CKR_NEED_TO_CREATE_THREADS,
+ * and CKR_CANT_LOCK are new for v2.01 */
+#define CKR_ARGUMENTS_BAD 0x00000007
+#define CKR_NO_EVENT 0x00000008
+#define CKR_NEED_TO_CREATE_THREADS 0x00000009
+#define CKR_CANT_LOCK 0x0000000A
+
+#define CKR_ATTRIBUTE_READ_ONLY 0x00000010
+#define CKR_ATTRIBUTE_SENSITIVE 0x00000011
+#define CKR_ATTRIBUTE_TYPE_INVALID 0x00000012
+#define CKR_ATTRIBUTE_VALUE_INVALID 0x00000013
+#define CKR_DATA_INVALID 0x00000020
+#define CKR_DATA_LEN_RANGE 0x00000021
+#define CKR_DEVICE_ERROR 0x00000030
+#define CKR_DEVICE_MEMORY 0x00000031
+#define CKR_DEVICE_REMOVED 0x00000032
+#define CKR_ENCRYPTED_DATA_INVALID 0x00000040
+#define CKR_ENCRYPTED_DATA_LEN_RANGE 0x00000041
+#define CKR_FUNCTION_CANCELED 0x00000050
+#define CKR_FUNCTION_NOT_PARALLEL 0x00000051
+
+/* CKR_FUNCTION_NOT_SUPPORTED is new for v2.0 */
+#define CKR_FUNCTION_NOT_SUPPORTED 0x00000054
+
+#define CKR_KEY_HANDLE_INVALID 0x00000060
+
+/* CKR_KEY_SENSITIVE was removed for v2.0 */
+
+#define CKR_KEY_SIZE_RANGE 0x00000062
+#define CKR_KEY_TYPE_INCONSISTENT 0x00000063
+
+/* CKR_KEY_NOT_NEEDED, CKR_KEY_CHANGED, CKR_KEY_NEEDED,
+ * CKR_KEY_INDIGESTIBLE, CKR_KEY_FUNCTION_NOT_PERMITTED,
+ * CKR_KEY_NOT_WRAPPABLE, and CKR_KEY_UNEXTRACTABLE are new for
+ * v2.0 */
+#define CKR_KEY_NOT_NEEDED 0x00000064
+#define CKR_KEY_CHANGED 0x00000065
+#define CKR_KEY_NEEDED 0x00000066
+#define CKR_KEY_INDIGESTIBLE 0x00000067
+#define CKR_KEY_FUNCTION_NOT_PERMITTED 0x00000068
+#define CKR_KEY_NOT_WRAPPABLE 0x00000069
+#define CKR_KEY_UNEXTRACTABLE 0x0000006A
+
+#define CKR_MECHANISM_INVALID 0x00000070
+#define CKR_MECHANISM_PARAM_INVALID 0x00000071
+
+/* CKR_OBJECT_CLASS_INCONSISTENT and CKR_OBJECT_CLASS_INVALID
+ * were removed for v2.0 */
+#define CKR_OBJECT_HANDLE_INVALID 0x00000082
+#define CKR_OPERATION_ACTIVE 0x00000090
+#define CKR_OPERATION_NOT_INITIALIZED 0x00000091
+#define CKR_PIN_INCORRECT 0x000000A0
+#define CKR_PIN_INVALID 0x000000A1
+#define CKR_PIN_LEN_RANGE 0x000000A2
+
+/* CKR_PIN_EXPIRED and CKR_PIN_LOCKED are new for v2.0 */
+#define CKR_PIN_EXPIRED 0x000000A3
+#define CKR_PIN_LOCKED 0x000000A4
+
+#define CKR_SESSION_CLOSED 0x000000B0
+#define CKR_SESSION_COUNT 0x000000B1
+#define CKR_SESSION_HANDLE_INVALID 0x000000B3
+#define CKR_SESSION_PARALLEL_NOT_SUPPORTED 0x000000B4
+#define CKR_SESSION_READ_ONLY 0x000000B5
+#define CKR_SESSION_EXISTS 0x000000B6
+
+/* CKR_SESSION_READ_ONLY_EXISTS and
+ * CKR_SESSION_READ_WRITE_SO_EXISTS are new for v2.0 */
+#define CKR_SESSION_READ_ONLY_EXISTS 0x000000B7
+#define CKR_SESSION_READ_WRITE_SO_EXISTS 0x000000B8
+
+#define CKR_SIGNATURE_INVALID 0x000000C0
+#define CKR_SIGNATURE_LEN_RANGE 0x000000C1
+#define CKR_TEMPLATE_INCOMPLETE 0x000000D0
+#define CKR_TEMPLATE_INCONSISTENT 0x000000D1
+#define CKR_TOKEN_NOT_PRESENT 0x000000E0
+#define CKR_TOKEN_NOT_RECOGNIZED 0x000000E1
+#define CKR_TOKEN_WRITE_PROTECTED 0x000000E2
+#define CKR_UNWRAPPING_KEY_HANDLE_INVALID 0x000000F0
+#define CKR_UNWRAPPING_KEY_SIZE_RANGE 0x000000F1
+#define CKR_UNWRAPPING_KEY_TYPE_INCONSISTENT 0x000000F2
+#define CKR_USER_ALREADY_LOGGED_IN 0x00000100
+#define CKR_USER_NOT_LOGGED_IN 0x00000101
+#define CKR_USER_PIN_NOT_INITIALIZED 0x00000102
+#define CKR_USER_TYPE_INVALID 0x00000103
+
+/* CKR_USER_ANOTHER_ALREADY_LOGGED_IN and CKR_USER_TOO_MANY_TYPES
+ * are new to v2.01 */
+#define CKR_USER_ANOTHER_ALREADY_LOGGED_IN 0x00000104
+#define CKR_USER_TOO_MANY_TYPES 0x00000105
+
+#define CKR_WRAPPED_KEY_INVALID 0x00000110
+#define CKR_WRAPPED_KEY_LEN_RANGE 0x00000112
+#define CKR_WRAPPING_KEY_HANDLE_INVALID 0x00000113
+#define CKR_WRAPPING_KEY_SIZE_RANGE 0x00000114
+#define CKR_WRAPPING_KEY_TYPE_INCONSISTENT 0x00000115
+#define CKR_RANDOM_SEED_NOT_SUPPORTED 0x00000120
+
+/* These are new to v2.0 */
+#define CKR_RANDOM_NO_RNG 0x00000121
+
+/* These are new to v2.11 */
+#define CKR_DOMAIN_PARAMS_INVALID 0x00000130
+
+/* These are new to v2.0 */
+#define CKR_BUFFER_TOO_SMALL 0x00000150
+#define CKR_SAVED_STATE_INVALID 0x00000160
+#define CKR_INFORMATION_SENSITIVE 0x00000170
+#define CKR_STATE_UNSAVEABLE 0x00000180
+
+/* These are new to v2.01 */
+#define CKR_CRYPTOKI_NOT_INITIALIZED 0x00000190
+#define CKR_CRYPTOKI_ALREADY_INITIALIZED 0x00000191
+#define CKR_MUTEX_BAD 0x000001A0
+#define CKR_MUTEX_NOT_LOCKED 0x000001A1
+
+/* This is new to v2.20 */
+#define CKR_FUNCTION_REJECTED 0x00000200
+
+#define CKR_VENDOR_DEFINED 0x80000000
+
+
+/* CK_NOTIFY is an application callback that processes events */
+typedef CK_CALLBACK_FUNCTION(CK_RV, CK_NOTIFY)(
+ CK_SESSION_HANDLE hSession, /* the session's handle */
+ CK_NOTIFICATION event,
+ CK_VOID_PTR pApplication /* passed to C_OpenSession */
+);
+
+
+/* CK_FUNCTION_LIST is a structure holding a Cryptoki spec
+ * version and pointers of appropriate types to all the
+ * Cryptoki functions */
+/* CK_FUNCTION_LIST is new for v2.0 */
+typedef struct CK_FUNCTION_LIST CK_FUNCTION_LIST;
+
+typedef CK_FUNCTION_LIST CK_PTR CK_FUNCTION_LIST_PTR;
+
+typedef CK_FUNCTION_LIST_PTR CK_PTR CK_FUNCTION_LIST_PTR_PTR;
+
+
+/* CK_CREATEMUTEX is an application callback for creating a
+ * mutex object */
+typedef CK_CALLBACK_FUNCTION(CK_RV, CK_CREATEMUTEX)(
+ CK_VOID_PTR_PTR ppMutex /* location to receive ptr to mutex */
+);
+
+
+/* CK_DESTROYMUTEX is an application callback for destroying a
+ * mutex object */
+typedef CK_CALLBACK_FUNCTION(CK_RV, CK_DESTROYMUTEX)(
+ CK_VOID_PTR pMutex /* pointer to mutex */
+);
+
+
+/* CK_LOCKMUTEX is an application callback for locking a mutex */
+typedef CK_CALLBACK_FUNCTION(CK_RV, CK_LOCKMUTEX)(
+ CK_VOID_PTR pMutex /* pointer to mutex */
+);
+
+
+/* CK_UNLOCKMUTEX is an application callback for unlocking a
+ * mutex */
+typedef CK_CALLBACK_FUNCTION(CK_RV, CK_UNLOCKMUTEX)(
+ CK_VOID_PTR pMutex /* pointer to mutex */
+);
+
+
+/* CK_C_INITIALIZE_ARGS provides the optional arguments to
+ * C_Initialize */
+typedef struct CK_C_INITIALIZE_ARGS {
+ CK_CREATEMUTEX CreateMutex;
+ CK_DESTROYMUTEX DestroyMutex;
+ CK_LOCKMUTEX LockMutex;
+ CK_UNLOCKMUTEX UnlockMutex;
+ CK_FLAGS flags;
+ CK_VOID_PTR pReserved;
+} CK_C_INITIALIZE_ARGS;
+
+/* flags: bit flags that provide capabilities of the slot
+ * Bit Flag Mask Meaning
+ */
+#define CKF_LIBRARY_CANT_CREATE_OS_THREADS 0x00000001
+#define CKF_OS_LOCKING_OK 0x00000002
+
+typedef CK_C_INITIALIZE_ARGS CK_PTR CK_C_INITIALIZE_ARGS_PTR;
+
+
+/* additional flags for parameters to functions */
+
+/* CKF_DONT_BLOCK is for the function C_WaitForSlotEvent */
+#define CKF_DONT_BLOCK 1
+
+/* CK_RSA_PKCS_OAEP_MGF_TYPE is new for v2.10.
+ * CK_RSA_PKCS_OAEP_MGF_TYPE is used to indicate the Message
+ * Generation Function (MGF) applied to a message block when
+ * formatting a message block for the PKCS #1 OAEP encryption
+ * scheme. */
+typedef CK_ULONG CK_RSA_PKCS_MGF_TYPE;
+
+typedef CK_RSA_PKCS_MGF_TYPE CK_PTR CK_RSA_PKCS_MGF_TYPE_PTR;
+
+/* The following MGFs are defined */
+/* CKG_MGF1_SHA256, CKG_MGF1_SHA384, and CKG_MGF1_SHA512
+ * are new for v2.20 */
+#define CKG_MGF1_SHA1 0x00000001
+#define CKG_MGF1_SHA256 0x00000002
+#define CKG_MGF1_SHA384 0x00000003
+#define CKG_MGF1_SHA512 0x00000004
+
+/* CK_RSA_PKCS_OAEP_SOURCE_TYPE is new for v2.10.
+ * CK_RSA_PKCS_OAEP_SOURCE_TYPE is used to indicate the source
+ * of the encoding parameter when formatting a message block
+ * for the PKCS #1 OAEP encryption scheme. */
+typedef CK_ULONG CK_RSA_PKCS_OAEP_SOURCE_TYPE;
+
+typedef CK_RSA_PKCS_OAEP_SOURCE_TYPE CK_PTR CK_RSA_PKCS_OAEP_SOURCE_TYPE_PTR;
+
+/* The following encoding parameter sources are defined */
+#define CKZ_DATA_SPECIFIED 0x00000001
+
+/* CK_RSA_PKCS_OAEP_PARAMS is new for v2.10.
+ * CK_RSA_PKCS_OAEP_PARAMS provides the parameters to the
+ * CKM_RSA_PKCS_OAEP mechanism. */
+typedef struct CK_RSA_PKCS_OAEP_PARAMS {
+ CK_MECHANISM_TYPE hashAlg;
+ CK_RSA_PKCS_MGF_TYPE mgf;
+ CK_RSA_PKCS_OAEP_SOURCE_TYPE source;
+ CK_VOID_PTR pSourceData;
+ CK_ULONG ulSourceDataLen;
+} CK_RSA_PKCS_OAEP_PARAMS;
+
+typedef CK_RSA_PKCS_OAEP_PARAMS CK_PTR CK_RSA_PKCS_OAEP_PARAMS_PTR;
+
+/* CK_RSA_PKCS_PSS_PARAMS is new for v2.11.
+ * CK_RSA_PKCS_PSS_PARAMS provides the parameters to the
+ * CKM_RSA_PKCS_PSS mechanism(s). */
+typedef struct CK_RSA_PKCS_PSS_PARAMS {
+ CK_MECHANISM_TYPE hashAlg;
+ CK_RSA_PKCS_MGF_TYPE mgf;
+ CK_ULONG sLen;
+} CK_RSA_PKCS_PSS_PARAMS;
+
+typedef CK_RSA_PKCS_PSS_PARAMS CK_PTR CK_RSA_PKCS_PSS_PARAMS_PTR;
+
+/* CK_EC_KDF_TYPE is new for v2.11. */
+typedef CK_ULONG CK_EC_KDF_TYPE;
+
+/* The following EC Key Derivation Functions are defined */
+#define CKD_NULL 0x00000001
+#define CKD_SHA1_KDF 0x00000002
+
+/* CK_ECDH1_DERIVE_PARAMS is new for v2.11.
+ * CK_ECDH1_DERIVE_PARAMS provides the parameters to the
+ * CKM_ECDH1_DERIVE and CKM_ECDH1_COFACTOR_DERIVE mechanisms,
+ * where each party contributes one key pair.
+ */
+typedef struct CK_ECDH1_DERIVE_PARAMS {
+ CK_EC_KDF_TYPE kdf;
+ CK_ULONG ulSharedDataLen;
+ CK_BYTE_PTR pSharedData;
+ CK_ULONG ulPublicDataLen;
+ CK_BYTE_PTR pPublicData;
+} CK_ECDH1_DERIVE_PARAMS;
+
+typedef CK_ECDH1_DERIVE_PARAMS CK_PTR CK_ECDH1_DERIVE_PARAMS_PTR;
+
+
+/* CK_ECDH2_DERIVE_PARAMS is new for v2.11.
+ * CK_ECDH2_DERIVE_PARAMS provides the parameters to the
+ * CKM_ECMQV_DERIVE mechanism, where each party contributes two key pairs. */
+typedef struct CK_ECDH2_DERIVE_PARAMS {
+ CK_EC_KDF_TYPE kdf;
+ CK_ULONG ulSharedDataLen;
+ CK_BYTE_PTR pSharedData;
+ CK_ULONG ulPublicDataLen;
+ CK_BYTE_PTR pPublicData;
+ CK_ULONG ulPrivateDataLen;
+ CK_OBJECT_HANDLE hPrivateData;
+ CK_ULONG ulPublicDataLen2;
+ CK_BYTE_PTR pPublicData2;
+} CK_ECDH2_DERIVE_PARAMS;
+
+typedef CK_ECDH2_DERIVE_PARAMS CK_PTR CK_ECDH2_DERIVE_PARAMS_PTR;
+
+typedef struct CK_ECMQV_DERIVE_PARAMS {
+ CK_EC_KDF_TYPE kdf;
+ CK_ULONG ulSharedDataLen;
+ CK_BYTE_PTR pSharedData;
+ CK_ULONG ulPublicDataLen;
+ CK_BYTE_PTR pPublicData;
+ CK_ULONG ulPrivateDataLen;
+ CK_OBJECT_HANDLE hPrivateData;
+ CK_ULONG ulPublicDataLen2;
+ CK_BYTE_PTR pPublicData2;
+ CK_OBJECT_HANDLE publicKey;
+} CK_ECMQV_DERIVE_PARAMS;
+
+typedef CK_ECMQV_DERIVE_PARAMS CK_PTR CK_ECMQV_DERIVE_PARAMS_PTR;
+
+/* Typedefs and defines for the CKM_X9_42_DH_KEY_PAIR_GEN and the
+ * CKM_X9_42_DH_PARAMETER_GEN mechanisms (new for PKCS #11 v2.11) */
+typedef CK_ULONG CK_X9_42_DH_KDF_TYPE;
+typedef CK_X9_42_DH_KDF_TYPE CK_PTR CK_X9_42_DH_KDF_TYPE_PTR;
+
+/* The following X9.42 DH key derivation functions are defined
+ (besides CKD_NULL already defined : */
+#define CKD_SHA1_KDF_ASN1 0x00000003
+#define CKD_SHA1_KDF_CONCATENATE 0x00000004
+
+/* CK_X9_42_DH1_DERIVE_PARAMS is new for v2.11.
+ * CK_X9_42_DH1_DERIVE_PARAMS provides the parameters to the
+ * CKM_X9_42_DH_DERIVE key derivation mechanism, where each party
+ * contributes one key pair */
+typedef struct CK_X9_42_DH1_DERIVE_PARAMS {
+ CK_X9_42_DH_KDF_TYPE kdf;
+ CK_ULONG ulOtherInfoLen;
+ CK_BYTE_PTR pOtherInfo;
+ CK_ULONG ulPublicDataLen;
+ CK_BYTE_PTR pPublicData;
+} CK_X9_42_DH1_DERIVE_PARAMS;
+
+typedef struct CK_X9_42_DH1_DERIVE_PARAMS CK_PTR CK_X9_42_DH1_DERIVE_PARAMS_PTR;
+
+/* CK_X9_42_DH2_DERIVE_PARAMS is new for v2.11.
+ * CK_X9_42_DH2_DERIVE_PARAMS provides the parameters to the
+ * CKM_X9_42_DH_HYBRID_DERIVE and CKM_X9_42_MQV_DERIVE key derivation
+ * mechanisms, where each party contributes two key pairs */
+typedef struct CK_X9_42_DH2_DERIVE_PARAMS {
+ CK_X9_42_DH_KDF_TYPE kdf;
+ CK_ULONG ulOtherInfoLen;
+ CK_BYTE_PTR pOtherInfo;
+ CK_ULONG ulPublicDataLen;
+ CK_BYTE_PTR pPublicData;
+ CK_ULONG ulPrivateDataLen;
+ CK_OBJECT_HANDLE hPrivateData;
+ CK_ULONG ulPublicDataLen2;
+ CK_BYTE_PTR pPublicData2;
+} CK_X9_42_DH2_DERIVE_PARAMS;
+
+typedef CK_X9_42_DH2_DERIVE_PARAMS CK_PTR CK_X9_42_DH2_DERIVE_PARAMS_PTR;
+
+typedef struct CK_X9_42_MQV_DERIVE_PARAMS {
+ CK_X9_42_DH_KDF_TYPE kdf;
+ CK_ULONG ulOtherInfoLen;
+ CK_BYTE_PTR pOtherInfo;
+ CK_ULONG ulPublicDataLen;
+ CK_BYTE_PTR pPublicData;
+ CK_ULONG ulPrivateDataLen;
+ CK_OBJECT_HANDLE hPrivateData;
+ CK_ULONG ulPublicDataLen2;
+ CK_BYTE_PTR pPublicData2;
+ CK_OBJECT_HANDLE publicKey;
+} CK_X9_42_MQV_DERIVE_PARAMS;
+
+typedef CK_X9_42_MQV_DERIVE_PARAMS CK_PTR CK_X9_42_MQV_DERIVE_PARAMS_PTR;
+
+/* CK_KEA_DERIVE_PARAMS provides the parameters to the
+ * CKM_KEA_DERIVE mechanism */
+/* CK_KEA_DERIVE_PARAMS is new for v2.0 */
+typedef struct CK_KEA_DERIVE_PARAMS {
+ CK_BBOOL isSender;
+ CK_ULONG ulRandomLen;
+ CK_BYTE_PTR pRandomA;
+ CK_BYTE_PTR pRandomB;
+ CK_ULONG ulPublicDataLen;
+ CK_BYTE_PTR pPublicData;
+} CK_KEA_DERIVE_PARAMS;
+
+typedef CK_KEA_DERIVE_PARAMS CK_PTR CK_KEA_DERIVE_PARAMS_PTR;
+
+
+/* CK_RC2_PARAMS provides the parameters to the CKM_RC2_ECB and
+ * CKM_RC2_MAC mechanisms. An instance of CK_RC2_PARAMS just
+ * holds the effective keysize */
+typedef CK_ULONG CK_RC2_PARAMS;
+
+typedef CK_RC2_PARAMS CK_PTR CK_RC2_PARAMS_PTR;
+
+
+/* CK_RC2_CBC_PARAMS provides the parameters to the CKM_RC2_CBC
+ * mechanism */
+typedef struct CK_RC2_CBC_PARAMS {
+ /* ulEffectiveBits was changed from CK_USHORT to CK_ULONG for
+ * v2.0 */
+ CK_ULONG ulEffectiveBits; /* effective bits (1-1024) */
+
+ CK_BYTE iv[8]; /* IV for CBC mode */
+} CK_RC2_CBC_PARAMS;
+
+typedef CK_RC2_CBC_PARAMS CK_PTR CK_RC2_CBC_PARAMS_PTR;
+
+
+/* CK_RC2_MAC_GENERAL_PARAMS provides the parameters for the
+ * CKM_RC2_MAC_GENERAL mechanism */
+/* CK_RC2_MAC_GENERAL_PARAMS is new for v2.0 */
+typedef struct CK_RC2_MAC_GENERAL_PARAMS {
+ CK_ULONG ulEffectiveBits; /* effective bits (1-1024) */
+ CK_ULONG ulMacLength; /* Length of MAC in bytes */
+} CK_RC2_MAC_GENERAL_PARAMS;
+
+typedef CK_RC2_MAC_GENERAL_PARAMS CK_PTR \
+ CK_RC2_MAC_GENERAL_PARAMS_PTR;
+
+
+/* CK_RC5_PARAMS provides the parameters to the CKM_RC5_ECB and
+ * CKM_RC5_MAC mechanisms */
+/* CK_RC5_PARAMS is new for v2.0 */
+typedef struct CK_RC5_PARAMS {
+ CK_ULONG ulWordsize; /* wordsize in bits */
+ CK_ULONG ulRounds; /* number of rounds */
+} CK_RC5_PARAMS;
+
+typedef CK_RC5_PARAMS CK_PTR CK_RC5_PARAMS_PTR;
+
+
+/* CK_RC5_CBC_PARAMS provides the parameters to the CKM_RC5_CBC
+ * mechanism */
+/* CK_RC5_CBC_PARAMS is new for v2.0 */
+typedef struct CK_RC5_CBC_PARAMS {
+ CK_ULONG ulWordsize; /* wordsize in bits */
+ CK_ULONG ulRounds; /* number of rounds */
+ CK_BYTE_PTR pIv; /* pointer to IV */
+ CK_ULONG ulIvLen; /* length of IV in bytes */
+} CK_RC5_CBC_PARAMS;
+
+typedef CK_RC5_CBC_PARAMS CK_PTR CK_RC5_CBC_PARAMS_PTR;
+
+
+/* CK_RC5_MAC_GENERAL_PARAMS provides the parameters for the
+ * CKM_RC5_MAC_GENERAL mechanism */
+/* CK_RC5_MAC_GENERAL_PARAMS is new for v2.0 */
+typedef struct CK_RC5_MAC_GENERAL_PARAMS {
+ CK_ULONG ulWordsize; /* wordsize in bits */
+ CK_ULONG ulRounds; /* number of rounds */
+ CK_ULONG ulMacLength; /* Length of MAC in bytes */
+} CK_RC5_MAC_GENERAL_PARAMS;
+
+typedef CK_RC5_MAC_GENERAL_PARAMS CK_PTR \
+ CK_RC5_MAC_GENERAL_PARAMS_PTR;
+
+
+/* CK_MAC_GENERAL_PARAMS provides the parameters to most block
+ * ciphers' MAC_GENERAL mechanisms. Its value is the length of
+ * the MAC */
+/* CK_MAC_GENERAL_PARAMS is new for v2.0 */
+typedef CK_ULONG CK_MAC_GENERAL_PARAMS;
+
+typedef CK_MAC_GENERAL_PARAMS CK_PTR CK_MAC_GENERAL_PARAMS_PTR;
+
+/* CK_DES/AES_ECB/CBC_ENCRYPT_DATA_PARAMS are new for v2.20 */
+typedef struct CK_DES_CBC_ENCRYPT_DATA_PARAMS {
+ CK_BYTE iv[8];
+ CK_BYTE_PTR pData;
+ CK_ULONG length;
+} CK_DES_CBC_ENCRYPT_DATA_PARAMS;
+
+typedef CK_DES_CBC_ENCRYPT_DATA_PARAMS CK_PTR CK_DES_CBC_ENCRYPT_DATA_PARAMS_PTR;
+
+typedef struct CK_AES_CBC_ENCRYPT_DATA_PARAMS {
+ CK_BYTE iv[16];
+ CK_BYTE_PTR pData;
+ CK_ULONG length;
+} CK_AES_CBC_ENCRYPT_DATA_PARAMS;
+
+typedef CK_AES_CBC_ENCRYPT_DATA_PARAMS CK_PTR CK_AES_CBC_ENCRYPT_DATA_PARAMS_PTR;
+
+/* CK_SKIPJACK_PRIVATE_WRAP_PARAMS provides the parameters to the
+ * CKM_SKIPJACK_PRIVATE_WRAP mechanism */
+/* CK_SKIPJACK_PRIVATE_WRAP_PARAMS is new for v2.0 */
+typedef struct CK_SKIPJACK_PRIVATE_WRAP_PARAMS {
+ CK_ULONG ulPasswordLen;
+ CK_BYTE_PTR pPassword;
+ CK_ULONG ulPublicDataLen;
+ CK_BYTE_PTR pPublicData;
+ CK_ULONG ulPAndGLen;
+ CK_ULONG ulQLen;
+ CK_ULONG ulRandomLen;
+ CK_BYTE_PTR pRandomA;
+ CK_BYTE_PTR pPrimeP;
+ CK_BYTE_PTR pBaseG;
+ CK_BYTE_PTR pSubprimeQ;
+} CK_SKIPJACK_PRIVATE_WRAP_PARAMS;
+
+typedef CK_SKIPJACK_PRIVATE_WRAP_PARAMS CK_PTR \
+ CK_SKIPJACK_PRIVATE_WRAP_PTR;
+
+
+/* CK_SKIPJACK_RELAYX_PARAMS provides the parameters to the
+ * CKM_SKIPJACK_RELAYX mechanism */
+/* CK_SKIPJACK_RELAYX_PARAMS is new for v2.0 */
+typedef struct CK_SKIPJACK_RELAYX_PARAMS {
+ CK_ULONG ulOldWrappedXLen;
+ CK_BYTE_PTR pOldWrappedX;
+ CK_ULONG ulOldPasswordLen;
+ CK_BYTE_PTR pOldPassword;
+ CK_ULONG ulOldPublicDataLen;
+ CK_BYTE_PTR pOldPublicData;
+ CK_ULONG ulOldRandomLen;
+ CK_BYTE_PTR pOldRandomA;
+ CK_ULONG ulNewPasswordLen;
+ CK_BYTE_PTR pNewPassword;
+ CK_ULONG ulNewPublicDataLen;
+ CK_BYTE_PTR pNewPublicData;
+ CK_ULONG ulNewRandomLen;
+ CK_BYTE_PTR pNewRandomA;
+} CK_SKIPJACK_RELAYX_PARAMS;
+
+typedef CK_SKIPJACK_RELAYX_PARAMS CK_PTR \
+ CK_SKIPJACK_RELAYX_PARAMS_PTR;
+
+
+typedef struct CK_PBE_PARAMS {
+ CK_BYTE_PTR pInitVector;
+ CK_UTF8CHAR_PTR pPassword;
+ CK_ULONG ulPasswordLen;
+ CK_BYTE_PTR pSalt;
+ CK_ULONG ulSaltLen;
+ CK_ULONG ulIteration;
+} CK_PBE_PARAMS;
+
+typedef CK_PBE_PARAMS CK_PTR CK_PBE_PARAMS_PTR;
+
+
+/* CK_KEY_WRAP_SET_OAEP_PARAMS provides the parameters to the
+ * CKM_KEY_WRAP_SET_OAEP mechanism */
+/* CK_KEY_WRAP_SET_OAEP_PARAMS is new for v2.0 */
+typedef struct CK_KEY_WRAP_SET_OAEP_PARAMS {
+ CK_BYTE bBC; /* block contents byte */
+ CK_BYTE_PTR pX; /* extra data */
+ CK_ULONG ulXLen; /* length of extra data in bytes */
+} CK_KEY_WRAP_SET_OAEP_PARAMS;
+
+typedef CK_KEY_WRAP_SET_OAEP_PARAMS CK_PTR \
+ CK_KEY_WRAP_SET_OAEP_PARAMS_PTR;
+
+
+typedef struct CK_SSL3_RANDOM_DATA {
+ CK_BYTE_PTR pClientRandom;
+ CK_ULONG ulClientRandomLen;
+ CK_BYTE_PTR pServerRandom;
+ CK_ULONG ulServerRandomLen;
+} CK_SSL3_RANDOM_DATA;
+
+
+typedef struct CK_SSL3_MASTER_KEY_DERIVE_PARAMS {
+ CK_SSL3_RANDOM_DATA RandomInfo;
+ CK_VERSION_PTR pVersion;
+} CK_SSL3_MASTER_KEY_DERIVE_PARAMS;
+
+typedef struct CK_SSL3_MASTER_KEY_DERIVE_PARAMS CK_PTR \
+ CK_SSL3_MASTER_KEY_DERIVE_PARAMS_PTR;
+
+
+typedef struct CK_SSL3_KEY_MAT_OUT {
+ CK_OBJECT_HANDLE hClientMacSecret;
+ CK_OBJECT_HANDLE hServerMacSecret;
+ CK_OBJECT_HANDLE hClientKey;
+ CK_OBJECT_HANDLE hServerKey;
+ CK_BYTE_PTR pIVClient;
+ CK_BYTE_PTR pIVServer;
+} CK_SSL3_KEY_MAT_OUT;
+
+typedef CK_SSL3_KEY_MAT_OUT CK_PTR CK_SSL3_KEY_MAT_OUT_PTR;
+
+
+typedef struct CK_SSL3_KEY_MAT_PARAMS {
+ CK_ULONG ulMacSizeInBits;
+ CK_ULONG ulKeySizeInBits;
+ CK_ULONG ulIVSizeInBits;
+ CK_BBOOL bIsExport;
+ CK_SSL3_RANDOM_DATA RandomInfo;
+ CK_SSL3_KEY_MAT_OUT_PTR pReturnedKeyMaterial;
+} CK_SSL3_KEY_MAT_PARAMS;
+
+typedef CK_SSL3_KEY_MAT_PARAMS CK_PTR CK_SSL3_KEY_MAT_PARAMS_PTR;
+
+/* CK_TLS_PRF_PARAMS is new for version 2.20 */
+typedef struct CK_TLS_PRF_PARAMS {
+ CK_BYTE_PTR pSeed;
+ CK_ULONG ulSeedLen;
+ CK_BYTE_PTR pLabel;
+ CK_ULONG ulLabelLen;
+ CK_BYTE_PTR pOutput;
+ CK_ULONG_PTR pulOutputLen;
+} CK_TLS_PRF_PARAMS;
+
+typedef CK_TLS_PRF_PARAMS CK_PTR CK_TLS_PRF_PARAMS_PTR;
+
+/* WTLS is new for version 2.20 */
+typedef struct CK_WTLS_RANDOM_DATA {
+ CK_BYTE_PTR pClientRandom;
+ CK_ULONG ulClientRandomLen;
+ CK_BYTE_PTR pServerRandom;
+ CK_ULONG ulServerRandomLen;
+} CK_WTLS_RANDOM_DATA;
+
+typedef CK_WTLS_RANDOM_DATA CK_PTR CK_WTLS_RANDOM_DATA_PTR;
+
+typedef struct CK_WTLS_MASTER_KEY_DERIVE_PARAMS {
+ CK_MECHANISM_TYPE DigestMechanism;
+ CK_WTLS_RANDOM_DATA RandomInfo;
+ CK_BYTE_PTR pVersion;
+} CK_WTLS_MASTER_KEY_DERIVE_PARAMS;
+
+typedef CK_WTLS_MASTER_KEY_DERIVE_PARAMS CK_PTR \
+ CK_WTLS_MASTER_KEY_DERIVE_PARAMS_PTR;
+
+typedef struct CK_WTLS_PRF_PARAMS {
+ CK_MECHANISM_TYPE DigestMechanism;
+ CK_BYTE_PTR pSeed;
+ CK_ULONG ulSeedLen;
+ CK_BYTE_PTR pLabel;
+ CK_ULONG ulLabelLen;
+ CK_BYTE_PTR pOutput;
+ CK_ULONG_PTR pulOutputLen;
+} CK_WTLS_PRF_PARAMS;
+
+typedef CK_WTLS_PRF_PARAMS CK_PTR CK_WTLS_PRF_PARAMS_PTR;
+
+typedef struct CK_WTLS_KEY_MAT_OUT {
+ CK_OBJECT_HANDLE hMacSecret;
+ CK_OBJECT_HANDLE hKey;
+ CK_BYTE_PTR pIV;
+} CK_WTLS_KEY_MAT_OUT;
+
+typedef CK_WTLS_KEY_MAT_OUT CK_PTR CK_WTLS_KEY_MAT_OUT_PTR;
+
+typedef struct CK_WTLS_KEY_MAT_PARAMS {
+ CK_MECHANISM_TYPE DigestMechanism;
+ CK_ULONG ulMacSizeInBits;
+ CK_ULONG ulKeySizeInBits;
+ CK_ULONG ulIVSizeInBits;
+ CK_ULONG ulSequenceNumber;
+ CK_BBOOL bIsExport;
+ CK_WTLS_RANDOM_DATA RandomInfo;
+ CK_WTLS_KEY_MAT_OUT_PTR pReturnedKeyMaterial;
+} CK_WTLS_KEY_MAT_PARAMS;
+
+typedef CK_WTLS_KEY_MAT_PARAMS CK_PTR CK_WTLS_KEY_MAT_PARAMS_PTR;
+
+/* CMS is new for version 2.20 */
+typedef struct CK_CMS_SIG_PARAMS {
+ CK_OBJECT_HANDLE certificateHandle;
+ CK_MECHANISM_PTR pSigningMechanism;
+ CK_MECHANISM_PTR pDigestMechanism;
+ CK_UTF8CHAR_PTR pContentType;
+ CK_BYTE_PTR pRequestedAttributes;
+ CK_ULONG ulRequestedAttributesLen;
+ CK_BYTE_PTR pRequiredAttributes;
+ CK_ULONG ulRequiredAttributesLen;
+} CK_CMS_SIG_PARAMS;
+
+typedef CK_CMS_SIG_PARAMS CK_PTR CK_CMS_SIG_PARAMS_PTR;
+
+typedef struct CK_KEY_DERIVATION_STRING_DATA {
+ CK_BYTE_PTR pData;
+ CK_ULONG ulLen;
+} CK_KEY_DERIVATION_STRING_DATA;
+
+typedef CK_KEY_DERIVATION_STRING_DATA CK_PTR \
+ CK_KEY_DERIVATION_STRING_DATA_PTR;
+
+
+/* The CK_EXTRACT_PARAMS is used for the
+ * CKM_EXTRACT_KEY_FROM_KEY mechanism. It specifies which bit
+ * of the base key should be used as the first bit of the
+ * derived key */
+/* CK_EXTRACT_PARAMS is new for v2.0 */
+typedef CK_ULONG CK_EXTRACT_PARAMS;
+
+typedef CK_EXTRACT_PARAMS CK_PTR CK_EXTRACT_PARAMS_PTR;
+
+/* CK_PKCS5_PBKD2_PSEUDO_RANDOM_FUNCTION_TYPE is new for v2.10.
+ * CK_PKCS5_PBKD2_PSEUDO_RANDOM_FUNCTION_TYPE is used to
+ * indicate the Pseudo-Random Function (PRF) used to generate
+ * key bits using PKCS #5 PBKDF2. */
+typedef CK_ULONG CK_PKCS5_PBKD2_PSEUDO_RANDOM_FUNCTION_TYPE;
+
+typedef CK_PKCS5_PBKD2_PSEUDO_RANDOM_FUNCTION_TYPE CK_PTR CK_PKCS5_PBKD2_PSEUDO_RANDOM_FUNCTION_TYPE_PTR;
+
+/* The following PRFs are defined in PKCS #5 v2.0. */
+#define CKP_PKCS5_PBKD2_HMAC_SHA1 0x00000001
+
+
+/* CK_PKCS5_PBKDF2_SALT_SOURCE_TYPE is new for v2.10.
+ * CK_PKCS5_PBKDF2_SALT_SOURCE_TYPE is used to indicate the
+ * source of the salt value when deriving a key using PKCS #5
+ * PBKDF2. */
+typedef CK_ULONG CK_PKCS5_PBKDF2_SALT_SOURCE_TYPE;
+
+typedef CK_PKCS5_PBKDF2_SALT_SOURCE_TYPE CK_PTR CK_PKCS5_PBKDF2_SALT_SOURCE_TYPE_PTR;
+
+/* The following salt value sources are defined in PKCS #5 v2.0. */
+#define CKZ_SALT_SPECIFIED 0x00000001
+
+/* CK_PKCS5_PBKD2_PARAMS is new for v2.10.
+ * CK_PKCS5_PBKD2_PARAMS is a structure that provides the
+ * parameters to the CKM_PKCS5_PBKD2 mechanism. */
+typedef struct CK_PKCS5_PBKD2_PARAMS {
+ CK_PKCS5_PBKDF2_SALT_SOURCE_TYPE saltSource;
+ CK_VOID_PTR pSaltSourceData;
+ CK_ULONG ulSaltSourceDataLen;
+ CK_ULONG iterations;
+ CK_PKCS5_PBKD2_PSEUDO_RANDOM_FUNCTION_TYPE prf;
+ CK_VOID_PTR pPrfData;
+ CK_ULONG ulPrfDataLen;
+ CK_UTF8CHAR_PTR pPassword;
+ CK_ULONG_PTR ulPasswordLen;
+} CK_PKCS5_PBKD2_PARAMS;
+
+typedef CK_PKCS5_PBKD2_PARAMS CK_PTR CK_PKCS5_PBKD2_PARAMS_PTR;
+
+#endif
diff --git a/src/Makefile.am b/src/Makefile.am
new file mode 100644
index 0000000..2229d31
--- /dev/null
+++ b/src/Makefile.am
@@ -0,0 +1,21 @@
+# Process this file with automake to create Makefile.in
+
+MAINTAINERCLEANFILES = Makefile.in
+DISTCLEANFILES= libp11.pc
+EXTRA_DIST = Makefile.mak makedef.pl
+
+INCLUDES = @LTDLINCL@ @OPENSSL_CFLAGS@ -I../rsaref/
+
+noinst_HEADERS= libp11-int.h
+include_HEADERS= libp11.h
+
+lib_LTLIBRARIES = libp11.la
+
+libp11_la_SOURCES = p11_attr.c p11_cert.c p11_err.c p11_key.c \
+ p11_load.c p11_misc.c p11_rsa.c p11_slot.c p11_ops.c
+
+libp11_la_LDFLAGS = -version-info @LIBP11_VERSION@
+libp11_la_LIBADD = @LIBLTDL@ @OPENSSL_LIBS@
+
+pkgconfigdir = @libdir@/pkgconfig
+pkgconfig_DATA = libp11.pc
diff --git a/src/Makefile.mak b/src/Makefile.mak
new file mode 100644
index 0000000..92b62b8
--- /dev/null
+++ b/src/Makefile.mak
@@ -0,0 +1,20 @@
+OPENSSL_INCL_DIR = /IC:\openssl\include
+OPENSSL_LIB = C:\openssl\out32dll\libeay32.lib
+
+COPTS = /Zi /MD /nologo $(OPENSSL_INCL_DIR) /D_WIN32_WINNT=0x0400 $(OPENSSL_DEF)
+LINKFLAGS = /DEBUG /NOLOGO /INCREMENTAL:NO /MACHINE:IX86
+
+TARGET = libp11.dll
+
+OBJECTS = p11_attr.obj p11_cert.obj p11_err.obj \
+ p11_key.obj p11_load.obj p11_misc.obj p11_rsa.obj p11_slot.obj p11_ops.obj
+
+all: $(TARGET)
+
+.c.obj::
+ cl $(COPTS) /c $<
+
+$(TARGET): $(OBJECTS)
+ perl makedef.pl $*.def $* $(OBJECTS)
+ link $(LINKFLAGS) /dll /def:$*.def /implib:$*.lib /out:$(TARGET) \
+ $(OBJECTS) $(OPENSSL_LIB)
diff --git a/src/libp11-int.h b/src/libp11-int.h
new file mode 100644
index 0000000..e33e98f
--- /dev/null
+++ b/src/libp11-int.h
@@ -0,0 +1,159 @@
+/* libp11, a simple layer on to of PKCS#11 API
+ * Copyright (C) 2005 Olaf Kirch <okir at lst.de>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef _LIBP11_INT_H
+#define _LIBP11_INT_H
+
+#include <openssl/bio.h>
+#include <openssl/err.h>
+#include <openssl/x509.h>
+
+#include <cryptoki.h>
+
+extern void *C_LoadModule(const char *name, CK_FUNCTION_LIST_PTR_PTR);
+extern CK_RV C_UnloadModule(void *module);
+
+#include <libp11.h>
+
+/* get private implementations of PKCS11 structures */
+
+/*
+ * PKCS11_CTX: context for a PKCS11 implementation
+ */
+typedef struct pkcs11_ctx_private {
+ char *name;
+ void *libinfo;
+ CK_FUNCTION_LIST_PTR method;
+
+ CK_SESSION_HANDLE session;
+ int nslots;
+ PKCS11_SLOT *slots;
+} PKCS11_CTX_private;
+#define PRIVCTX(ctx) ((PKCS11_CTX_private *) (ctx->_private))
+
+typedef struct pkcs11_slot_private {
+ PKCS11_CTX *parent;
+ unsigned char haveSession, loggedIn;
+ CK_SLOT_ID id;
+ CK_SESSION_HANDLE session;
+} PKCS11_SLOT_private;
+#define PRIVSLOT(slot) ((PKCS11_SLOT_private *) (slot->_private))
+#define SLOT2CTX(slot) (PRIVSLOT(slot)->parent)
+
+typedef struct pkcs11_token_private {
+ PKCS11_SLOT *parent;
+ int nkeys, nprkeys;
+ PKCS11_KEY *keys;
+ int ncerts;
+ PKCS11_CERT *certs;
+} PKCS11_TOKEN_private;
+#define PRIVTOKEN(token) ((PKCS11_TOKEN_private *) (token->_private))
+#define TOKEN2SLOT(token) (PRIVTOKEN(token)->parent)
+#define TOKEN2CTX(token) SLOT2CTX(TOKEN2SLOT(token))
+
+typedef struct pkcs11_key_ops {
+ int type; /* EVP_PKEY_xxx */
+ int (*get_public) (PKCS11_KEY *, EVP_PKEY *);
+ int (*get_private) (PKCS11_KEY *, EVP_PKEY *);
+} PKCS11_KEY_ops;
+
+typedef struct pkcs11_key_private {
+ PKCS11_TOKEN *parent;
+ CK_OBJECT_HANDLE object;
+ unsigned char id[255];
+ size_t id_len;
+ PKCS11_KEY_ops *ops;
+} PKCS11_KEY_private;
+#define PRIVKEY(key) ((PKCS11_KEY_private *) key->_private)
+#define KEY2SLOT(key) TOKEN2SLOT(KEY2TOKEN(key))
+#define KEY2TOKEN(key) (PRIVKEY(key)->parent)
+#define KEY2CTX(key) TOKEN2CTX(KEY2TOKEN(key))
+
+typedef struct pkcs11_cert_private {
+ PKCS11_TOKEN *parent;
+ CK_OBJECT_HANDLE object;
+ unsigned char id[255];
+ size_t id_len;
+} PKCS11_CERT_private;
+#define PRIVCERT(cert) ((PKCS11_CERT_private *) cert->_private)
+#define CERT2SLOT(cert) TOKEN2SLOT(CERT2TOKEN(cert))
+#define CERT2TOKEN(cert) (PRIVCERT(cert)->parent)
+#define CERT2CTX(cert) TOKEN2CTX(CERT2TOKEN(cert))
+
+/*
+ * Mapping Cryptoki error codes to those used internally
+ * by this code.
+ * Right now, we just map them directly, and make sure
+ * that the few genuine messages we use don't clash with
+ * PKCS#11
+ */
+#define pkcs11_map_err(rv) (rv)
+
+/*
+ * Internal functions
+ */
+#define CRYPTOKI_checkerr(f, rv) \
+ do { if (rv) { \
+ PKCS11err(f, pkcs11_map_err(rv)); \
+ return -1; \
+ } } while (0)
+#define CRYPTOKI_call(ctx, func_and_args) \
+ PRIVCTX(ctx)->method->func_and_args
+
+/* Memory allocation */
+#define PKCS11_NEW(type) \
+ ((type *) pkcs11_malloc(sizeof(type)))
+#define PKCS11_DUP(s) \
+ pkcs11_strdup((char *) s, sizeof(s))
+
+extern int PKCS11_open_session(PKCS11_SLOT *, int);
+extern void pkcs11_destroy_all_slots(PKCS11_CTX *);
+extern void pkcs11_destroy_slot(PKCS11_CTX *, PKCS11_SLOT *);
+extern void pkcs11_destroy_keys(PKCS11_TOKEN *);
+extern void pkcs11_destroy_certs(PKCS11_TOKEN *);
+extern void *pkcs11_malloc(size_t);
+extern char *pkcs11_strdup(char *, size_t);
+
+extern int pkcs11_getattr(PKCS11_TOKEN *, CK_OBJECT_HANDLE,
+ unsigned int, void *, size_t);
+extern int pkcs11_getattr_s(PKCS11_TOKEN *, CK_OBJECT_HANDLE,
+ unsigned int, void *, size_t);
+extern int pkcs11_getattr_var(PKCS11_TOKEN *, CK_OBJECT_HANDLE,
+ unsigned int, void *, size_t *);
+extern int pkcs11_getattr_bn(PKCS11_TOKEN *, CK_OBJECT_HANDLE,
+ unsigned int, BIGNUM **);
+
+#define key_getattr(key, t, p, s) \
+ pkcs11_getattr(KEY2TOKEN((key)), PRIVKEY((key))->object, (t), (p), (s))
+
+#define key_getattr_bn(key, t, bn) \
+ pkcs11_getattr_bn(KEY2TOKEN((key)), PRIVKEY((key))->object, (t), (bn))
+
+typedef int (*pkcs11_i2d_fn) (void *, unsigned char **);
+extern void pkcs11_addattr(CK_ATTRIBUTE_PTR, int, const void *, size_t);
+extern void pkcs11_addattr_int(CK_ATTRIBUTE_PTR, int, unsigned long);
+extern void pkcs11_addattr_s(CK_ATTRIBUTE_PTR, int, const char *);
+extern void pkcs11_addattr_bn(CK_ATTRIBUTE_PTR, int, const BIGNUM *);
+extern void pkcs11_addattr_obj(CK_ATTRIBUTE_PTR, int, pkcs11_i2d_fn, void *);
+extern void pkcs11_zap_attrs(CK_ATTRIBUTE_PTR, unsigned int);
+
+extern void *memdup(const void *, size_t);
+
+extern PKCS11_KEY_ops pkcs11_rsa_ops;
+
+#endif
diff --git a/src/libp11.h b/src/libp11.h
new file mode 100644
index 0000000..5f07420
--- /dev/null
+++ b/src/libp11.h
@@ -0,0 +1,205 @@
+/* libp11, a simple layer on to of PKCS#11 API
+ * Copyright (C) 2005 Olaf Kirch <okir at lst.de>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef _LIB11_H
+#define _LIB11_H
+
+#include <openssl/bio.h>
+#include <openssl/err.h>
+#include <openssl/x509.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* get some structures for local code to handle pkcs11 data readily */
+#define ERR_LIB_PKCS11 ERR_LIB_USER
+
+#define PKCS11err(f,r) \
+ERR_PUT_error(ERR_LIB_PKCS11,(f),(r),__FILE__,__LINE__)
+
+/*
+ * The purpose of this library is to provide a simple PKCS11
+ * interface to OpenSSL application that wish to use a previously
+ * initialized card (as opposed to initializing it, etc).
+ *
+ * I am therefore making some simplifying assumptions:
+ *
+ * - no support for any operations that alter the card,
+ * i.e. readonly-login
+ */
+
+/* PKCS11 key object (public or private) */
+typedef struct PKCS11_key_st {
+ char *label;
+ unsigned char *id;
+ int id_len;
+ unsigned char isPrivate; /* private key present? */
+ unsigned char needLogin; /* login to read private key? */
+ EVP_PKEY *evp_key; /* initially NULL, need to call PKCS11_load_key */
+ void *_private;
+} PKCS11_KEY;
+
+/* PKCS11 certificate object */
+typedef struct PKCS11_cert_st {
+ char *label;
+ unsigned char *id;
+ int id_len;
+ X509 *x509;
+ void *_private;
+} PKCS11_CERT;
+
+/* PKCS11 token, e.g. smart card or USB key */
+typedef struct PKCS11_token_st {
+ char *label;
+ char *manufacturer;
+ char *model;
+ unsigned char initialized;
+ unsigned char loginRequired;
+ unsigned char secureLogin;
+ unsigned char userPinSet;
+ unsigned char readOnly;
+ void *_private;
+} PKCS11_TOKEN;
+
+/* PKCS11 slot, e.g. card reader */
+typedef struct PKCS11_slot_st {
+ char *manufacturer;
+ char *description;
+ unsigned char removable;
+ PKCS11_TOKEN *token; /* NULL if no token present */
+ void *_private;
+} PKCS11_SLOT;
+
+typedef struct PKCS11_ctx_st {
+ char *manufacturer;
+ char *description;
+ void *_private;
+} PKCS11_CTX;
+
+extern PKCS11_CTX *PKCS11_CTX_new(void);
+extern int PKCS11_CTX_load(PKCS11_CTX *, const char *ident);
+extern void PKCS11_CTX_unload(PKCS11_CTX *);
+extern void PKCS11_CTX_free(PKCS11_CTX *);
+
+/* Get a list of all slots */
+extern int PKCS11_enumerate_slots(PKCS11_CTX *, PKCS11_SLOT **, unsigned int *);
+
+/* Find the first slot with a token */
+extern PKCS11_SLOT *PKCS11_find_token(PKCS11_CTX *);
+
+/* Authenticate to the card */
+extern int PKCS11_login(PKCS11_SLOT *, int so, const char *pin);
+extern int PKCS11_logout(PKCS11_SLOT *);
+
+/* Get a list of all keys associated with this token */
+extern int PKCS11_enumerate_keys(PKCS11_TOKEN *, PKCS11_KEY **, unsigned int *);
+
+/* Get the key type (as EVP_PKEY_XXX) */
+extern int PKCS11_get_key_type(PKCS11_KEY *);
+
+/* Get size of key modulus in number of bytes */
+extern int PKCS11_get_key_size(PKCS11_KEY *);
+/* Get actual modules and public exponent as BIGNUM */
+extern int PKCS11_get_key_modulus(PKCS11_KEY *, BIGNUM **);
+extern int PKCS11_get_key_exponent(PKCS11_KEY *, BIGNUM **);
+
+/* Get the enveloped private key */
+extern EVP_PKEY *PKCS11_get_private_key(PKCS11_KEY *);
+extern EVP_PKEY *PKCS11_get_public_key(PKCS11_KEY *);
+
+/* Find the corresponding certificate (if any) */
+extern PKCS11_CERT *PKCS11_find_certificate(PKCS11_KEY *);
+
+/* Find the corresponding key (if any) */
+extern PKCS11_KEY *PKCS11_find_key(PKCS11_CERT *);
+
+/* Get a list of all certificates associated with this token */
+extern int PKCS11_enumerate_certs(PKCS11_TOKEN *, PKCS11_CERT **, unsigned int *);
+
+/* Initialize a token */
+extern int PKCS11_init_token(PKCS11_TOKEN *, const char *pin,
+ const char *label);
+
+/* Initialize the user PIN on a token */
+extern int PKCS11_init_pin(PKCS11_TOKEN *, const char *pin);
+
+/* Change the user PIN on a token */
+extern int PKCS11_change_pin(PKCS11_SLOT *, const char *old_pin,
+ const char *new_pin);
+
+/* Store various objects on the token */
+extern int PKCS11_generate_key(PKCS11_TOKEN *, int, unsigned int, char *);
+extern int PKCS11_store_private_key(PKCS11_TOKEN *, EVP_PKEY *, char *);
+
+/* rsa private key operations */
+extern int PKCS11_sign(int type, const unsigned char *m, unsigned int m_len,
+ unsigned char *sigret, unsigned int *siglen, const PKCS11_KEY * key);
+extern int PKCS11_private_encrypt(int flen, const unsigned char *from,
+ unsigned char *to, const PKCS11_KEY * rsa, int padding);
+extern int PKCS11_private_decrypt(int flen, const unsigned char *from,
+ unsigned char *to, PKCS11_KEY * key, int padding);
+extern int PKCS11_verify(int type, const unsigned char *m, unsigned int m_len,
+ unsigned char *signature, unsigned int siglen, PKCS11_KEY * key);
+
+/* access random number generator */
+extern int PKCS11_seed_random(PKCS11_SLOT *, const unsigned char *s, unsigned int s_len);
+extern int PKCS11_generate_random(PKCS11_SLOT *, unsigned char *r, unsigned int r_len);
+
+/* Load PKCS11 error strings */
+extern void ERR_load_PKCS11_strings(void);
+
+/*
+ * Function and reason codes
+ */
+#define PKCS11_F_PKCS11_CTX_LOAD 1
+#define PKCS11_F_PKCS11_ENUM_SLOTS 2
+#define PKCS11_F_PKCS11_CHECK_TOKEN 3
+#define PKCS11_F_PKCS11_OPEN_SESSION 4
+#define PKCS11_F_PKCS11_LOGIN 5
+#define PKCS11_F_PKCS11_ENUM_KEYS 6
+#define PKCS11_F_PKCS11_GET_KEY 7
+#define PKCS11_F_PKCS11_RSA_DECRYPT 8
+#define PKCS11_F_PKCS11_RSA_ENCRYPT 9
+#define PKCS11_F_PKCS11_RSA_SIGN 10
+#define PKCS11_F_PKCS11_RSA_VERIFY 11
+#define PKCS11_F_PKCS11_ENUM_CERTS 12
+#define PKCS11_F_PKCS11_INIT_TOKEN 13
+#define PKCS11_F_PKCS11_INIT_PIN 14
+#define PKCS11_F_PKCS11_LOGOUT 15
+#define PKCS11_F_PKCS11_STORE_PRIVATE_KEY 16
+#define PKCS11_F_PKCS11_GENERATE_KEY 17
+#define PKCS11_F_PKCS11_STORE_PUBLIC_KEY 18
+#define PKCS11_F_PKCS11_STORE_CERTIFICATE 19
+#define PKCS11_F_PKCS11_SEED_RANDOM 20
+#define PKCS11_F_PKCS11_GENERATE_RANDOM 21
+#define PKCS11_F_PKCS11_CHANGE_PIN 22
+#define PKCS11_F_PKCS11_GETATTR 40
+
+#define PKCS11_ERR_BASE 1024
+#define PKCS11_LOAD_MODULE_ERROR (PKCS11_ERR_BASE+1)
+#define PKCS11_MODULE_LOADED_ERROR (PKCS11_ERR_BASE+2)
+#define PKCS11_SYMBOL_NOT_FOUND_ERROR (PKCS11_ERR_BASE+3)
+#define PKCS11_NOT_SUPPORTED (PKCS11_ERR_BASE+4)
+#define PKCS11_NO_SESSION (PKCS11_ERR_BASE+5)
+#define PKCS11_KEYGEN_FAILED (PKCS11_ERR_BASE+6)
+
+#ifdef __cplusplus
+}
+#endif
+#endif
diff --git a/src/libp11.pc.in b/src/libp11.pc.in
new file mode 100644
index 0000000..d496752
--- /dev/null
+++ b/src/libp11.pc.in
@@ -0,0 +1,11 @@
+prefix=@prefix@
+exec_prefix=@exec_prefix@
+libdir=@libdir@
+includedir=@includedir@
+
+Name: libp11
+Description: libp11
+Version: @VERSION@
+Libs: -L${libdir} -lp11
+Cflags: -I${includedir}
+
diff --git a/src/libpkcs11.c b/src/libpkcs11.c
new file mode 100644
index 0000000..0c5e15e
--- /dev/null
+++ b/src/libpkcs11.c
@@ -0,0 +1,93 @@
+/* libp11, a simple layer on to of PKCS#11 API
+ * Copyright (C) 2005 Olaf Kirch <okir at lst.de>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+/*
+ * Convenience pkcs11 library that can be linked into an application,
+ * and will bind to a specific pkcs11 module.
+ *
+ * Copyright (C) 2002 Olaf Kirch <okir at lst.de>
+ */
+
+#include "pkcs11.h"
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <opensc/scdl.h>
+
+#define MAGIC 0xd00bed00
+
+struct sc_pkcs11_module {
+ unsigned int _magic;
+ void *handle;
+};
+typedef struct sc_pkcs11_module sc_pkcs11_module_t;
+
+/*
+ * Load a module - this will load the shared object, call
+ * C_Initialize, and get the list of function pointers
+ */
+void *
+C_LoadModule(const char *mspec, CK_FUNCTION_LIST_PTR_PTR funcs)
+{
+ sc_pkcs11_module_t *mod;
+ CK_RV (*c_get_function_list)(CK_FUNCTION_LIST_PTR_PTR);
+ int rv;
+
+ mod = (sc_pkcs11_module_t *) calloc(1, sizeof(*mod));
+ mod->_magic = MAGIC;
+
+ if (mspec == NULL)
+ mspec = PKCS11_DEFAULT_MODULE_NAME;
+ mod->handle = scdl_open(mspec);
+ if (mod->handle == NULL)
+ goto failed;
+
+ /* Get the list of function pointers */
+ c_get_function_list = (CK_RV (*)(CK_FUNCTION_LIST_PTR_PTR))
+ scdl_get_address(mod->handle, "C_GetFunctionList");
+ if (!c_get_function_list)
+ goto failed;
+ rv = c_get_function_list(funcs);
+ if (rv == CKR_OK)
+ return (void *) mod;
+
+failed:
+ C_UnloadModule((void *) mod);
+ return NULL;
+}
+
+/*
+ * Unload a pkcs11 module.
+ * The calling application is responsible for cleaning up
+ * and calling C_Finalize
+ */
+CK_RV
+C_UnloadModule(void *module)
+{
+ sc_pkcs11_module_t *mod = (sc_pkcs11_module_t *) module;
+
+ if (!mod || mod->_magic != MAGIC)
+ return CKR_ARGUMENTS_BAD;
+
+ if (scdl_close(mod->handle) < 0)
+ return CKR_FUNCTION_FAILED;
+
+ memset(mod, 0, sizeof(*mod));
+ free(mod);
+ return CKR_OK;
+}
diff --git a/src/makedef.pl b/src/makedef.pl
new file mode 100644
index 0000000..2752f7a
--- /dev/null
+++ b/src/makedef.pl
@@ -0,0 +1,33 @@
+$def = $ARGV[0];
+shift @ARGV;
+$lib = $ARGV[0];
+shift @ARGV;
+$dumpbin = "dumpbin /symbols @ARGV";
+
+open(DUMP, "$dumpbin |")
+ || die "Can't run `$dumpbin': $!.\n";
+
+open(DEF, "> $def")
+ || die "Can't open `$def': $!.\n";
+
+print DEF "LIBRARY $lib\n";
+print DEF "EXPORTS\n";
+
+while(<DUMP>)
+{
+ if(!/\bUNDEF\b/ && /\bExternal\b/)
+ {
+ s/^.*\|\s+//;
+ split;
+ $_ = $_[0];
+
+ if(!/^\?\?_G/ && !/^\?\?_E/ && !/DllMain/)
+ {
+ # Stupid windows linker needs to have
+ # preceding underscore for ANSI C programs
+ s/^_//;
+
+ print DEF " $_\n";
+ }
+ }
+}
diff --git a/src/p11_attr.c b/src/p11_attr.c
new file mode 100644
index 0000000..e1eab58
--- /dev/null
+++ b/src/p11_attr.c
@@ -0,0 +1,150 @@
+/* libp11, a simple layer on to of PKCS#11 API
+ * Copyright (C) 2005 Olaf Kirch <okir at lst.de>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+/*
+ * PKCS11 attribute querying.
+ *
+ * The number of layers we stack on top of each other here
+ * is frightening.
+ *
+ * Copyright (C) 2002, Olaf Kirch <okir at lst.de>
+ */
+
+#include <assert.h>
+#include <string.h>
+
+#include "libp11-int.h"
+
+static int pkcs11_getattr_int(PKCS11_CTX *, CK_SESSION_HANDLE,
+ CK_OBJECT_HANDLE, CK_ATTRIBUTE_TYPE, void *, size_t *);
+
+/*
+ * Query pkcs11 attributes
+ */
+static int
+pkcs11_getattr_int(PKCS11_CTX * ctx, CK_SESSION_HANDLE session,
+ CK_OBJECT_HANDLE o, CK_ATTRIBUTE_TYPE type, void *value,
+ size_t * size)
+{
+ CK_ATTRIBUTE templ;
+ int rv;
+
+ templ.type = type;
+ templ.pValue = value;
+ templ.ulValueLen = *size;
+
+ rv = CRYPTOKI_call(ctx, C_GetAttributeValue(session, o, &templ, 1));
+ CRYPTOKI_checkerr(PKCS11_F_PKCS11_GETATTR, rv);
+
+ *size = templ.ulValueLen;
+ return 0;
+}
+
+int
+pkcs11_getattr_var(PKCS11_TOKEN * token, CK_OBJECT_HANDLE object,
+ unsigned int type, void *value, size_t * size)
+{
+ return pkcs11_getattr_int(TOKEN2CTX(token),
+ PRIVSLOT(TOKEN2SLOT(token))->session,
+ object, type, value, size);
+}
+
+int
+pkcs11_getattr(PKCS11_TOKEN * token, CK_OBJECT_HANDLE object,
+ unsigned int type, void *value, size_t size)
+{
+ return pkcs11_getattr_var(token, object, type, value, &size);
+}
+
+int
+pkcs11_getattr_s(PKCS11_TOKEN * token, CK_OBJECT_HANDLE object,
+ unsigned int type, void *value, size_t size)
+{
+ memset(value, 0, size);
+ return pkcs11_getattr_var(token, object, type, value, &size);
+}
+
+int
+pkcs11_getattr_bn(PKCS11_TOKEN * token, CK_OBJECT_HANDLE object,
+ unsigned int type, BIGNUM ** bn)
+{
+ CK_BYTE binary[4196 / 8];
+ size_t size = sizeof(binary);
+
+ if (pkcs11_getattr_var(token, object, type, binary, &size))
+ return -1;
+ if (size == -1) {
+ PKCS11err(PKCS11_F_PKCS11_GETATTR,
+ pkcs11_map_err(CKR_ATTRIBUTE_TYPE_INVALID));
+ return -1;
+ }
+ *bn = BN_bin2bn(binary, size, NULL);
+ return *bn ? 0 : -1;
+}
+
+/*
+ * Add attributes to template
+ */
+void pkcs11_addattr(CK_ATTRIBUTE_PTR ap, int type, const void *data, size_t size)
+{
+ ap->type = type;
+ ap->pValue = malloc(size);
+ memcpy(ap->pValue, data, size);
+ ap->ulValueLen = size;
+}
+
+/* In PKCS11, virtually every integer is a CK_ULONG */
+void pkcs11_addattr_int(CK_ATTRIBUTE_PTR ap, int type, unsigned long value)
+{
+ CK_ULONG ulValue = value;
+
+ pkcs11_addattr(ap, type, &ulValue, sizeof(ulValue));
+}
+
+void pkcs11_addattr_s(CK_ATTRIBUTE_PTR ap, int type, const char *s)
+{
+ pkcs11_addattr(ap, type, s, s ? strlen(s) + 1 : 0);
+}
+
+void pkcs11_addattr_bn(CK_ATTRIBUTE_PTR ap, int type, const BIGNUM * bn)
+{
+ unsigned char temp[1024];
+ unsigned int n;
+
+ assert(BN_num_bytes(bn) <= sizeof(temp));
+ n = BN_bn2bin(bn, temp);
+ pkcs11_addattr(ap, type, temp, n);
+}
+
+void pkcs11_addattr_obj(CK_ATTRIBUTE_PTR ap, int type, pkcs11_i2d_fn enc, void *obj)
+{
+ unsigned char *p;
+
+ ap->type = type;
+ ap->ulValueLen = enc(obj, NULL);
+ ap->pValue = p = (unsigned char *) malloc(ap->ulValueLen);
+ enc(obj, &p);
+}
+
+void pkcs11_zap_attrs(CK_ATTRIBUTE_PTR ap, unsigned int n)
+{
+ while (n--) {
+ if (ap[n].pValue)
+ free(ap[n].pValue);
+ }
+}
diff --git a/src/p11_cert.c b/src/p11_cert.c
new file mode 100644
index 0000000..ce3357c
--- /dev/null
+++ b/src/p11_cert.c
@@ -0,0 +1,258 @@
+/* libp11, a simple layer on to of PKCS#11 API
+ * Copyright (C) 2005 Olaf Kirch <okir at lst.de>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+/*
+ * p11_cert.c - Handle certificates residing on a PKCS11 token
+ *
+ * Copyright (C) 2002, Olaf Kirch <okir at lst.de>
+ */
+
+#include <string.h>
+#include "libp11-int.h"
+
+static int pkcs11_find_certs(PKCS11_TOKEN *);
+static int pkcs11_next_cert(PKCS11_CTX *, PKCS11_TOKEN *, CK_SESSION_HANDLE);
+static int pkcs11_init_cert(PKCS11_CTX * ctx, PKCS11_TOKEN * token,
+ CK_SESSION_HANDLE session, CK_OBJECT_HANDLE o,
+ PKCS11_CERT **);
+static int pkcs11_store_certificate(PKCS11_TOKEN *, X509 *,
+ char *, unsigned char *, unsigned int,
+ PKCS11_CERT **);
+
+static CK_OBJECT_CLASS cert_search_class;
+static CK_ATTRIBUTE cert_search_attrs[] = {
+ {CKA_CLASS, &cert_search_class, sizeof(cert_search_class)},
+};
+#define numof(arr) (sizeof(arr)/sizeof((arr)[0]))
+
+/*
+ * Enumerate all certs on the card
+ */
+int
+PKCS11_enumerate_certs(PKCS11_TOKEN * token,
+ PKCS11_CERT ** certp, unsigned int *countp)
+{
+ PKCS11_TOKEN_private *priv = PRIVTOKEN(token);
+
+ if (priv->ncerts < 0) {
+ priv->ncerts = 0;
+ if (pkcs11_find_certs(token)) {
+ pkcs11_destroy_certs(token);
+ return -1;
+ }
+ }
+ *certp = priv->certs;
+ *countp = priv->ncerts;
+ return 0;
+}
+
+/*
+ * Find certificate matching a key
+ */
+PKCS11_CERT *PKCS11_find_certificate(PKCS11_KEY * key)
+{
+ PKCS11_KEY_private *kpriv;
+ PKCS11_CERT_private *cpriv;
+ PKCS11_CERT *cert;
+ unsigned int n, count;
+
+ kpriv = PRIVKEY(key);
+ if (PKCS11_enumerate_certs(KEY2TOKEN(key), &cert, &count))
+ return NULL;
+ for (n = 0; n < count; n++, cert++) {
+ cpriv = PRIVCERT(cert);
+ if (cpriv->id_len == kpriv->id_len
+ && !memcmp(cpriv->id, kpriv->id, kpriv->id_len))
+ return cert;
+ }
+ return NULL;
+}
+
+/*
+ * Find all certs of a given type (public or private)
+ */
+int pkcs11_find_certs(PKCS11_TOKEN * token)
+{
+ PKCS11_SLOT *slot = TOKEN2SLOT(token);
+ PKCS11_CTX *ctx = TOKEN2CTX(token);
+ CK_SESSION_HANDLE session;
+ int rv, res = -1;
+
+ /* Make sure we have a session */
+ if (!PRIVSLOT(slot)->haveSession && PKCS11_open_session(slot, 0))
+ return -1;
+ session = PRIVSLOT(slot)->session;
+
+ /* Tell the PKCS11 lib to enumerate all matching objects */
+ cert_search_class = CKO_CERTIFICATE;
+ rv = CRYPTOKI_call(ctx, C_FindObjectsInit(session, cert_search_attrs,
+ numof(cert_search_attrs)));
+ CRYPTOKI_checkerr(PKCS11_F_PKCS11_ENUM_CERTS, rv);
+
+ do {
+ res = pkcs11_next_cert(ctx, token, session);
+ } while (res == 0);
+
+ CRYPTOKI_call(ctx, C_FindObjectsFinal(session));
+ return (res < 0) ? -1 : 0;
+}
+
+int
+pkcs11_next_cert(PKCS11_CTX * ctx, PKCS11_TOKEN * token, CK_SESSION_HANDLE session)
+{
+ CK_OBJECT_HANDLE obj;
+ CK_ULONG count;
+ int rv;
+
+ /* Get the next matching object */
+ rv = CRYPTOKI_call(ctx, C_FindObjects(session, &obj, 1, &count));
+ CRYPTOKI_checkerr(PKCS11_F_PKCS11_ENUM_CERTS, rv);
+
+ if (count == 0)
+ return 1;
+
+ if (pkcs11_init_cert(ctx, token, session, obj, NULL))
+ return -1;
+
+ return 0;
+}
+
+int
+pkcs11_init_cert(PKCS11_CTX * ctx, PKCS11_TOKEN * token,
+ CK_SESSION_HANDLE session, CK_OBJECT_HANDLE obj, PKCS11_CERT ** ret)
+{
+ PKCS11_TOKEN_private *tpriv;
+ PKCS11_CERT_private *kpriv;
+ PKCS11_CERT *cert, *tmp;
+ char label[256], data[2048];
+ unsigned char id[256];
+ CK_CERTIFICATE_TYPE cert_type;
+ size_t size;
+
+ size = sizeof(cert_type);
+ if (pkcs11_getattr_var(token, obj, CKA_CERTIFICATE_TYPE, &cert_type, &size))
+ return -1;
+
+ /* Ignore any certs we don't understand */
+ if (cert_type != CKC_X_509)
+ return 0;
+
+ tpriv = PRIVTOKEN(token);
+ tmp = (PKCS11_CERT *) OPENSSL_realloc(tpriv->certs,
+ (tpriv->ncerts + 1) * sizeof(PKCS11_CERT));
+ if (!tmp) {
+ free(tpriv->certs);
+ tpriv->certs = NULL;
+ return -1;
+ }
+ tpriv->certs = tmp;
+
+ cert = tpriv->certs + tpriv->ncerts++;
+ memset(cert, 0, sizeof(*cert));
+ cert->_private = kpriv = PKCS11_NEW(PKCS11_CERT_private);
+ kpriv->object = obj;
+ kpriv->parent = token;
+
+ if (!pkcs11_getattr_s(token, obj, CKA_LABEL, label, sizeof(label)))
+ cert->label = BUF_strdup(label);
+ size = sizeof(data);
+ if (!pkcs11_getattr_var(token, obj, CKA_VALUE, data, &size)) {
+ unsigned char *p = (unsigned char *) data;
+
+ cert->x509 = d2i_X509(NULL, &p, size);
+ }
+ cert->id_len = sizeof(id);
+ if (!pkcs11_getattr_var(token, obj, CKA_ID, id, (size_t *) & cert->id_len)) {
+ cert->id = (unsigned char *) malloc(cert->id_len);
+ memcpy(cert->id, id, cert->id_len);
+ }
+
+ /* Initialize internal information */
+ kpriv->id_len = sizeof(kpriv->id);
+ if (pkcs11_getattr_var(token, obj, CKA_ID, kpriv->id, &kpriv->id_len))
+ kpriv->id_len = 0;
+
+ if (ret)
+ *ret = cert;
+
+ return 0;
+}
+
+/*
+ * Destroy all certs
+ */
+void pkcs11_destroy_certs(PKCS11_TOKEN * token)
+{
+ PKCS11_TOKEN_private *priv = PRIVTOKEN(token);
+
+ while (priv->ncerts > 0) {
+ PKCS11_CERT *cert = &priv->certs[--(priv->ncerts)];
+
+ if (cert->x509)
+ X509_free(cert->x509);
+ OPENSSL_free(cert->label);
+ if (cert->id)
+ free(cert->id);
+ }
+ if (priv->certs)
+ OPENSSL_free(priv->certs);
+ priv->ncerts = -1;
+ priv->certs = NULL;
+}
+
+/*
+ * Store certificate
+ */
+int
+pkcs11_store_certificate(PKCS11_TOKEN * token, X509 * x509, char *label,
+ unsigned char *id, unsigned int id_len,
+ PKCS11_CERT ** ret_cert)
+{
+ PKCS11_SLOT *slot = TOKEN2SLOT(token);
+ PKCS11_CTX *ctx = TOKEN2CTX(token);
+ CK_SESSION_HANDLE session;
+ CK_OBJECT_HANDLE object;
+ CK_ATTRIBUTE attrs[32];
+ unsigned int n = 0;
+ int rv;
+
+ /* First, make sure we have a session */
+ if (!PRIVSLOT(slot)->haveSession && PKCS11_open_session(slot, 1))
+ return -1;
+ session = PRIVSLOT(slot)->session;
+
+ /* Now build the template */
+ pkcs11_addattr_int(attrs + n++, CKA_CLASS, CKO_CERTIFICATE);
+ pkcs11_addattr_int(attrs + n++, CKA_CERTIFICATE_TYPE, CKC_X_509);
+ pkcs11_addattr_obj(attrs + n++, CKA_VALUE, (pkcs11_i2d_fn) i2d_X509, x509);
+ if (label)
+ pkcs11_addattr_s(attrs + n++, CKA_LABEL, label);
+ if (id && id_len)
+ pkcs11_addattr(attrs + n++, CKA_ID, id, id_len);
+
+ /* Now call the pkcs11 module to create the object */
+ rv = CRYPTOKI_call(ctx, C_CreateObject(session, attrs, n, &object));
+
+ /* Zap all memory allocated when building the template */
+ pkcs11_zap_attrs(attrs, n);
+
+ CRYPTOKI_checkerr(PKCS11_F_PKCS11_STORE_CERTIFICATE, rv);
+
+ /* Gobble the key object */
+ return pkcs11_init_cert(ctx, token, session, object, ret_cert);
+}
diff --git a/src/p11_err.c b/src/p11_err.c
new file mode 100644
index 0000000..f0709be
--- /dev/null
+++ b/src/p11_err.c
@@ -0,0 +1,159 @@
+/* libp11, a simple layer on to of PKCS#11 API
+ * Copyright (C) 2005 Olaf Kirch <okir at lst.de>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include "libp11-int.h"
+
+/* BEGIN ERROR CODES */
+#ifndef NO_ERR
+static ERR_STRING_DATA PKCS11_str_library[] = {
+ {ERR_PACK(ERR_LIB_PKCS11, 0, 0), "PKCS11 library"},
+ {0, NULL}
+};
+
+static ERR_STRING_DATA PKCS11_str_functs[] = {
+ {ERR_PACK(0, PKCS11_F_PKCS11_CTX_LOAD, 0), "PKCS11_CTX_load"},
+ {ERR_PACK(0, PKCS11_F_PKCS11_ENUM_SLOTS, 0), "PKCS11_enum_slots"},
+ {ERR_PACK(0, PKCS11_F_PKCS11_CHECK_TOKEN, 0), "PKCS11_check_token"},
+ {ERR_PACK(0, PKCS11_F_PKCS11_OPEN_SESSION, 0), "PKCS11_open_session"},
+ {ERR_PACK(0, PKCS11_F_PKCS11_LOGIN, 0), "PKCS11_login"},
+ {ERR_PACK(0, PKCS11_F_PKCS11_ENUM_KEYS, 0), "PKCS11_enum_keys"},
+ {ERR_PACK(0, PKCS11_F_PKCS11_GET_KEY, 0), "PKCS11_get_key"},
+ {ERR_PACK(0, PKCS11_F_PKCS11_RSA_DECRYPT, 0), "PKCS11_rsa_decrypt"},
+ {ERR_PACK(0, PKCS11_F_PKCS11_RSA_ENCRYPT, 0), "PKCS11_rsa_encrypt"},
+ {ERR_PACK(0, PKCS11_F_PKCS11_RSA_SIGN, 0), "PKCS11_rsa_sign"},
+ {ERR_PACK(0, PKCS11_F_PKCS11_RSA_VERIFY, 0), "PKCS11_rsa_verify"},
+ {ERR_PACK(0, PKCS11_F_PKCS11_ENUM_CERTS, 0), "PKCS11_enum_certs"},
+ {ERR_PACK(0, PKCS11_F_PKCS11_INIT_TOKEN, 0), "PKCS11_init_token"},
+ {ERR_PACK(0, PKCS11_F_PKCS11_INIT_PIN, 0), "PKCS11_init_pin"},
+ {ERR_PACK(0, PKCS11_F_PKCS11_GETATTR, 0), "PKCS11_get_attribute"},
+ {ERR_PACK(0, PKCS11_F_PKCS11_LOGOUT, 0), "PKCS11_logout"},
+ {ERR_PACK(0, PKCS11_F_PKCS11_STORE_PRIVATE_KEY, 0), "PKCS11_store_private_key"},
+ {ERR_PACK(0, PKCS11_F_PKCS11_GENERATE_KEY, 0), "PKCS11_generate_key"},
+ {ERR_PACK(0, PKCS11_F_PKCS11_STORE_PUBLIC_KEY, 0), "PKCS11_store_public_key"},
+ {ERR_PACK(0, PKCS11_F_PKCS11_STORE_CERTIFICATE, 0), "PKCS11_store_certificate"},
+ {ERR_PACK(0, PKCS11_F_PKCS11_CHANGE_PIN, 0), "PKCS11_change_pin"},
+ {0, NULL}
+};
+
+static ERR_STRING_DATA PKCS11_str_reasons[] = {
+ {PKCS11_LOAD_MODULE_ERROR, "Unable to load PKCS#11 module"},
+ {PKCS11_MODULE_LOADED_ERROR, "Already loaded module for PKCS11 context"},
+ {PKCS11_SYMBOL_NOT_FOUND_ERROR, "Symbol not found in PKCS#11 module"},
+ {PKCS11_NOT_SUPPORTED, "Not supported"},
+ {PKCS11_NO_SESSION, "No session open"},
+ {CKR_CANCEL, "Cancel"},
+ {CKR_HOST_MEMORY, "Host memory error"},
+ {CKR_SLOT_ID_INVALID, "Invalid slot ID"},
+ {CKR_GENERAL_ERROR, "General Error"},
+ {CKR_FUNCTION_FAILED, "Function failed"},
+ {CKR_ARGUMENTS_BAD, "Invalid arguments"},
+ {CKR_NO_EVENT, "No event"},
+ {CKR_NEED_TO_CREATE_THREADS, "Need to create threads"},
+ {CKR_CANT_LOCK, "Cannott lock"},
+ {CKR_ATTRIBUTE_READ_ONLY, "Attribute read only"},
+ {CKR_ATTRIBUTE_SENSITIVE, "Attribute sensitive"},
+ {CKR_ATTRIBUTE_TYPE_INVALID, "Attribute type invalid"},
+ {CKR_ATTRIBUTE_VALUE_INVALID, "Attribute value invalid"},
+ {CKR_DATA_INVALID, "Data invalid"},
+ {CKR_DATA_LEN_RANGE, "Data len range"},
+ {CKR_DEVICE_ERROR, "Device error"},
+ {CKR_DEVICE_MEMORY, "Device memory"},
+ {CKR_DEVICE_REMOVED, "Device removed"},
+ {CKR_ENCRYPTED_DATA_INVALID, "Encrypted data invalid"},
+ {CKR_ENCRYPTED_DATA_LEN_RANGE, "Encrypted data len range"},
+ {CKR_FUNCTION_CANCELED, "Function canceled"},
+ {CKR_FUNCTION_NOT_PARALLEL, "Function not parallel"},
+ {CKR_FUNCTION_NOT_SUPPORTED, "Function not supported"},
+ {CKR_KEY_HANDLE_INVALID, "Key handle invalid"},
+ {CKR_KEY_SIZE_RANGE, "Key size range"},
+ {CKR_KEY_TYPE_INCONSISTENT, "Key type inconsistent"},
+ {CKR_KEY_NOT_NEEDED, "Key not needed"},
+ {CKR_KEY_CHANGED, "Key changed"},
+ {CKR_KEY_NEEDED, "Key needed"},
+ {CKR_KEY_INDIGESTIBLE, "Key indigestible"},
+ {CKR_KEY_FUNCTION_NOT_PERMITTED, "Key function not permitted"},
+ {CKR_KEY_NOT_WRAPPABLE, "Key not wrappable"},
+ {CKR_KEY_UNEXTRACTABLE, "Key unextractable"},
+ {CKR_MECHANISM_INVALID, "Mechanism invalid"},
+ {CKR_MECHANISM_PARAM_INVALID, "Mechanism param invalid"},
+ {CKR_OBJECT_HANDLE_INVALID, "Object handle invalid"},
+ {CKR_OPERATION_ACTIVE, "Operation active"},
+ {CKR_OPERATION_NOT_INITIALIZED, "Operation not initialized"},
+ {CKR_PIN_INCORRECT, "PIN incorrect"},
+ {CKR_PIN_INVALID, "PIN invalid"},
+ {CKR_PIN_LEN_RANGE, "Invalid PIN length"},
+ {CKR_PIN_EXPIRED, "PIN expired"},
+ {CKR_PIN_LOCKED, "PIN locked"},
+ {CKR_SESSION_CLOSED, "Session closed"},
+ {CKR_SESSION_COUNT, "Session count"},
+ {CKR_SESSION_HANDLE_INVALID, "Session handle invalid"},
+ {CKR_SESSION_PARALLEL_NOT_SUPPORTED, "Session parallel not supported"},
+ {CKR_SESSION_READ_ONLY, "Session read only"},
+ {CKR_SESSION_EXISTS, "Session exists"},
+ {CKR_SESSION_READ_ONLY_EXISTS, "Read-only session exists"},
+ {CKR_SESSION_READ_WRITE_SO_EXISTS, "Read/write SO session exists"},
+ {CKR_SIGNATURE_INVALID, "Signature invalid"},
+ {CKR_SIGNATURE_LEN_RANGE, "Signature len range"},
+ {CKR_TEMPLATE_INCOMPLETE, "Incomplete template"},
+ {CKR_TEMPLATE_INCONSISTENT, "Inconsistent template"},
+ {CKR_TOKEN_NOT_PRESENT, "No PKCS#11 token present"},
+ {CKR_TOKEN_NOT_RECOGNIZED, "PKCS#11 token not recognized"},
+ {CKR_TOKEN_WRITE_PROTECTED, "Token write protected"},
+ {CKR_UNWRAPPING_KEY_HANDLE_INVALID, "Unwrapping key handle invalid"},
+ {CKR_UNWRAPPING_KEY_SIZE_RANGE, "Unwrapping key size range"},
+ {CKR_UNWRAPPING_KEY_TYPE_INCONSISTENT, "Unwrapping key type inconsistent"},
+ {CKR_USER_ALREADY_LOGGED_IN, "User already logged in"},
+ {CKR_USER_NOT_LOGGED_IN, "User not logged in"},
+ {CKR_USER_PIN_NOT_INITIALIZED, "User pin not initialized"},
+ {CKR_USER_TYPE_INVALID, "User type invalid"},
+ {CKR_USER_ANOTHER_ALREADY_LOGGED_IN, "User another is already logged in"},
+ {CKR_USER_TOO_MANY_TYPES, "User too many types"},
+ {CKR_WRAPPED_KEY_INVALID, "Wrapped key invalid"},
+ {CKR_WRAPPED_KEY_LEN_RANGE, "Wrapped key len range"},
+ {CKR_WRAPPING_KEY_HANDLE_INVALID, "Wrapping key handle invalid"},
+ {CKR_WRAPPING_KEY_SIZE_RANGE, "Wrapping key size range"},
+ {CKR_WRAPPING_KEY_TYPE_INCONSISTENT, "Wrapping key type inconsistent"},
+ {CKR_RANDOM_SEED_NOT_SUPPORTED, "Random seed not supported"},
+ {CKR_RANDOM_NO_RNG, "Random no rng"},
+ {CKR_DOMAIN_PARAMS_INVALID, "Domain params invalid"},
+ {CKR_BUFFER_TOO_SMALL, "Buffer too small"},
+ {CKR_SAVED_STATE_INVALID, "Saved state invalid"},
+ {CKR_INFORMATION_SENSITIVE, "Information sensitive"},
+ {CKR_STATE_UNSAVEABLE, "State unsaveable"},
+ {CKR_CRYPTOKI_NOT_INITIALIZED, "Cryptoki not initialized"},
+ {CKR_CRYPTOKI_ALREADY_INITIALIZED, "Cryptoki already initialized"},
+ {CKR_MUTEX_BAD, "Mutex bad"},
+ {CKR_MUTEX_NOT_LOCKED, "Mutex not locked"},
+ {CKR_VENDOR_DEFINED, "Vendor defined"},
+ {0, NULL}
+};
+#endif
+
+void ERR_load_PKCS11_strings(void)
+{
+ static int init = 1;
+
+ if (init) {
+ init = 0;
+#ifndef NO_ERR
+ ERR_load_strings(0, PKCS11_str_library);
+ ERR_load_strings(ERR_LIB_PKCS11, PKCS11_str_functs);
+ ERR_load_strings(ERR_LIB_PKCS11, PKCS11_str_reasons);
+#endif
+ }
+}
diff --git a/src/p11_key.c b/src/p11_key.c
new file mode 100644
index 0000000..f6785e0
--- /dev/null
+++ b/src/p11_key.c
@@ -0,0 +1,495 @@
+/* libp11, a simple layer on to of PKCS#11 API
+ * Copyright (C) 2005 Olaf Kirch <okir at lst.de>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include <string.h>
+#include "libp11-int.h"
+
+#ifdef _WIN32
+#define strncasecmp strnicmp
+#endif
+
+static int pkcs11_find_keys(PKCS11_TOKEN *, unsigned int);
+static int pkcs11_next_key(PKCS11_CTX * ctx, PKCS11_TOKEN * token,
+ CK_SESSION_HANDLE session, CK_OBJECT_CLASS type);
+static int pkcs11_init_key(PKCS11_CTX * ctx, PKCS11_TOKEN * token,
+ CK_SESSION_HANDLE session, CK_OBJECT_HANDLE o,
+ CK_OBJECT_CLASS type, PKCS11_KEY **);
+static int pkcs11_store_private_key(PKCS11_TOKEN *, EVP_PKEY *, char *,
+ unsigned char *, unsigned int, PKCS11_KEY **);
+static int pkcs11_store_public_key(PKCS11_TOKEN *, EVP_PKEY *, char *,
+ unsigned char *, unsigned int, PKCS11_KEY **);
+static int hex_to_bin(const char *in, unsigned char *out, size_t * outlen);
+
+static CK_OBJECT_CLASS key_search_class;
+static CK_ATTRIBUTE key_search_attrs[] = {
+ {CKA_CLASS, &key_search_class, sizeof(key_search_class)},
+};
+#define numof(arr) (sizeof(arr)/sizeof((arr)[0]))
+#define MAX_VALUE_LEN 200
+
+/*
+ * Enumerate all keys on the card
+ * For now, we enumerate just the private keys.
+ */
+int
+PKCS11_enumerate_keys(PKCS11_TOKEN * token, PKCS11_KEY ** keyp, unsigned int *countp)
+{
+ PKCS11_TOKEN_private *priv = PRIVTOKEN(token);
+
+ if (priv->nkeys < 0) {
+ priv->nkeys = 0;
+ if (pkcs11_find_keys(token, CKO_PRIVATE_KEY)) {
+ pkcs11_destroy_keys(token);
+ return -1;
+ }
+ priv->nprkeys = priv->nkeys;
+ if (pkcs11_find_keys(token, CKO_PUBLIC_KEY)) {
+ pkcs11_destroy_keys(token);
+ return -1;
+ }
+ }
+ *keyp = priv->keys;
+ *countp = priv->nprkeys;
+ return 0;
+}
+
+/*
+ * Find key matching a certificate
+ */
+PKCS11_KEY *PKCS11_find_key(PKCS11_CERT *cert)
+{
+ PKCS11_CERT_private *cpriv;
+ PKCS11_KEY_private *kpriv;
+ PKCS11_KEY *key;
+ unsigned int n, count;
+
+ cpriv = PRIVCERT(cert);
+ if (PKCS11_enumerate_keys(CERT2TOKEN(cert), &key, &count))
+ return NULL;
+ for (n = 0; n < count; n++, key++) {
+ kpriv = PRIVKEY(key);
+ if (cpriv->id_len == kpriv->id_len
+ && !memcmp(cpriv->id, kpriv->id, cpriv->id_len))
+ return key;
+ }
+ return NULL;
+}
+
+/*
+ * Store a private key on the token
+ */
+int PKCS11_store_private_key(PKCS11_TOKEN * token, EVP_PKEY * pk, char *label)
+{
+ if (pkcs11_store_private_key(token, pk, label, NULL, 0, NULL))
+ return -1;
+ return 0;
+}
+
+/*
+ * Generate and store a private key on the token
+ * FIXME: We should check first whether the token supports
+ * on-board key generation, and if it does, use its own algorithm
+ */
+int
+PKCS11_generate_key(PKCS11_TOKEN * token,
+ int algorithm, unsigned int bits, char *label)
+{
+ PKCS11_KEY *key_obj;
+ EVP_PKEY *pk;
+ RSA *rsa;
+ BIO *err;
+ int rc;
+
+ if (algorithm != EVP_PKEY_RSA) {
+ PKCS11err(PKCS11_F_PKCS11_GENERATE_KEY, PKCS11_NOT_SUPPORTED);
+ return -1;
+ }
+
+ err = BIO_new_fp(stderr, BIO_NOCLOSE);
+ rsa = RSA_generate_key(bits, 0x10001, NULL, err);
+ BIO_free(err);
+ if (rsa == NULL) {
+ PKCS11err(PKCS11_F_PKCS11_GENERATE_KEY, PKCS11_KEYGEN_FAILED);
+ return -1;
+ }
+
+ pk = EVP_PKEY_new();
+ EVP_PKEY_assign_RSA(pk, rsa);
+ rc = pkcs11_store_private_key(token, pk, label, NULL, 0, &key_obj);
+
+ if (rc == 0) {
+ PKCS11_KEY_private *kpriv;
+
+ kpriv = PRIVKEY(key_obj);
+ rc = pkcs11_store_public_key(token, pk, label,
+ kpriv->id, kpriv->id_len, NULL);
+ }
+ EVP_PKEY_free(pk);
+ return rc;
+}
+
+/*
+ * Get the key type
+ */
+int PKCS11_get_key_type(PKCS11_KEY * key)
+{
+ PKCS11_KEY_private *priv = PRIVKEY(key);
+
+ return priv->ops->type;
+}
+
+/*
+ * Create a key object that will allow an OpenSSL application
+ * to use the token via an EVP_PKEY
+ */
+EVP_PKEY *PKCS11_get_private_key(PKCS11_KEY * key)
+{
+ PKCS11_KEY_private *priv = PRIVKEY(key);
+ EVP_PKEY *pk;
+
+ pk = EVP_PKEY_new();
+ if (priv->ops->get_private(key, pk)
+ || priv->ops->get_public(key, pk)) {
+ EVP_PKEY_free(pk);
+ return NULL;
+ }
+ key->evp_key = pk;
+ return pk;
+}
+
+EVP_PKEY *PKCS11_get_public_key(PKCS11_KEY * key)
+{
+ return PKCS11_get_private_key(key);
+}
+
+
+/*
+ * Find all keys of a given type (public or private)
+ */
+int pkcs11_find_keys(PKCS11_TOKEN * token, unsigned int type)
+{
+ PKCS11_SLOT *slot = TOKEN2SLOT(token);
+ PKCS11_CTX *ctx = TOKEN2CTX(token);
+ CK_SESSION_HANDLE session;
+ int rv, res = -1;
+
+ /* Make sure we have a session */
+ if (!PRIVSLOT(slot)->haveSession && PKCS11_open_session(slot, 0))
+ return -1;
+ session = PRIVSLOT(slot)->session;
+
+ /* Tell the PKCS11 lib to enumerate all matching objects */
+ key_search_class = type;
+ rv = CRYPTOKI_call(ctx, C_FindObjectsInit(session, key_search_attrs,
+ numof(key_search_attrs)));
+ CRYPTOKI_checkerr(PKCS11_F_PKCS11_ENUM_KEYS, rv);
+
+ do {
+ res = pkcs11_next_key(ctx, token, session, type);
+ } while (res == 0);
+
+ CRYPTOKI_call(ctx, C_FindObjectsFinal(session));
+ return (res < 0) ? -1 : 0;
+}
+
+int
+pkcs11_next_key(PKCS11_CTX * ctx, PKCS11_TOKEN * token,
+ CK_SESSION_HANDLE session, CK_OBJECT_CLASS type)
+{
+ CK_OBJECT_HANDLE obj;
+ CK_ULONG count;
+ int rv;
+
+ /* Get the next matching object */
+ rv = CRYPTOKI_call(ctx, C_FindObjects(session, &obj, 1, &count));
+ CRYPTOKI_checkerr(PKCS11_F_PKCS11_ENUM_KEYS, rv);
+
+ if (count == 0)
+ return 1;
+
+ if (pkcs11_init_key(ctx, token, session, obj, type, NULL))
+ return -1;
+
+ return 0;
+}
+
+int
+pkcs11_init_key(PKCS11_CTX * ctx, PKCS11_TOKEN * token,
+ CK_SESSION_HANDLE session, CK_OBJECT_HANDLE obj,
+ CK_OBJECT_CLASS type, PKCS11_KEY ** ret)
+{
+ PKCS11_TOKEN_private *tpriv;
+ PKCS11_KEY_private *kpriv;
+ PKCS11_KEY *key, *tmp;
+ char label[256];
+ unsigned char id[256];
+ CK_KEY_TYPE key_type;
+ PKCS11_KEY_ops *ops;
+ size_t size;
+
+ size = sizeof(key_type);
+ if (pkcs11_getattr_var(token, obj, CKA_KEY_TYPE, &key_type, &size))
+ return -1;
+
+ switch (key_type) {
+ case CKK_RSA:
+ ops = &pkcs11_rsa_ops;
+ break;
+ default:
+ /* Ignore any keys we don't understand */
+ return 0;
+ }
+
+ tpriv = PRIVTOKEN(token);
+ tmp = (PKCS11_KEY *) OPENSSL_realloc(tpriv->keys,
+ (tpriv->nkeys + 1) * sizeof(PKCS11_KEY));
+ if (!tmp) {
+ free(tpriv->keys);
+ tpriv->keys = NULL;
+ return -1;
+ }
+ tpriv->keys = tmp;
+
+ key = tpriv->keys + tpriv->nkeys++;
+ memset(key, 0, sizeof(*key));
+ key->_private = kpriv = PKCS11_NEW(PKCS11_KEY_private);
+ kpriv->object = obj;
+ kpriv->parent = token;
+
+ if (!pkcs11_getattr_s(token, obj, CKA_LABEL, label, sizeof(label)))
+ key->label = BUF_strdup(label);
+ key->id_len = sizeof(id);
+ if (!pkcs11_getattr_var(token, obj, CKA_ID, id, (size_t *) & key->id_len)) {
+ key->id = (unsigned char *) malloc(key->id_len);
+ memcpy(key->id, id, key->id_len);
+ }
+ key->isPrivate = (type == CKO_PRIVATE_KEY);
+
+ /* Initialize internal information */
+ kpriv->id_len = sizeof(kpriv->id);
+ if (pkcs11_getattr_var(token, obj, CKA_ID, kpriv->id, &kpriv->id_len))
+ kpriv->id_len = 0;
+ kpriv->ops = ops;
+
+ if (ret)
+ *ret = key;
+ return 0;
+}
+
+/*
+ * Destroy all keys
+ */
+void pkcs11_destroy_keys(PKCS11_TOKEN * token)
+{
+ PKCS11_TOKEN_private *priv = PRIVTOKEN(token);
+
+ while (priv->nkeys > 0) {
+ PKCS11_KEY *key = &priv->keys[--(priv->nkeys)];
+
+ if (key->evp_key)
+ EVP_PKEY_free(key->evp_key);
+ OPENSSL_free(key->label);
+ if (key->id)
+ free(key->id);
+ }
+ if (priv->keys)
+ OPENSSL_free(priv->keys);
+ priv->nprkeys = -1;
+ priv->nkeys = -1;
+ priv->keys = NULL;
+}
+
+/*
+ * Store private key
+ */
+int
+pkcs11_store_private_key(PKCS11_TOKEN * token, EVP_PKEY * pk, char *label,
+ unsigned char *id, unsigned int id_len,
+ PKCS11_KEY ** ret_key)
+{
+ PKCS11_SLOT *slot = TOKEN2SLOT(token);
+ PKCS11_CTX *ctx = TOKEN2CTX(token);
+ CK_SESSION_HANDLE session;
+ CK_OBJECT_HANDLE object;
+ CK_ATTRIBUTE attrs[32];
+ unsigned int n = 0;
+ int rv;
+
+ /* First, make sure we have a session */
+ if (!PRIVSLOT(slot)->haveSession && PKCS11_open_session(slot, 1))
+ return -1;
+ session = PRIVSLOT(slot)->session;
+
+ /* Now build the key attrs */
+ if (pk->type == EVP_PKEY_RSA) {
+ RSA *rsa = EVP_PKEY_get1_RSA(pk);
+
+ pkcs11_addattr_int(attrs + n++, CKA_CLASS, CKO_PRIVATE_KEY);
+ pkcs11_addattr_int(attrs + n++, CKA_KEY_TYPE, CKK_RSA);
+ pkcs11_addattr_bn(attrs + n++, CKA_MODULUS, rsa->n);
+ pkcs11_addattr_bn(attrs + n++, CKA_PUBLIC_EXPONENT, rsa->e);
+ pkcs11_addattr_bn(attrs + n++, CKA_PRIVATE_EXPONENT, rsa->d);
+ pkcs11_addattr_bn(attrs + n++, CKA_PRIME_1, rsa->p);
+ pkcs11_addattr_bn(attrs + n++, CKA_PRIME_2, rsa->q);
+ if (label)
+ pkcs11_addattr_s(attrs + n++, CKA_LABEL, label);
+ if (id && id_len)
+ pkcs11_addattr(attrs + n++, CKA_ID, id, id_len);
+ } else {
+ PKCS11err(PKCS11_F_PKCS11_STORE_PRIVATE_KEY, PKCS11_NOT_SUPPORTED);
+ return -1;
+ }
+
+ /* Now call the pkcs11 module to create the object */
+ rv = CRYPTOKI_call(ctx, C_CreateObject(session, attrs, n, &object));
+
+ /* Zap all memory allocated when building the template */
+ pkcs11_zap_attrs(attrs, n);
+
+ CRYPTOKI_checkerr(PKCS11_F_PKCS11_STORE_PRIVATE_KEY, rv);
+
+ /* Gobble the key object */
+ return pkcs11_init_key(ctx, token, session, object,
+ CKO_PRIVATE_KEY, ret_key);
+}
+
+/*
+ * Store public key
+ */
+int
+pkcs11_store_public_key(PKCS11_TOKEN * token, EVP_PKEY * pk, char *label,
+ unsigned char *id, unsigned int id_len,
+ PKCS11_KEY ** ret_key)
+{
+ PKCS11_SLOT *slot = TOKEN2SLOT(token);
+ PKCS11_CTX *ctx = TOKEN2CTX(token);
+ CK_SESSION_HANDLE session;
+ CK_OBJECT_HANDLE object;
+ CK_ATTRIBUTE attrs[32];
+ unsigned int n = 0;
+ int rv;
+
+ /* First, make sure we have a session */
+ if (!PRIVSLOT(slot)->haveSession && PKCS11_open_session(slot, 1))
+ return -1;
+ session = PRIVSLOT(slot)->session;
+
+ /* Now build the key attrs */
+ if (pk->type == EVP_PKEY_RSA) {
+ RSA *rsa = EVP_PKEY_get1_RSA(pk);
+
+ pkcs11_addattr_int(attrs + n++, CKA_CLASS, CKO_PUBLIC_KEY);
+ pkcs11_addattr_int(attrs + n++, CKA_KEY_TYPE, CKK_RSA);
+ pkcs11_addattr_bn(attrs + n++, CKA_MODULUS, rsa->n);
+ pkcs11_addattr_bn(attrs + n++, CKA_PUBLIC_EXPONENT, rsa->e);
+ if (label)
+ pkcs11_addattr_s(attrs + n++, CKA_LABEL, label);
+ if (id && id_len)
+ pkcs11_addattr(attrs + n++, CKA_ID, id, id_len);
+ } else {
+ PKCS11err(PKCS11_F_PKCS11_STORE_PUBLIC_KEY, PKCS11_NOT_SUPPORTED);
+ return -1;
+ }
+
+ /* Now call the pkcs11 module to create the object */
+ rv = CRYPTOKI_call(ctx, C_CreateObject(session, attrs, n, &object));
+
+ /* Zap all memory allocated when building the template */
+ pkcs11_zap_attrs(attrs, n);
+
+ CRYPTOKI_checkerr(PKCS11_F_PKCS11_STORE_PUBLIC_KEY, rv);
+
+ /* Gobble the key object */
+ return pkcs11_init_key(ctx, token, session, object, CKO_PUBLIC_KEY, ret_key);
+}
+int PKCS11_get_key_modulus(PKCS11_KEY * key, BIGNUM **bn)
+{
+
+ if (pkcs11_getattr_bn(KEY2TOKEN(key), PRIVKEY(key)->object, CKA_MODULUS, bn))
+ return 0;
+ return 1;
+}
+int PKCS11_get_key_exponent(PKCS11_KEY * key, BIGNUM **bn)
+{
+
+ if (pkcs11_getattr_bn(KEY2TOKEN(key), PRIVKEY(key)->object, CKA_PUBLIC_EXPONENT, bn))
+ return 0;
+ return 1;
+}
+
+
+int PKCS11_get_key_size(PKCS11_KEY * key)
+{
+ BIGNUM* n;
+ int numbytes=0;
+ n=BN_new();
+ if(key_getattr_bn(key, CKA_MODULUS, &n))
+ return 0;
+ numbytes=BN_num_bytes(n);
+ BN_free(n);
+ return numbytes;
+}
+
+
+static int hex_to_bin(const char *in, unsigned char *out, size_t * outlen)
+{
+ size_t left, count = 0;
+
+ if (in == NULL || *in == '\0') {
+ *outlen = 0;
+ return 1;
+ }
+
+ left = *outlen;
+
+ while (*in != '\0') {
+ int byte = 0, nybbles = 2;
+ char c;
+
+ while (nybbles-- && *in && *in != ':') {
+ byte <<= 4;
+ c = *in++;
+ if ('0' <= c && c <= '9')
+ c -= '0';
+ else if ('a' <= c && c <= 'f')
+ c = c - 'a' + 10;
+ else if ('A' <= c && c <= 'F')
+ c = c - 'A' + 10;
+ else {
+ fprintf(stderr,"hex_to_bin(): invalid char '%c' in hex string\n", c);
+ *outlen = 0;
+ return 0;
+ }
+ byte |= c;
+ }
+ if (*in == ':')
+ in++;
+ if (left <= 0) {
+ fprintf(stderr,"hex_to_bin(): hex string too long");
+ *outlen = 0;
+ return 0;
+ }
+ out[count++] = (unsigned char) byte;
+ left--;
+ c++;
+ }
+
+ *outlen = count;
+ return 1;
+}
+
diff --git a/src/p11_load.c b/src/p11_load.c
new file mode 100644
index 0000000..222ce9c
--- /dev/null
+++ b/src/p11_load.c
@@ -0,0 +1,111 @@
+/* libp11, a simple layer on to of PKCS#11 API
+ * Copyright (C) 2005 Olaf Kirch <okir at lst.de>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include <string.h>
+#include "libp11-int.h"
+
+static void *handle = NULL;
+
+/*
+ * Create a new context
+ */
+PKCS11_CTX *PKCS11_CTX_new(void)
+{
+ PKCS11_CTX_private *priv;
+ PKCS11_CTX *ctx;
+
+ /* Load error strings */
+ ERR_load_PKCS11_strings();
+
+ priv = PKCS11_NEW(PKCS11_CTX_private);
+ ctx = PKCS11_NEW(PKCS11_CTX);
+ ctx->_private = priv;
+
+ /* Mark list of slots as "need to fetch from card" */
+ priv->nslots = -1;
+
+ return ctx;
+}
+
+/*
+ * Load the shared library, and initialize it.
+ */
+int PKCS11_CTX_load(PKCS11_CTX * ctx, const char *name)
+{
+ PKCS11_CTX_private *priv = PRIVCTX(ctx);
+ CK_INFO ck_info;
+ int rv;
+
+ if (priv->libinfo != NULL) {
+ PKCS11err(PKCS11_F_PKCS11_CTX_LOAD, PKCS11_MODULE_LOADED_ERROR);
+ return -1;
+ }
+ handle = C_LoadModule(name, &priv->method);
+ if (!handle) {
+ PKCS11err(PKCS11_F_PKCS11_CTX_LOAD, PKCS11_LOAD_MODULE_ERROR);
+ return -1;
+ }
+
+ /* Tell the PKCS11 to initialize itself */
+ rv = priv->method->C_Initialize(NULL);
+ CRYPTOKI_checkerr(PKCS11_F_PKCS11_CTX_LOAD, rv);
+
+ /* Get info on the library */
+ rv = priv->method->C_GetInfo(&ck_info);
+ CRYPTOKI_checkerr(PKCS11_F_PKCS11_CTX_LOAD, rv);
+
+ ctx->manufacturer = PKCS11_DUP(ck_info.manufacturerID);
+ ctx->description = PKCS11_DUP(ck_info.libraryDescription);
+
+ return 0;
+}
+
+/*
+ * Unload the shared library
+ */
+void PKCS11_CTX_unload(PKCS11_CTX * ctx)
+{
+ PKCS11_CTX_private *priv;
+ priv = PRIVCTX(ctx);
+
+ /* Free any slot info we have allocated */
+ pkcs11_destroy_all_slots(ctx);
+
+ /* Tell the PKCS11 library to shut down */
+ priv->method->C_Finalize(NULL);
+
+ /* Unload the module */
+ C_UnloadModule(handle);
+}
+
+/*
+ * Free a context
+ */
+void PKCS11_CTX_free(PKCS11_CTX * ctx)
+{
+ /* Do not remove the strings since OpenSSL strings may still be used by
+ * the application and we can't know
+
+ ERR_free_strings();
+ ERR_remove_state(0);
+ */
+ OPENSSL_free(ctx->manufacturer);
+ OPENSSL_free(ctx->description);
+ OPENSSL_free(ctx->_private);
+ OPENSSL_free(ctx);
+}
diff --git a/src/p11_misc.c b/src/p11_misc.c
new file mode 100644
index 0000000..471d258
--- /dev/null
+++ b/src/p11_misc.c
@@ -0,0 +1,62 @@
+/* libp11, a simple layer on to of PKCS#11 API
+ * Copyright (C) 2005 Olaf Kirch <okir at lst.de>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include <string.h>
+#include <openssl/crypto.h>
+#include "libp11-int.h"
+
+void *pkcs11_malloc(size_t size)
+{
+ void *p = OPENSSL_malloc(size);
+ if (p == NULL)
+ return NULL;
+ memset(p, 0, size);
+ return p;
+}
+
+/* PKCS11 strings are fixed size blank padded,
+ * so when strduping them we must make sure
+ * we stop at the end of the buffer, and while we're
+ * at it it's nice to remove the padding */
+char *pkcs11_strdup(char *mem, size_t size)
+{
+ char *res;
+
+ while (size && mem[size - 1] == ' ')
+ size--;
+ res = (char *) OPENSSL_malloc(size + 1);
+ if (res == NULL)
+ return NULL;
+ memcpy(res, mem, size);
+ res[size] = '\0';
+ return res;
+}
+
+/*
+ * Dup memory
+ */
+void *memdup(const void *src, size_t size)
+{
+ void *dst;
+
+ dst = malloc(size);
+ if (dst == NULL)
+ return NULL;
+ memcpy(dst, src, size);
+ return dst;
+}
diff --git a/src/p11_ops.c b/src/p11_ops.c
new file mode 100644
index 0000000..2dd9f06
--- /dev/null
+++ b/src/p11_ops.c
@@ -0,0 +1,161 @@
+/* libp11, a simple layer on to of PKCS#11 API
+ * Copyright (C) 2005 Olaf Kirch <okir at lst.de>
+ * Copyright (C) 2005 Kevin Stefanik <kstef at mtppi.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+
+/* this file does certain cryptographic operations via the pkcs11 library */
+
+#include <string.h>
+#include "libp11-int.h"
+
+int
+PKCS11_sign(int type, const unsigned char *m, unsigned int m_len,
+ unsigned char *sigret, unsigned int *siglen, const PKCS11_KEY * key)
+{
+
+ PKCS11_KEY_private *priv;
+ PKCS11_SLOT *slot;
+ PKCS11_CTX *ctx;
+ CK_SESSION_HANDLE session;
+ CK_MECHANISM mechanism;
+ int rv, ssl = ((type == NID_md5_sha1) ? 1 : 0);
+ unsigned char *encoded = NULL;
+ int sigsize;
+ CK_ULONG ck_sigsize;
+
+ if (key == NULL)
+ return 0;
+ ctx = KEY2CTX(key);
+ priv = PRIVKEY(key);
+ slot = TOKEN2SLOT(priv->parent);
+ session = PRIVSLOT(slot)->session;
+
+ sigsize=PKCS11_get_key_size(key);
+ ck_sigsize=sigsize;
+
+ if (ssl) {
+ if((m_len != 36) /* SHA1 + MD5 */ ||
+ ((m_len + RSA_PKCS1_PADDING) > sigsize)) {
+ return(0); /* the size is wrong */
+ }
+ } else {
+ ASN1_TYPE parameter = { V_ASN1_NULL, { NULL } };
+ ASN1_STRING digest = { m_len, V_ASN1_OCTET_STRING, (unsigned char *)m };
+ X509_ALGOR algor = { NULL, ¶meter };
+ X509_SIG digest_info = { &algor, &digest };
+ int size;
+ /* Fetch the OID of the algorithm used */
+ if((algor.algorithm = OBJ_nid2obj(type)) &&
+ (algor.algorithm->length) &&
+ /* Get the size of the encoded DigestInfo */
+ (size = i2d_X509_SIG(&digest_info, NULL)) &&
+ /* Check that size is compatible with PKCS#11 padding */
+ (size + RSA_PKCS1_PADDING <= sigsize) &&
+ (encoded = (unsigned char *) malloc(sigsize))) {
+ unsigned char *tmp = encoded;
+ /* Actually do the encoding */
+ i2d_X509_SIG(&digest_info,&tmp);
+ m = encoded;
+ m_len = size;
+ } else {
+ return(0);
+ }
+ }
+
+ memset(&mechanism, 0, sizeof(mechanism));
+ mechanism.mechanism = CKM_RSA_PKCS;
+
+ /* API is somewhat fishy here. *siglen is 0 on entry (cleared
+ * by OpenSSL). The library assumes that the memory passed
+ * by the caller is always big enough */
+ if((rv = CRYPTOKI_call(ctx, C_SignInit
+ (session, &mechanism, priv->object))) == 0) {
+ rv = CRYPTOKI_call(ctx, C_Sign
+ (session, (CK_BYTE *) m, m_len,
+ sigret, &ck_sigsize));
+ }
+ *siglen = ck_sigsize;
+ free(encoded);
+
+ if (rv) {
+ PKCS11err(PKCS11_F_PKCS11_RSA_SIGN, pkcs11_map_err(rv));
+ }
+ return (rv) ? 0 : 1;
+}
+
+
+int
+PKCS11_private_encrypt(int flen, const unsigned char *from, unsigned char *to,
+ const PKCS11_KEY * rsa, int padding)
+{
+ /* PKCS11 calls go here */
+ PKCS11err(PKCS11_F_PKCS11_RSA_ENCRYPT, PKCS11_NOT_SUPPORTED);
+ return -1;
+}
+
+int
+PKCS11_private_decrypt(int flen, const unsigned char *from, unsigned char *to,
+ PKCS11_KEY * key, int padding)
+{
+ CK_RV rv;
+ PKCS11_KEY_private *priv;
+ PKCS11_SLOT *slot;
+ PKCS11_CTX *ctx;
+ CK_SESSION_HANDLE session;
+ CK_MECHANISM mechanism;
+ CK_ULONG size;
+
+ if (padding != RSA_PKCS1_PADDING) {
+ printf("pkcs11 engine: only RSA_PKCS1_PADDING allowed so far\n");
+ return -1;
+ }
+ if (key == NULL)
+ return -1;
+
+ /* PKCS11 calls go here */
+
+ ctx = KEY2CTX(key);
+ priv = PRIVKEY(key);
+ slot = TOKEN2SLOT(priv->parent);
+ session = PRIVSLOT(slot)->session;
+ memset(&mechanism, 0, sizeof(mechanism));
+ mechanism.mechanism = CKM_RSA_PKCS;
+
+ if( (rv = CRYPTOKI_call(ctx, C_DecryptInit(session, &mechanism, priv->object))) == 0) {
+ rv = CRYPTOKI_call(ctx, C_Decrypt
+ (session, (CK_BYTE *) from, (CK_ULONG)flen,
+ (CK_BYTE_PTR)to, &size));
+ }
+
+ if (rv) {
+ PKCS11err(PKCS11_F_PKCS11_RSA_DECRYPT, pkcs11_map_err(rv));
+ }
+
+ return (rv) ? 0 : size;
+}
+
+int
+PKCS11_verify(int type, const unsigned char *m, unsigned int m_len,
+ unsigned char *signature, unsigned int siglen, PKCS11_KEY * key)
+{
+
+ /* PKCS11 calls go here */
+ PKCS11err(PKCS11_F_PKCS11_RSA_VERIFY, PKCS11_NOT_SUPPORTED);
+ return -1;
+}
+
diff --git a/src/p11_rsa.c b/src/p11_rsa.c
new file mode 100644
index 0000000..c392958
--- /dev/null
+++ b/src/p11_rsa.c
@@ -0,0 +1,153 @@
+/* libp11, a simple layer on to of PKCS#11 API
+ * Copyright (C) 2005 Olaf Kirch <okir at lst.de>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+/*
+ * This file implements the handling of RSA keys stored on a
+ * PKCS11 token
+ */
+
+#include <string.h>
+#include <openssl/evp.h>
+#include <openssl/rsa.h>
+#include "libp11-int.h"
+
+static int pkcs11_get_rsa_public(PKCS11_KEY *, EVP_PKEY *);
+static int pkcs11_get_rsa_private(PKCS11_KEY *, EVP_PKEY *);
+RSA_METHOD *pkcs11_get_rsa_method(void);
+
+
+/*
+ * Get RSA key material
+ */
+int pkcs11_get_rsa_private(PKCS11_KEY * key, EVP_PKEY * pk)
+{
+ CK_BBOOL sensitive, extractable;
+ RSA *rsa;
+
+ if (!(rsa = EVP_PKEY_get1_RSA(pk))) {
+ ERR_clear_error(); /* the above flags an error */
+ rsa = RSA_new();
+ EVP_PKEY_set1_RSA(pk, rsa);
+ }
+
+ if (key_getattr(key, CKA_SENSITIVE, &sensitive, sizeof(sensitive))
+ || key_getattr(key, CKA_EXTRACTABLE, &extractable, sizeof(extractable)))
+ return -1;
+
+ if (!rsa->n && key_getattr_bn(key, CKA_MODULUS, &rsa->n))
+ return -1;
+ if (!rsa->e && key_getattr_bn(key, CKA_PUBLIC_EXPONENT, &rsa->e))
+ return -1;
+
+ /* If the key is not extractable, create a key object
+ * that will use the card's functions to sign & decrypt */
+ if (sensitive || !extractable) {
+ RSA_set_method(rsa, pkcs11_get_rsa_method());
+ rsa->flags |= RSA_FLAG_SIGN_VER;
+ RSA_set_app_data(rsa, key);
+ return 0;
+ }
+
+ /* TBD - extract RSA private key. */
+ /* In the mean time let's use the card anyway */
+ RSA_set_method(rsa, pkcs11_get_rsa_method());
+ rsa->flags |= RSA_FLAG_SIGN_VER;
+ RSA_set_app_data(rsa, key);
+ return 0;
+ /*
+ PKCS11err(PKCS11_F_PKCS11_GET_KEY, PKCS11_NOT_SUPPORTED);
+ return -1;
+ */
+}
+
+int pkcs11_get_rsa_public(PKCS11_KEY * key, EVP_PKEY * pk)
+{
+ /* TBD */
+ return 0;
+/* return pkcs11_get_rsa_private(key,pk);*/
+}
+
+
+static int
+pkcs11_rsa_decrypt(int flen, const unsigned char *from, unsigned char *to,
+ RSA * rsa, int padding)
+{
+
+ return PKCS11_private_decrypt( flen, from, to, (PKCS11_KEY *) RSA_get_app_data(rsa), padding);
+}
+
+static int
+pkcs11_rsa_encrypt(int flen, const unsigned char *from, unsigned char *to,
+ RSA * rsa, int padding)
+{
+ return PKCS11_private_encrypt(flen,from,to,(PKCS11_KEY *) RSA_get_app_data(rsa), padding);
+}
+
+static int
+pkcs11_rsa_sign(int type, const unsigned char *m, unsigned int m_len,
+ unsigned char *sigret, unsigned int *siglen, const RSA * rsa)
+{
+
+ return PKCS11_sign(type,m,m_len,sigret,siglen,(PKCS11_KEY *) RSA_get_app_data(rsa));
+}
+/* Lousy hack alert. If RSA_verify detects that the key has the
+ * RSA_FLAG_SIGN_VER flags set, it will assume that verification
+ * is implemented externally as well.
+ * We work around this by temporarily cleaning the flag, and
+ * calling RSA_verify once more.
+ */
+static int
+pkcs11_rsa_verify(int type, const unsigned char *m, unsigned int m_len,
+ unsigned char *signature, unsigned int siglen, const RSA * rsa)
+{
+ RSA *r = (RSA *) rsa; /* Ugly hack to get rid of compiler warning */
+ int res;
+
+ if (r->flags & RSA_FLAG_SIGN_VER) {
+ r->flags &= ~RSA_FLAG_SIGN_VER;
+ res = RSA_verify(type, m, m_len, signature, siglen, r);
+ r->flags |= RSA_FLAG_SIGN_VER;
+ } else {
+ PKCS11err(PKCS11_F_PKCS11_RSA_VERIFY, PKCS11_NOT_SUPPORTED);
+ res = 0;
+ }
+ return res;
+}
+
+/*
+ * Overload the default OpenSSL methods for RSA
+ */
+RSA_METHOD *pkcs11_get_rsa_method(void)
+{
+ static RSA_METHOD ops;
+
+ if (!ops.rsa_priv_enc) {
+ ops = *RSA_get_default_method();
+ ops.rsa_priv_enc = pkcs11_rsa_encrypt;
+ ops.rsa_priv_dec = pkcs11_rsa_decrypt;
+ ops.rsa_sign = pkcs11_rsa_sign;
+ ops.rsa_verify = pkcs11_rsa_verify;
+ }
+ return &ops;
+}
+
+PKCS11_KEY_ops pkcs11_rsa_ops = {
+ EVP_PKEY_RSA,
+ pkcs11_get_rsa_public,
+ pkcs11_get_rsa_private
+};
diff --git a/src/p11_slot.c b/src/p11_slot.c
new file mode 100644
index 0000000..7fc5be5
--- /dev/null
+++ b/src/p11_slot.c
@@ -0,0 +1,383 @@
+/* libp11, a simple layer on to of PKCS#11 API
+ * Copyright (C) 2005 Olaf Kirch <okir at lst.de>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include <string.h>
+#include <openssl/buffer.h>
+#include "libp11-int.h"
+
+static int pkcs11_init_slot(PKCS11_CTX *, PKCS11_SLOT *, CK_SLOT_ID);
+static int pkcs11_check_token(PKCS11_CTX *, PKCS11_SLOT *);
+static void pkcs11_destroy_token(PKCS11_TOKEN *);
+
+/*
+ * Enumerate slots
+ */
+int
+PKCS11_enumerate_slots(PKCS11_CTX * ctx, PKCS11_SLOT ** slotp, unsigned int *countp)
+{
+ PKCS11_CTX_private *priv = PRIVCTX(ctx);
+
+ if (priv->nslots < 0) {
+ CK_SLOT_ID slotid[64];
+ CK_ULONG nslots = sizeof(slotid), n;
+ PKCS11_SLOT *slots;
+ int rv;
+
+ rv = priv->method->C_GetSlotList(FALSE, slotid, &nslots);
+ CRYPTOKI_checkerr(PKCS11_F_PKCS11_ENUM_SLOTS, rv);
+
+ slots = (PKCS11_SLOT *) pkcs11_malloc(nslots * sizeof(PKCS11_SLOT));
+ for (n = 0; n < nslots; n++) {
+ if (pkcs11_init_slot(ctx, &slots[n], slotid[n])) {
+ while (n--)
+ pkcs11_destroy_slot(ctx, slots + n);
+ OPENSSL_free(slots);
+ return -1;
+ }
+ }
+ priv->nslots = nslots;
+ priv->slots = slots;
+ }
+
+ *slotp = priv->slots;
+ *countp = priv->nslots;
+ return 0;
+}
+
+/*
+ * Find a slot with a token that looks "valuable"
+ */
+PKCS11_SLOT *PKCS11_find_token(PKCS11_CTX * ctx)
+{
+ PKCS11_SLOT *slot_list, *slot, *best;
+ PKCS11_TOKEN *tok;
+ unsigned int n, nslots;
+
+ if (PKCS11_enumerate_slots(ctx, &slot_list, &nslots))
+ return NULL;
+
+ best = NULL;
+ for (n = 0, slot = slot_list; n < nslots; n++, slot++) {
+ if ((tok = slot->token) != NULL) {
+ if (best == NULL
+ || (tok->initialized > best->token->initialized
+ && tok->userPinSet > best->token->userPinSet
+ && tok->loginRequired > best->token->loginRequired))
+ best = slot;
+ }
+ }
+ return best;
+}
+
+/*
+ * Open a session with this slot
+ */
+int PKCS11_open_session(PKCS11_SLOT * slot, int rw)
+{
+ PKCS11_SLOT_private *priv = PRIVSLOT(slot);
+ PKCS11_CTX *ctx = SLOT2CTX(slot);
+ int rv;
+
+ if (priv->haveSession) {
+ CRYPTOKI_call(ctx, C_CloseSession(priv->session));
+ priv->haveSession = 0;
+ }
+ rv = CRYPTOKI_call(ctx,
+ C_OpenSession(priv->id,
+ CKF_SERIAL_SESSION | (rw ? CKF_RW_SESSION :
+ 0), NULL, NULL,
+ &priv->session));
+ CRYPTOKI_checkerr(PKCS11_F_PKCS11_OPEN_SESSION, rv);
+ priv->haveSession = 1;
+
+ return 0;
+}
+
+/*
+ * Authenticate with the card
+ */
+int PKCS11_login(PKCS11_SLOT * slot, int so, const char *pin)
+{
+ PKCS11_SLOT_private *priv = PRIVSLOT(slot);
+ PKCS11_CTX *ctx = priv->parent;
+ int rv;
+
+ /* Calling PKCS11_login invalidates all cached
+ * keys we have */
+ if (slot->token)
+ pkcs11_destroy_keys(slot->token);
+ if (priv->loggedIn) {
+ /* already logged in, log out first */
+ if (PKCS11_logout(slot))
+ return -1;
+ }
+ if (!priv->haveSession) {
+ /* SO gets a r/w session by default,
+ * user gets a r/o session by default. */
+ if (PKCS11_open_session(slot, so))
+ return -1;
+ }
+
+ rv = CRYPTOKI_call(ctx, C_Login(priv->session,
+ so ? CKU_SO : CKU_USER,
+ (CK_UTF8CHAR *) pin, strlen(pin)));
+ CRYPTOKI_checkerr(PKCS11_F_PKCS11_LOGIN, rv);
+ priv->loggedIn = 1;
+ return 0;
+}
+
+/*
+ * Log out
+ */
+int PKCS11_logout(PKCS11_SLOT * slot)
+{
+ PKCS11_SLOT_private *priv = PRIVSLOT(slot);
+ PKCS11_CTX *ctx = priv->parent;
+ int rv;
+
+ /* Calling PKCS11_logout invalidates all cached
+ * keys we have */
+ if (slot->token)
+ pkcs11_destroy_keys(slot->token);
+ if (!priv->haveSession) {
+ PKCS11err(PKCS11_F_PKCS11_LOGOUT, PKCS11_NO_SESSION);
+ return -1;
+ }
+
+ rv = CRYPTOKI_call(ctx, C_Logout(priv->session));
+ CRYPTOKI_checkerr(PKCS11_F_PKCS11_LOGOUT, rv);
+ priv->loggedIn = 0;
+ return 0;
+}
+
+/*
+ * Initialize the token
+ */
+int PKCS11_init_token(PKCS11_TOKEN * token, const char *pin, const char *label)
+{
+ PKCS11_SLOT_private *priv = PRIVSLOT(TOKEN2SLOT(token));
+ PKCS11_CTX_private *cpriv;
+ PKCS11_CTX *ctx = priv->parent;
+ int n, rv;
+
+ if (!label)
+ label = "PKCS#11 Token";
+ rv = CRYPTOKI_call(ctx, C_InitToken(priv->id,
+ (CK_UTF8CHAR *) pin, strlen(pin),
+ (CK_UTF8CHAR *) label));
+ CRYPTOKI_checkerr(PKCS11_F_PKCS11_INIT_TOKEN, rv);
+
+ cpriv = PRIVCTX(ctx);
+ for (n = 0; n < cpriv->nslots; n++) {
+ if (pkcs11_check_token(ctx, cpriv->slots + n) < 0)
+ return -1;
+ }
+
+ return 0;
+}
+
+/*
+ * Set the User PIN
+ */
+int PKCS11_init_pin(PKCS11_TOKEN * token, const char *pin)
+{
+ PKCS11_SLOT_private *priv = PRIVSLOT(TOKEN2SLOT(token));
+ PKCS11_CTX *ctx = priv->parent;
+ int len, rv;
+
+ if (!priv->haveSession) {
+ PKCS11err(PKCS11_F_PKCS11_INIT_PIN, PKCS11_NO_SESSION);
+ return -1;
+ }
+
+ len = pin ? strlen(pin) : 0;
+ rv = CRYPTOKI_call(ctx, C_InitPIN(priv->session, (CK_UTF8CHAR *) pin, len));
+ CRYPTOKI_checkerr(PKCS11_F_PKCS11_INIT_PIN, rv);
+
+ return pkcs11_check_token(ctx, TOKEN2SLOT(token));
+}
+
+/*
+ * Change the User PIN
+ */
+int PKCS11_change_pin(PKCS11_SLOT * slot, const char *old_pin,
+ const char *new_pin)
+{
+ PKCS11_SLOT_private *priv = PRIVSLOT(slot);
+ PKCS11_CTX *ctx = priv->parent;
+ int old_len, new_len, rv;
+
+ if (!priv->haveSession) {
+ PKCS11err(PKCS11_F_PKCS11_CHANGE_PIN, PKCS11_NO_SESSION);
+ return -1;
+ }
+
+ old_len = old_pin ? strlen(old_pin) : 0;
+ new_len = new_pin ? strlen(new_pin) : 0;
+ rv = CRYPTOKI_call(ctx, C_SetPIN(priv->session, (CK_UTF8CHAR *) old_pin,
+ old_len, (CK_UTF8CHAR *) new_pin, new_len));
+ CRYPTOKI_checkerr(PKCS11_F_PKCS11_CHANGE_PIN, rv);
+
+ return pkcs11_check_token(ctx, slot);
+}
+
+/*
+ * Seed the random number generator
+ */
+int PKCS11_seed_random(PKCS11_SLOT *slot, const unsigned char *s,
+ unsigned int s_len)
+{
+ PKCS11_SLOT_private *priv = PRIVSLOT(slot);
+ PKCS11_CTX *ctx = priv->parent;
+ int rv;
+
+ if (!priv->haveSession && PKCS11_open_session(slot, 0)) {
+ PKCS11err(PKCS11_F_PKCS11_SEED_RANDOM, PKCS11_NO_SESSION);
+ return -1;
+ }
+
+ rv = CRYPTOKI_call(ctx, C_SeedRandom(priv->session, (CK_BYTE_PTR) s, s_len));
+ CRYPTOKI_checkerr(PKCS11_F_PKCS11_SEED_RANDOM, rv);
+
+ return pkcs11_check_token(ctx, slot);
+}
+
+/*
+ * Generate random numbers
+ */
+int PKCS11_generate_random(PKCS11_SLOT *slot, unsigned char *r,
+ unsigned int r_len)
+{
+ PKCS11_SLOT_private *priv = PRIVSLOT(slot);
+ PKCS11_CTX *ctx = priv->parent;
+ int rv;
+
+ if (!priv->haveSession && PKCS11_open_session(slot, 0)) {
+ PKCS11err(PKCS11_F_PKCS11_GENERATE_RANDOM, PKCS11_NO_SESSION);
+ return -1;
+ }
+
+ rv = CRYPTOKI_call(ctx, C_GenerateRandom(priv->session, (CK_BYTE_PTR) r, r_len));
+ CRYPTOKI_checkerr(PKCS11_F_PKCS11_GENERATE_RANDOM, rv);
+
+ return pkcs11_check_token(ctx, slot);
+}
+
+/*
+ * Helper functions
+ */
+int pkcs11_init_slot(PKCS11_CTX * ctx, PKCS11_SLOT * slot, CK_SLOT_ID id)
+{
+ PKCS11_SLOT_private *priv;
+ CK_SLOT_INFO info;
+ int rv;
+
+ rv = CRYPTOKI_call(ctx, C_GetSlotInfo(id, &info));
+ CRYPTOKI_checkerr(PKCS11_F_PKCS11_ENUM_SLOTS, rv);
+
+ priv = PKCS11_NEW(PKCS11_SLOT_private);
+ priv->parent = ctx;
+ priv->id = id;
+
+ slot->description = PKCS11_DUP(info.slotDescription);
+ slot->manufacturer = PKCS11_DUP(info.manufacturerID);
+ slot->removable = (info.flags & CKF_REMOVABLE_DEVICE) ? 1 : 0;
+ slot->_private = priv;
+
+ if ((info.flags & CKF_TOKEN_PRESENT) && pkcs11_check_token(ctx, slot))
+ return -1;
+
+ return 0;
+}
+
+void pkcs11_destroy_all_slots(PKCS11_CTX * ctx)
+{
+ PKCS11_CTX_private *priv = PRIVCTX(ctx);
+
+ while (priv->nslots > 0)
+ pkcs11_destroy_slot(ctx, &priv->slots[--(priv->nslots)]);
+ OPENSSL_free(priv->slots);
+ priv->slots = NULL;
+ priv->nslots = -1;
+}
+
+void pkcs11_destroy_slot(PKCS11_CTX * ctx, PKCS11_SLOT * slot)
+{
+ PKCS11_SLOT_private *priv = PRIVSLOT(slot);
+
+ CRYPTOKI_call(ctx, C_CloseAllSessions(priv->id));
+ OPENSSL_free(slot->_private);
+ OPENSSL_free(slot->description);
+ OPENSSL_free(slot->manufacturer);
+ if (slot->token) {
+ pkcs11_destroy_token(slot->token);
+ OPENSSL_free(slot->token);
+ }
+ memset(slot, 0, sizeof(*slot));
+}
+
+int pkcs11_check_token(PKCS11_CTX * ctx, PKCS11_SLOT * slot)
+{
+ PKCS11_SLOT_private *priv = PRIVSLOT(slot);
+ PKCS11_TOKEN_private *tpriv;
+ CK_TOKEN_INFO info;
+ PKCS11_TOKEN *token;
+ int rv;
+
+ if (slot->token)
+ pkcs11_destroy_token(slot->token);
+ else
+ slot->token = PKCS11_NEW(PKCS11_TOKEN);
+ token = slot->token;
+
+ rv = CRYPTOKI_call(ctx, C_GetTokenInfo(priv->id, &info));
+ if (rv == CKR_TOKEN_NOT_PRESENT) {
+ OPENSSL_free(token);
+ slot->token = NULL;
+ return 0;
+ }
+ CRYPTOKI_checkerr(PKCS11_F_PKCS11_CHECK_TOKEN, rv);
+
+ /* We have a token */
+ tpriv = PKCS11_NEW(PKCS11_TOKEN_private);
+ tpriv->parent = slot;
+ tpriv->nkeys = -1;
+ tpriv->ncerts = -1;
+
+ token->label = PKCS11_DUP(info.label);
+ token->manufacturer = PKCS11_DUP(info.manufacturerID);
+ token->model = PKCS11_DUP(info.model);
+ token->initialized = (info.flags & CKF_TOKEN_INITIALIZED) ? 1 : 0;
+ token->loginRequired = (info.flags & CKF_LOGIN_REQUIRED) ? 1 : 0;
+ token->secureLogin = (info.flags & CKF_PROTECTED_AUTHENTICATION_PATH) ? 1 : 0;
+ token->userPinSet = (info.flags & CKF_USER_PIN_INITIALIZED) ? 1 : 0;
+ token->readOnly = (info.flags & CKF_WRITE_PROTECTED) ? 1 : 0;
+ token->_private = tpriv;
+
+ return 0;
+}
+
+void pkcs11_destroy_token(PKCS11_TOKEN * token)
+{
+ /* XXX destroy keys associated with this token */
+ OPENSSL_free(token->label);
+ OPENSSL_free(token->manufacturer);
+ OPENSSL_free(token->model);
+ OPENSSL_free(token->_private);
+ memset(token, 0, sizeof(*token));
+}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-opensc/libp11.git
More information about the pkg-opensc-commit
mailing list