OpenPACE
eac.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2010-2012 Frank Morgner and Dominik Oepen
3 *
4 * This file is part of OpenPACE.
5 *
6 * OpenPACE is free software: you can redistribute it and/or modify it under
7 * the terms of the GNU General Public License as published by the Free
8 * Software Foundation, either version 3 of the License, or (at your option)
9 * any later version.
10 *
11 * OpenPACE is distributed in the hope that it will be useful, but WITHOUT ANY
12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14 * details.
15 *
16 * You should have received a copy of the GNU General Public License along with
17 * OpenPACE. If not, see <http://www.gnu.org/licenses/>.
18 *
19 * Additional permission under GNU GPL version 3 section 7
20 *
21 * If you modify this Program, or any covered work, by linking or combining it
22 * with OpenSSL (or a modified version of that library), containing
23 * parts covered by the terms of OpenSSL's license, the licensors of
24 * this Program grant you additional permission to convey the resulting work.
25 * Corresponding Source for a non-source form of such a combination shall include
26 * the source code for the parts of OpenSSL used as well as that of the
27 * covered work.
28 *
29 * If you modify this Program, or any covered work, by linking or combining it
30 * with OpenSC (or a modified version of that library), containing
31 * parts covered by the terms of OpenSC's license, the licensors of
32 * this Program grant you additional permission to convey the resulting work.
33 * Corresponding Source for a non-source form of such a combination shall include
34 * the source code for the parts of OpenSC used as well as that of the
35 * covered work.
36 */
37
46#ifndef EAC_H_
47#define EAC_H_
48
49#ifdef __cplusplus
50extern "C" {
51#endif
52
53#include <eac/cv_cert.h>
54#include <eac/objects.h>
55#include <openssl/asn1.h>
56#include <openssl/buffer.h>
57#include <openssl/cmac.h>
58#include <openssl/ec.h>
59#include <openssl/evp.h>
60
89
95typedef struct ka_ctx {
97 const EVP_MD * md;
99 ENGINE * md_engine;
101 CMAC_CTX * cmac_ctx;
103 const EVP_CIPHER * cipher;
107 unsigned char * iv;
112
121 BUF_MEM * (*generate_key)(EVP_PKEY *key, BN_CTX *bn_ctx);
131 BUF_MEM * (*compute_key)(EVP_PKEY *key, const BUF_MEM *in, BN_CTX *bn_ctx);
132
134 EVP_PKEY *key;
135
139 BUF_MEM *k_enc;
141 BUF_MEM *k_mac;
143
146typedef struct pace_ctx {
174 unsigned char version;
176 int id;
180 BUF_MEM * (*map_generate_key)(const struct pace_ctx *ctx, BN_CTX *bn_ctx);
184 int (*map_compute_key)(struct pace_ctx * ctx, const BUF_MEM * s,
185 const BUF_MEM * in, BN_CTX *bn_ctx);
186
188 EVP_PKEY *static_key;
192 BUF_MEM *nonce;
196
199typedef struct ri_ctx {
217 int id;
219 const EVP_MD * md;
228 BUF_MEM * (*generate_key)(EVP_PKEY *key, BN_CTX *bn_ctx);
238 BUF_MEM * (*compute_key)(EVP_PKEY *key, const BUF_MEM *in, BN_CTX *bn_ctx);
240 EVP_PKEY *static_key;
242
244typedef CVC_CERT * (*CVC_lookup_cvca_cert) (const unsigned char *chr, size_t car_len);
245
299
301typedef X509_STORE * (*X509_lookup_csca_cert) (unsigned long issuer_name_hash);
302
340
376
378#define EAC_AES_MAC_LENGTH 8
379
390void EAC_init(void);
391
395void EAC_cleanup(void);
396
401EAC_CTX *
403
412
424int
425EAC_CTX_init_pace(EAC_CTX *ctx, int protocol, int curve);
426
439int
441 const unsigned char *privkey, size_t privkey_len,
442 const unsigned char *cvca, size_t cvca_len);
443
455int EAC_CTX_init_ca(EAC_CTX *ctx, int protocol, int curve);
456
468int
469EAC_CTX_init_ri(EAC_CTX *ctx, int protocol, int stnd_dp);
470
481int EAC_CTX_init_ef_cardaccess(unsigned const char * in, size_t in_len,
482 EAC_CTX *ctx);
483
497 const unsigned char *ef_cardsecurity, size_t ef_cardsecurity_len,
498 EAC_CTX *ctx);
499
508int EAC_CTX_get_cvca_lookup(const EAC_CTX *ctx, CVC_lookup_cvca_cert *lookup_cvca_cert);
530
536void EAC_set_cvc_default_dir(const char *default_dir);
537
565
571void EAC_set_x509_default_dir(const char *default_dir);
572
590BUF_MEM *
591EAC_add_iso_pad(const EAC_CTX *ctx, const BUF_MEM * unpadded);
599BUF_MEM *
600EAC_remove_iso_pad(const BUF_MEM * padded);
601
610
618int EAC_reset_ssc(const EAC_CTX *ctx);
627int EAC_set_ssc(const EAC_CTX *ctx, unsigned long ssc);
628
639BUF_MEM *
640EAC_encrypt(const EAC_CTX *ctx, const BUF_MEM *data);
641
652BUF_MEM *
653EAC_decrypt(const EAC_CTX *ctx, const BUF_MEM *data);
654
665BUF_MEM *
666EAC_authenticate(const EAC_CTX *ctx, const BUF_MEM *data);
676int
677EAC_verify_authentication(const EAC_CTX *ctx, const BUF_MEM *data,
678 const BUF_MEM *mac);
679
689BUF_MEM *
690EAC_Comp(const EAC_CTX *ctx, int id, const BUF_MEM *pub);
691
703BUF_MEM *
704EAC_hash_certificate_description(const unsigned char *cert_desc,
705 size_t cert_desc_len);
706
708#define EAC_ID_PACE 0
710#define EAC_ID_CA 1
712#define EAC_ID_TA 2
714#define EAC_ID_EAC 3
715
726int
728
745int EAC_CTX_print_private(BIO *out, const EAC_CTX *ctx, int indent);
755int BUF_MEM_print(BIO *out, const BUF_MEM *buf, int indent);
756
765void
767
769#ifdef __cplusplus
770}
771#endif
772#endif
Interface for Card Verifiable Certificates.
eac_tr_version
Identification of the specifications to use.
Definition eac.h:81
@ EAC_TR_VERSION_2_01
Perform EAC according to TR-03110 v2.01.
Definition eac.h:85
@ EAC_TR_VERSION_2_02
Perform EAC according to TR-03110 v2.02 and later.
Definition eac.h:87
@ EAC_TR_VERSION
Undefined type, if nothing else matches.
Definition eac.h:83
struct ta_ctx TA_CTX
Context for the Terminal Authentication protocol.
struct pace_ctx PACE_CTX
Context for the Password Authenticated Connection Establishment protocol.
struct eac_ctx EAC_CTX
Context for the Extended Access Control protocol.
struct ca_ctx CA_CTX
Context for the Chip Authentication protocol.
struct ri_ctx RI_CTX
Context for the Restricted Identification protocol.
X509_STORE *(* X509_lookup_csca_cert)(unsigned long issuer_name_hash)
callback for finding the X.509 trust anchor
Definition eac.h:301
struct ka_ctx KA_CTX
Context for a key agreement and subsequent derivation of session keys.
CVC_CERT *(* CVC_lookup_cvca_cert)(const unsigned char *chr, size_t car_len)
callback for finding the CVCA trust anchor
Definition eac.h:244
int EAC_CTX_set_cvca_lookup(EAC_CTX *ctx, CVC_lookup_cvca_cert lookup_cvca_cert)
Set the CVCA lookup callback.
int EAC_CTX_get_csca_lookup_cert(const EAC_CTX *ctx, X509_lookup_csca_cert *lookup_cvca_cert)
Get the CSCA lookup callback.
int EAC_CTX_init_ri(EAC_CTX *ctx, int protocol, int stnd_dp)
Initialize an EAC context for Restricted Identification.
X509_lookup_csca_cert EAC_get_default_csca_lookup(void)
Return the default lookup of the country signing CA.
int EAC_CTX_init_pace(EAC_CTX *ctx, int protocol, int curve)
Initialize an EAC context for PACE.
int EAC_CTX_set_csca_lookup_cert(EAC_CTX *ctx, X509_lookup_csca_cert lookup_cvca_cert)
Set the CSCA lookup callback.
void EAC_init(void)
Initializes OpenSSL and the EAC identifier.
void EAC_set_x509_default_dir(const char *default_dir)
Set directory for EAC_get_default_csca_lookup()
void EAC_CTX_clear_free(EAC_CTX *ctx)
Free an EAC context.
void EAC_cleanup(void)
Wrapper to EVP_cleanup()
void EAC_set_cvc_default_dir(const char *default_dir)
Set directory for EAC_get_default_cvca_lookup()
int EAC_CTX_init_ca(EAC_CTX *ctx, int protocol, int curve)
Initialize an EAC context for Chip Authentication.
CVC_lookup_cvca_cert EAC_get_default_cvca_lookup(void)
Return the default lookup of the country verifying CA.
int EAC_CTX_init_ef_cardaccess(unsigned const char *in, size_t in_len, EAC_CTX *ctx)
Initialize an EAC context for PACE, TA and CA from the data given in an EF.CardAccess.
int EAC_CTX_init_ta(const EAC_CTX *ctx, const unsigned char *privkey, size_t privkey_len, const unsigned char *cvca, size_t cvca_len)
Initialize an EAC context for TA with the terminal's PKI data. Use either a CV certificate or a known...
int EAC_CTX_init_ef_cardsecurity(const unsigned char *ef_cardsecurity, size_t ef_cardsecurity_len, EAC_CTX *ctx)
Initialize an EAC context for PACE, TA and CA from the data given in an EF.CardSecurity.
EAC_CTX * EAC_CTX_new(void)
Create a new EAC context.
int EAC_CTX_get_cvca_lookup(const EAC_CTX *ctx, CVC_lookup_cvca_cert *lookup_cvca_cert)
Return the EAC context's CVCA lookup callback.
void BUF_MEM_clear_free(BUF_MEM *b)
Frees and wipes a buffer.
int EAC_CTX_print_private(BIO *out, const EAC_CTX *ctx, int indent)
Print EAC context including private data.
int BUF_MEM_print(BIO *out, const BUF_MEM *buf, int indent)
Prints buffer.
BUF_MEM * EAC_hash_certificate_description(const unsigned char *cert_desc, size_t cert_desc_len)
Compute the hash of a CV certificate description.
int EAC_verify_authentication(const EAC_CTX *ctx, const BUF_MEM *data, const BUF_MEM *mac)
Verify authenticated data according to TR-03110 F.2.
int EAC_CTX_set_encryption_ctx(EAC_CTX *ctx, int id)
Set the SM context for encryption, decryption and authentication.
BUF_MEM * EAC_encrypt(const EAC_CTX *ctx, const BUF_MEM *data)
Encrypts data according to TR-03110 F.2.
BUF_MEM * EAC_add_iso_pad(const EAC_CTX *ctx, const BUF_MEM *unpadded)
Pad a buffer using ISO/IEC 9797-1 padding method 2.
int EAC_reset_ssc(const EAC_CTX *ctx)
Reset the Send Sequence Counter.
BUF_MEM * EAC_decrypt(const EAC_CTX *ctx, const BUF_MEM *data)
Decrypt data according to TR-03110 F.2.
BUF_MEM * EAC_authenticate(const EAC_CTX *ctx, const BUF_MEM *data)
Authenticate data according to TR-03110 F.2.
int EAC_set_ssc(const EAC_CTX *ctx, unsigned long ssc)
Set the Send Sequence Counter.
BUF_MEM * EAC_Comp(const EAC_CTX *ctx, int id, const BUF_MEM *pub)
Compresse a public key according to TR-03110 Table A.2.
int EAC_increment_ssc(const EAC_CTX *ctx)
Increment the Send Sequence Counter.
BUF_MEM * EAC_remove_iso_pad(const BUF_MEM *padded)
Remove ISO/IEC 9797-1 padding method 2 from a message.
Definitions of object identifiers.
Context for the Chip Authentication protocol.
Definition eac.h:304
unsigned char version
(currently unused) Version of the CA protocol, MUST be 1 or 2
Definition eac.h:306
int id
identifier of this CA context
Definition eac.h:321
int flags
Flags to control some of the behaviour of the CA.
Definition eac.h:327
int protocol
Identifier of the protocol's OID specifying the exact CA parameters to use.
Definition eac.h:319
X509_lookup_csca_cert lookup_csca_cert
callback for finding the X.509 trust anchor
Definition eac.h:338
KA_CTX * ka_ctx
Key agreement object used with the PICC's private key.
Definition eac.h:329
The actual certifcate, consisting of the body and a signature.
Definition cv_cert.h:209
Context for the Extended Access Control protocol.
Definition eac.h:342
STACK_OF(CA_CTX *) ca_ctxs
stack of available Chip Authentication configurations
TA_CTX * ta_ctx
Context for the currently selected Terminal Authentication protocol.
Definition eac.h:364
CA_CTX * ca_ctx
Context for the currently selected Chip Authentication protocol.
Definition eac.h:368
EVP_MD_CTX * md_ctx
Context for various hashing operations.
Definition eac.h:348
KA_CTX * key_ctx
Context for currently selected secure messaging established with PACE or CA.
Definition eac.h:372
PACE_CTX * pace_ctx
Context for the currently selected Password Authenticated Connection Establishment protocol.
Definition eac.h:354
STACK_OF(RI_CTX *) ri_ctxs
stack of available Restricted Identification configurations
BN_CTX * bn_ctx
Context for various operations with BIGNUM objects.
Definition eac.h:346
STACK_OF(PACE_CTX *) pace_ctxs
stack of available Password Authenticated Connection Establishment configurations
BIGNUM * ssc
Send sequence counter.
Definition eac.h:374
EVP_CIPHER_CTX * cipher_ctx
Context for various cipher operations.
Definition eac.h:350
RI_CTX * ri_ctx
Context for the currently selected Restricted Identification protocol.
Definition eac.h:360
enum eac_tr_version tr_version
Perform EAC conforming to this version of TR-03110.
Definition eac.h:344
Context for a key agreement and subsequent derivation of session keys.
Definition eac.h:95
ENGINE * cipher_engine
Cipher's engine.
Definition eac.h:105
BUF_MEM * k_mac
Symmetric key used for integrity protection. Derived from KA_CTX.shared_secret.
Definition eac.h:141
ENGINE * md_engine
Digest's engine.
Definition eac.h:99
int enc_keylen
Length of the computed key for the encryption/decryption.
Definition eac.h:111
BUF_MEM * k_enc
Symmetric key used for encryption/decryption. Derived from KA_CTX.shared_secret.
Definition eac.h:139
const EVP_CIPHER * cipher
Cipher to use for encryption/decryption.
Definition eac.h:103
EVP_PKEY * key
Container for the key pair used for key agreement.
Definition eac.h:134
const EVP_MD * md
Digest to use for key derivation.
Definition eac.h:97
BUF_MEM * shared_secret
Shared secret computed during the key agreement protocol.
Definition eac.h:137
CMAC_CTX * cmac_ctx
Context for CMAC.
Definition eac.h:101
int mac_keylen
Length of the computed key for the message authentication code.
Definition eac.h:109
unsigned char * iv
Initialisation vector for encryption/decryption.
Definition eac.h:107
Context for the Password Authenticated Connection Establishment protocol.
Definition eac.h:146
BUF_MEM * nonce
PICC's decrypted challenge generated in PACE step 1.
Definition eac.h:192
KA_CTX * ka_ctx
Key agreement object used with the ephemeral domain parameters.
Definition eac.h:190
unsigned char version
(currently unused) Version of the PACE protocol, MUST be 1 or 2
Definition eac.h:174
BUF_MEM * my_eph_pubkey
The own ephemeral public key generated in PACe step 3b.
Definition eac.h:194
int(* map_compute_key)(struct pace_ctx *ctx, const BUF_MEM *s, const BUF_MEM *in, BN_CTX *bn_ctx)
Points to the implementation of a specific mapping.
Definition eac.h:184
EVP_PKEY * static_key
PICC's static domain parameters.
Definition eac.h:188
int id
identifier of this PACE context
Definition eac.h:176
int protocol
Identifier of the protocol's OID specifying the exact PACE parameters to use.
Definition eac.h:172
Context for the Restricted Identification protocol.
Definition eac.h:199
int protocol
Identifier of the hash function to use.
Definition eac.h:215
EVP_PKEY * static_key
PICC's static domain parameters.
Definition eac.h:240
int id
identifier of this RI context
Definition eac.h:217
const EVP_MD * md
Digest to use for derivation of I^{sector}_{ID}.
Definition eac.h:219
Context for the Terminal Authentication protocol.
Definition eac.h:247
EVP_PKEY * pub_key
TA public key used for signing the challenge.
Definition eac.h:272
CVC_CERT * new_trust_anchor
When a complete CV certificate chain has been verified, this will be the new trust anchor.
Definition eac.h:282
BUF_MEM * nonce
PICC's challenge.
Definition eac.h:276
ENGINE * key_engine
(currently unused) engine for signing and signature verification
Definition eac.h:268
EVP_PKEY * priv_key
TA private key used for signing the challenge.
Definition eac.h:270
CVC_lookup_cvca_cert lookup_cvca_cert
Lookup the CVCA trust anchor.
Definition eac.h:297
BUF_MEM * pk_pcd
PCD's public key extracted from it's CV certificate.
Definition eac.h:274
CVC_CERT * trust_anchor
Trust anchor for CV certificate validation.
Definition eac.h:278
CVC_CERT * current_cert
Most recent verified CV certificate in a certificate chain.
Definition eac.h:280
unsigned char version
(currently unused) Version of the TA protocol, MUST be 1 or 2
Definition eac.h:249
int flags
Flags to control some of the behaviour of the CA.
Definition eac.h:288
int protocol
Identifier of the protocol's OID specifying the exact TA parameters to use.
Definition eac.h:266