scd: Split data structures into app and card related objects.
[gnupg.git] / scd / iso7816.h
1 /* iso7816.h - ISO 7816 commands
2  *      Copyright (C) 2003 Free Software Foundation, Inc.
3  *
4  * This file is part of GnuPG.
5  *
6  * GnuPG is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * GnuPG is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, see <https://www.gnu.org/licenses/>.
18  */
19
20 #ifndef ISO7816_H
21 #define ISO7816_H
22
23 #if GNUPG_MAJOR_VERSION == 1
24 #include "cardglue.h"
25 #endif
26
27 /* Command codes used by iso7816_check_pinpad. */
28 #define ISO7816_VERIFY                0x20
29 #define ISO7816_CHANGE_REFERENCE_DATA 0x24
30 #define ISO7816_RESET_RETRY_COUNTER   0x2C
31
32
33 /* Information to be passed to pinpad equipped readers.  See
34    ccid-driver.c for details. */
35 struct pininfo_s
36 {
37   int fixedlen;  /*
38                   * -1: Variable length input is not supported,
39                   *     no information of fixed length yet.
40                   *  0: Use variable length input.
41                   * >0: Fixed length of PIN.
42                   */
43   int minlen;
44   int maxlen;
45 };
46 typedef struct pininfo_s pininfo_t;
47
48
49 gpg_error_t iso7816_map_sw (int sw);
50
51 gpg_error_t iso7816_select_application (int slot,
52                                         const char *aid, size_t aidlen,
53                                         unsigned int flags);
54 gpg_error_t iso7816_select_application_ext (int slot,
55                                             const char *aid, size_t aidlen,
56                                             unsigned int flags,
57                                             unsigned char **result,
58                                             size_t *resultlen);
59 gpg_error_t iso7816_select_file (int slot, int tag, int is_dir);
60 gpg_error_t iso7816_select_path (int slot,
61                                  const unsigned short *path, size_t pathlen);
62 gpg_error_t iso7816_list_directory (int slot, int list_dirs,
63                                     unsigned char **result, size_t *resultlen);
64 gpg_error_t iso7816_send_apdu (int slot, int extended_mode,
65                                int class, int ins, int p0, int p1,
66                                int lc, const void *data,
67                                unsigned int *r_sw,
68                                unsigned char **result, size_t *resultlen);
69 gpg_error_t iso7816_apdu_direct (int slot,
70                                  const void *apdudata, size_t apdudatalen,
71                                  int handle_more, unsigned int *r_sw,
72                                  unsigned char **result, size_t *resultlen);
73 gpg_error_t iso7816_check_pinpad (int slot, int command,
74                                   pininfo_t *pininfo);
75 gpg_error_t iso7816_verify (int slot,
76                             int chvno, const char *chv, size_t chvlen);
77 gpg_error_t iso7816_verify_kp (int slot, int chvno, pininfo_t *pininfo);
78 gpg_error_t iso7816_change_reference_data (int slot, int chvno,
79                                const char *oldchv, size_t oldchvlen,
80                                const char *newchv, size_t newchvlen);
81 gpg_error_t iso7816_change_reference_data_kp (int slot, int chvno,
82                                               int is_exchange,
83                                               pininfo_t *pininfo);
84 gpg_error_t iso7816_reset_retry_counter (int slot, int chvno,
85                                          const char *newchv, size_t newchvlen);
86 gpg_error_t iso7816_reset_retry_counter_with_rc (int slot, int chvno,
87                                                  const char *data,
88                                                  size_t datalen);
89 gpg_error_t iso7816_get_data (int slot, int extended_mode, int tag,
90                               unsigned char **result, size_t *resultlen);
91 gpg_error_t iso7816_get_data_odd (int slot, int extended_mode, unsigned int tag,
92                                   unsigned char **result, size_t *resultlen);
93 gpg_error_t iso7816_put_data (int slot, int extended_mode, int tag,
94                               const void *data, size_t datalen);
95 gpg_error_t iso7816_put_data_odd (int slot, int extended_mode, int tag,
96                                   const void *data, size_t datalen);
97 gpg_error_t iso7816_manage_security_env (int slot, int p1, int p2,
98                                          const unsigned char *data,
99                                          size_t datalen);
100 gpg_error_t iso7816_compute_ds (int slot, int extended_mode,
101                                 const unsigned char *data, size_t datalen,
102                                 int le,
103                                 unsigned char **result, size_t *resultlen);
104 gpg_error_t iso7816_decipher (int slot, int extended_mode,
105                               const unsigned char *data, size_t datalen,
106                               int le, int padind,
107                               unsigned char **result, size_t *resultlen);
108 gpg_error_t iso7816_internal_authenticate (int slot, int extended_mode,
109                                    const unsigned char *data, size_t datalen,
110                                    int le,
111                                    unsigned char **result, size_t *resultlen);
112 gpg_error_t iso7816_general_authenticate (int slot, int extended_mode,
113                                           int algoref, int keyref,
114                                           const unsigned char *data,
115                                           size_t datalen,
116                                           int le,
117                                           unsigned char **result,
118                                           size_t *resultlen);
119 gpg_error_t iso7816_generate_keypair (int slot, int extended_mode,
120                                       int p1, int p2,
121                                       const char *data, size_t datalen,
122                                       int le,
123                                       unsigned char **result,
124                                       size_t *resultlen);
125 gpg_error_t iso7816_read_public_key (int slot, int extended_mode,
126                                     const char *data, size_t datalen,
127                                     int le,
128                                     unsigned char **result, size_t *resultlen);
129 gpg_error_t iso7816_get_challenge (int slot,
130                                    int length, unsigned char *buffer);
131
132 gpg_error_t iso7816_read_binary (int slot, size_t offset, size_t nmax,
133                                  unsigned char **result, size_t *resultlen);
134 gpg_error_t iso7816_read_record (int slot, int recno, int reccount,
135                                  int short_ef,
136                                  unsigned char **result, size_t *resultlen);
137
138 #endif /*ISO7816_H*/