root/trunk/src/libopensc/internal.h

Revision 3405, 9.1 KB (checked in by alonbl, 9 months ago)

Complete rewrite of OpenSC build system.

1. Build system now supports MinGW (Windows) compilation using msys and cross compilation.
2. Ability to explicitly disable and enable dependencies of the package.
3. openct, pcsc and nsplugins features are disabled by default.
4. Modified pcsc driver to use pcsc dynamically, no compile time dependency is required.
5. --enable-pcsc-lite configuration option renamed to --enable-pcsc.
6. Install opensc.conf file (as opensc.conf.new if opensc.conf exists).
7. Add--enable-doc configuration option, allow installing documentation into target.
8. Add --disable-man configuration option, allow msys mingw32 users to

build from svn without extra dependencies.

9. Add export files to each library in order to export only required symbols.

Windows native build may use these files instead of scanning objects' symbols.

10. Add opensc-tool --info to display some general information about the build.
11. Create compatibility library to be linked against library instread of recompiling the

same source files in different places.

12. Add different win32 version resource to each class of outputs.
13. Make xsl-stylesheets location selectable.
14. Some win32 fixups.
15. Some warning fixups.
16. Many other autoconf/automake cleanups.

Alon Bar-Lev

svn diff -r 3315:3399 https://www.opensc-project.org/svn/opensc/branches/alonbl/mingw

_M .
D configure.in
_M src
_M src/openssh
M src/openssh/Makefile.am
_M src/tools
M src/tools/rutoken-tool.c
M src/tools/opensc-tool.c
M src/tools/cardos-info.c
M src/tools/pkcs15-crypt.c
M src/tools/pkcs15-init.c
M src/tools/piv-tool.c
M src/tools/netkey-tool.c
M src/tools/eidenv.c
M src/tools/cryptoflex-tool.c
M src/tools/util.c
M src/tools/pkcs11-tool.c
M src/tools/pkcs15-tool.c
M src/tools/util.h
M src/tools/opensc-explorer.c
M src/tools/Makefile.am
_M src/pkcs11
M src/pkcs11/pkcs11-global.c
M src/pkcs11/framework-pkcs15.c
M src/pkcs11/mechanism.c
M src/pkcs11/pkcs11-display.c
M src/pkcs11/pkcs11-object.c
A src/pkcs11/opensc-pkcs11.exports
M src/pkcs11/sc-pkcs11.h
M src/pkcs11/pkcs11-spy.c
M src/pkcs11/openssl.c
M src/pkcs11/Makefile.am
A src/pkcs11/pkcs11-spy.exports
_M src/tests
_M src/tests/regression
M src/tests/regression/Makefile.am
M src/tests/sc-test.c
M src/tests/pintest.c
M src/tests/Makefile.am
_M src/include
_M src/include/opensc
M src/include/opensc/Makefile.am
A src/include/opensc/svnignore
M src/include/Makefile.am
_M src/signer
_M src/signer/npinclude
M src/signer/npinclude/Makefile.am
M src/signer/Makefile.am
A src/signer/signer.exports
_M src/common
A src/common/compat_dummy.c
D src/common/getopt.txt
D src/common/strlcpy.c
D src/common/LICENSE
A src/common/compat_getopt.txt
A src/common/compat_strlcpy.c
A src/common/LICENSE.compat_getopt
A src/common/compat_getopt.c
D src/common/strlcpy.h
D src/common/ChangeLog
D src/common/getpass.c
D src/common/my_getopt.c
A src/common/compat_strlcpy.h
A src/common/compat_getpass.c
A src/common/compat_getopt.h
A src/common/ChangeLog.compat_getopt
D src/common/README.strlcpy
D src/common/my_getopt.h
A src/common/compat_getpass.h
A src/common/README.compat_strlcpy
D src/common/strlcpy.3
A src/common/README.compat_getopt
D src/common/getopt.3
D src/common/README.my_getopt
A src/common/compat_strlcpy.3
A src/common/compat_getopt.3
M src/common/Makefile.am
M src/Makefile.am
_M src/pkcs15init
M src/pkcs15init/pkcs15-oberthur.c
M src/pkcs15init/profile.c
M src/pkcs15init/pkcs15-lib.c
M src/pkcs15init/pkcs15-rutoken.c
A src/pkcs15init/pkcs15init.exports
M src/pkcs15init/pkcs15-gpk.c
M src/pkcs15init/Makefile.am
_M src/scconf
M src/scconf/Makefile.am
M src/scconf/parse.c
A src/scconf/scconf.exports
_M src/libopensc
M src/libopensc/card-rutoken.c
M src/libopensc/compression.c
M src/libopensc/sc.c
M src/libopensc/card-piv.c
M src/libopensc/pkcs15-openpgp.c
M src/libopensc/pkcs15-postecert.c
M src/libopensc/pkcs15-tcos.c
M src/libopensc/opensc-config.in
M src/libopensc/reader-pcsc.c
A src/libopensc/internal-winscard.h
M src/libopensc/ctx.c
A src/libopensc/libopensc.exports
M src/libopensc/pkcs15-piv.c
M src/libopensc/pkcs15-infocamere.c
M src/libopensc/internal.h
M src/libopensc/pkcs15-actalis.c
M src/libopensc/pkcs15-starcert.c
M src/libopensc/card-oberthur.c
M src/libopensc/pkcs15-atrust-acos.c
M src/libopensc/p15card-helper.c
D src/libopensc/part10.h
M src/libopensc/ui.c
M src/libopensc/card-gpk.c
M src/libopensc/pkcs15-wrap.c
M src/libopensc/pkcs15-gemsafeGPK.c
M src/libopensc/log.c
M src/libopensc/pkcs15-esteid.c
M src/libopensc/pkcs15-prkey-rutoken.c
M src/libopensc/log.h
M src/libopensc/Makefile.am
M src/libopensc/reader-openct.c
_M aclocal
M aclocal/Makefile.am
_M win32
M win32/Makefile.am
A win32/versioninfo.rc.in
A win32/ltrc.inc
A configure.ac
_M doc
_M doc/tools
M doc/tools/pkcs15-profile.xml
D doc/changelog.sh
D doc/export-wiki.xsl
_M doc/api
_M doc/api/file
M doc/api/man.xsl
_M doc/api/asn1
_M doc/api/apps
_M doc/api/init
_M doc/api/types
_M doc/api/card
M doc/api/html.xsl
_M doc/api/misc
_M doc/api/util
M doc/Makefile.am
D doc/export-wiki.sh
AM doc/nonpersistent
A doc/nonpersistent/export-wiki.xsl
A doc/nonpersistent/Makefile.am
A doc/nonpersistent/export-wiki.sh
A doc/nonpersistent/svn2cl.xsl
D doc/generate-man.sh
D doc/svn2cl.xsl
M Makefile.am
A svnignore
_M etc
M etc/opensc.conf.in
M etc/Makefile.am
D man
_M solaris
M solaris/Makefile

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1/*
2 * internal.h: Internal definitions for libopensc
3 *
4 * Copyright (C) 2001, 2002  Juha YrjölÀ <juha.yrjola@iki.fi>
5 *               2005        The OpenSC project
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20 */
21
22#ifndef _SC_INTERNAL_H
23#define _SC_INTERNAL_H
24
25#ifdef HAVE_CONFIG_H
26#include <config.h>
27#endif
28
29#ifdef __cplusplus
30extern "C" {
31#endif
32
33#include "opensc.h"
34#include "log.h"
35#include "ui.h"
36#include "cards.h"
37#include <assert.h>
38#ifdef _WIN32
39#include <windows.h>
40#endif
41
42#define SC_FILE_MAGIC                   0x14426950
43#define SC_CARD_MAGIC                   0x27182818
44#define SC_CTX_MAGIC                    0x0A550335
45
46#ifndef _WIN32
47#define msleep(t)       usleep((t) * 1000)
48#else
49#define msleep(t)       Sleep(t)
50#define sleep(t)        Sleep((t) * 1000)
51#endif
52
53struct sc_atr_table {
54        /* The atr fields are required to
55         * be in aa:bb:cc hex format. */
56        char *atr;
57        /* The atrmask is logically AND'd with an
58         * card atr prior to comparison with the
59         * atr reference value above. */
60        char *atrmask;
61        char *name;
62        int type;
63        unsigned long flags;
64        /* Reference to card_atr configuration block,
65         * available to user configured card entries. */
66        scconf_block *card_atr;
67};
68
69/* Internal use only */
70int sc_check_sw(struct sc_card *card, unsigned int sw1, unsigned int sw2);
71
72int _sc_add_reader(struct sc_context *ctx, struct sc_reader *reader);
73int _sc_parse_atr(struct sc_context *ctx, struct sc_slot_info *slot);
74struct sc_slot_info *_sc_get_slot_info(struct sc_reader *reader, int slot_id);
75
76/* Add an ATR to the card driver's struct sc_atr_table */
77int _sc_add_atr(struct sc_context *ctx, struct sc_card_driver *driver, struct sc_atr_table *src);
78int _sc_free_atr(struct sc_context *ctx, struct sc_card_driver *driver);
79
80/**
81 * Convert an unsigned long into 4 bytes in big endian order
82 * @param  buf   the byte array for the result, should be 4 bytes long
83 * @param  x     the value to be converted
84 */
85void ulong2bebytes(u8 *buf, unsigned long x);
86/**
87 * Convert an unsigned long into 2 bytes in big endian order
88 * @param  buf   the byte array for the result, should be 2 bytes long
89 * @param  x     the value to be converted
90 */
91void ushort2bebytes(u8 *buf, unsigned short x);
92/**
93 * Convert 4 bytes in big endian order into an unsigned long
94 * @param  buf   the byte array of 4 bytes
95 * @return       the converted value
96 */
97unsigned long bebytes2ulong(const u8 *buf);
98/**
99 * Convert 2 bytes in big endian order into an unsigned short
100 * @param  buf   the byte array of 2 bytes
101 * @return       the converted value
102 */
103unsigned short bebytes2ushort(const u8 *buf);
104
105/* Returns an scconf_block entry with matching ATR/ATRmask to the ATR specified,
106 * NULL otherwise. Additionally, if card driver is not specified, search through
107 * all card drivers user configured ATRs. */
108scconf_block *_sc_match_atr_block(sc_context_t *ctx, struct sc_card_driver *driver, u8 *atr, size_t atr_len);
109
110/* Returns an index number if a match was found, -1 otherwise. table has to
111 * be null terminated. */
112int _sc_match_atr(struct sc_card *card, struct sc_atr_table *table, int *type_out);
113
114int _sc_check_forced_protocol(struct sc_context *ctx, u8 *atr, size_t atr_len, unsigned int *protocol);
115
116int _sc_card_add_algorithm(struct sc_card *card, const struct sc_algorithm_info *info);
117int _sc_card_add_rsa_alg(struct sc_card *card, unsigned int key_length,
118                         unsigned long flags, unsigned long exponent);
119struct sc_algorithm_info * _sc_card_find_rsa_alg(struct sc_card *card,
120                                                 unsigned int key_length);
121
122int sc_asn1_read_tag(const u8 ** buf, size_t buflen, unsigned int *cla_out,
123                     unsigned int *tag_out, size_t *taglen);
124
125/********************************************************************/
126/*                 pkcs1 padding/encoding functions                 */
127/********************************************************************/
128
129int sc_pkcs1_strip_01_padding(const u8 *in_dat, size_t in_len, u8 *out_dat,
130                              size_t *out_len);
131int sc_pkcs1_strip_02_padding(const u8 *data, size_t len, u8 *out_dat,
132                              size_t *out_len);
133int sc_pkcs1_strip_digest_info_prefix(unsigned int *algorithm,
134                const u8 *in_dat, size_t in_len, u8 *out_dat, size_t *out_len);
135
136/**
137 * PKCS1 encodes the given data.
138 * @param  ctx     IN  sc_context_t object
139 * @param  flags   IN  the algorithm to use
140 * @param  in      IN  input buffer
141 * @param  inlen   IN  length of the input
142 * @param  out     OUT output buffer (in == out is allowed)
143 * @param  outlen  OUT length of the output buffer
144 * @param  modlen  IN  length of the modulus in bytes
145 * @return SC_SUCCESS on success and an error code otherwise
146 */
147int sc_pkcs1_encode(sc_context_t *ctx, unsigned long flags,
148        const u8 *in, size_t inlen, u8 *out, size_t *outlen, size_t modlen);
149/**
150 * Get the necessary padding and sec. env. flags.
151 * @param  ctx     IN  sc_contex_t object
152 * @param  iflags  IN  the desired algorithms flags
153 * @param  caps    IN  the card / key capabilities
154 * @param  pflags  OUT the padding flags to use
155 * @param  salg    OUT the security env. algorithm flag to use
156 * @return SC_SUCCESS on success and an error code otherwise
157 */
158int sc_get_encoding_flags(sc_context_t *ctx,
159        unsigned long iflags, unsigned long caps,
160        unsigned long *pflags, unsigned long *salg);
161
162/********************************************************************/
163/*             mutex functions                                      */
164/********************************************************************/
165
166/**
167 * Creates a new sc_mutex object. Note: unless sc_mutex_set_mutex_funcs()
168 * this function does nothing and always returns SC_SUCCESS.
169 * @param  ctx    sc_context_t object with the thread context
170 * @param  mutex  pointer for the newly created mutex object
171 * @return SC_SUCCESS on success and an error code otherwise
172 */
173int sc_mutex_create(const sc_context_t *ctx, void **mutex);
174/**
175 * Tries to acquire a lock for a sc_mutex object. Note: Unless
176 * sc_mutex_set_mutex_funcs() has been called before this
177 * function does nothing and always returns SUCCESS.
178 * @param  ctx    sc_context_t object with the thread context
179 * @param  mutex  mutex object to lock
180 * @return SC_SUCCESS on success and an error code otherwise
181 */
182int sc_mutex_lock(const sc_context_t *ctx, void *mutex);
183/**
184 * Unlocks a sc_mutex object. Note: Unless sc_mutex_set_mutex_funcs()
185 * has been called before this function does nothing and always returns
186 * SC_SUCCESS.
187 * @param  ctx    sc_context_t object with the thread context
188 * @param  mutex  mutex object to unlock
189 * @return SC_SUCCESS on success and an error code otherwise
190 */
191int sc_mutex_unlock(const sc_context_t *ctx, void *mutex);
192/**
193 * Destroys a sc_mutex object. Note: Unless sc_mutex_set_mutex_funcs()
194 * has been called before this function does nothing and always returns
195 * SC_SUCCESS.
196 * @param  ctx    sc_context_t object with the thread context
197 * @param  mutex  mutex object to be destroyed
198 * @return SC_SUCCESS on success and an error code otherwise
199 */
200int sc_mutex_destroy(const sc_context_t *ctx, void *mutex);
201/**
202 * Returns a unique id for every thread.
203 * @param  ctx  sc_context_t object with the thread context
204 * @return unsigned long with the unique id or 0 if not supported
205 */
206unsigned long sc_thread_id(const sc_context_t *ctx);
207
208/********************************************************************/
209/*             internal APDU handling functions                     */
210/********************************************************************/
211
212/**
213 * Returns the encoded APDU in newly created buffer.
214 * @param  ctx     sc_context_t object
215 * @param  apdu    sc_apdu_t object with the APDU to encode
216 * @param  buf     pointer to the newly allocated buffer
217 * @param  len     length of the encoded APDU
218 * @param  proto   protocol to be used
219 * @return SC_SUCCESS on success and an error code otherwise
220 */
221int sc_apdu_get_octets(sc_context_t *ctx, const sc_apdu_t *apdu, u8 **buf,
222        size_t *len, unsigned int proto);
223/**
224 * Sets the status bytes and return data in the APDU
225 * @param  ctx     sc_context_t object
226 * @param  apdu    the apdu to which the data should be written
227 * @param  buf     returned data
228 * @param  len     length of the returned data
229 * @return SC_SUCCESS on success and an error code otherwise
230 */
231int sc_apdu_set_resp(sc_context_t *ctx, sc_apdu_t *apdu, const u8 *buf,
232        size_t len);
233/**
234 * Logs APDU
235 * @param  ctx          sc_context_t object
236 * @param  buf          buffer with the APDU data
237 * @param  len          length of the APDU
238 * @param  is_outgoing  != 0 if the data is send to the card
239 */
240void sc_apdu_log(sc_context_t *ctx, const u8 *data, size_t len,
241        int is_outgoing);
242#ifdef __cplusplus
243}
244#endif
245
246#endif
Note: See TracBrowser for help on using the browser.