7#ifndef DESFIRECRYPTO_HPP
8#define DESFIRECRYPTO_HPP
65 void appendDecipherData(
const ByteVector &data);
72 virtual ByteVector desfireDecrypt(
size_t length);
80 virtual bool verifyMAC(
bool end,
const ByteVector &data);
114 static short desfire_crc16(
const void *data,
size_t dataLength);
122 static uint32_t desfire_crc32(
const void *data,
size_t dataLength);
187 bool calccrc =
true);
202 std::shared_ptr<openssl::OpenSSLSymmetricCipher> cipher,
const ByteVector ¶m =
ByteVector(),
203 bool calccrc =
true);
238 std::shared_ptr<openssl::OpenSSLSymmetricCipher> cipher,
size_t datalen);
258 std::shared_ptr<openssl::OpenSSLSymmetricCipher> cipherMAC,
const ByteVector &data);
283 virtual void authenticate_PICC2(
unsigned char keyno,
const ByteVector &encRndA);
296 const ByteVector &encRndB,
unsigned int randomlen);
304 void iso_authenticate_PICC2(
unsigned char keyno,
const ByteVector &encRndA1,
305 unsigned int randomlen);
324 ByteVector aes_authenticate_PICC1_GENERIC(
unsigned char keyno,
325 const std::shared_ptr<Key> &key,
333 void aes_authenticate_PICC2(
unsigned char keyno,
const ByteVector &encRndA1);
335 void aes_authenticate_PICC2_GENERIC(
unsigned char keyno,
336 const std::shared_ptr<Key> &key,
350 static void getKey(std::shared_ptr<DESFireKey> key,
ByteVector diversify,
358 static void getKeyVersioned(std::shared_ptr<DESFireKey> key,
365 void selectApplication(
size_t aid);
375 std::shared_ptr<DESFireKey> newkey,
377 unsigned char keysetno = 0);
381 void createApplication(
int aid, uint8_t maxKeySlotNb, uint8_t maxNbKeys,
386 d_identifier = identifier;
399 static std::shared_ptr<DESFireKey> getDefaultKey(
DESFireKeyType keyType);
404 virtual void setDefaultKeysAt(std::shared_ptr<Location> location);
413 virtual void setKey(
size_t aid, uint8_t keyslot, uint8_t keyno,
414 std::shared_ptr<DESFireKey> key);
423 virtual void setKeyInAllKeySet(
size_t aid, uint8_t keySlotNb, uint8_t nbKeys,
424 std::shared_ptr<DESFireKey> key);
429 virtual void clearKeys();
437 std::shared_ptr<DESFireKey> getKey(uint8_t keyslot, uint8_t keyno)
const;
448 bool getKey(
size_t aid, uint8_t keyset, uint8_t keyno,
ByteVector diversify,
467 std::shared_ptr<DESFireKey> getKey(
size_t aid, uint8_t keyslot, uint8_t keyno)
const;
472 std::map<std::tuple<size_t, uint8_t, uint8_t>, std::shared_ptr<DESFireKey>>
d_keys;
483 std::shared_ptr<openssl::OpenSSLSymmetricCipher>
d_cipher;
DESFire cryptographic functions.
Definition: desfirecrypto.hpp:49
CryptoMethod d_auth_method
The current authentication method.
Definition: desfirecrypto.hpp:478
ByteVector d_last_left
The last left buffer for card command.
Definition: desfirecrypto.hpp:538
ByteVector d_lastIV
The last Initialization Vector (DESFire native mode).
Definition: desfirecrypto.hpp:503
std::shared_ptr< openssl::OpenSSLSymmetricCipher > d_cipher
The current cipher.
Definition: desfirecrypto.hpp:483
ByteVector d_rndB
The random number B.
Definition: desfirecrypto.hpp:548
void setIdentifier(ByteVector identifier)
Definition: desfirecrypto.hpp:384
ByteVector d_identifier
The card identifier use for key diversification.
Definition: desfirecrypto.hpp:553
std::map< std::tuple< size_t, uint8_t, uint8_t >, std::shared_ptr< DESFireKey > > d_keys
Definition: desfirecrypto.hpp:472
ByteVector d_rndA
The random number A.
Definition: desfirecrypto.hpp:543
ByteVector getIdentifier() const
Definition: desfirecrypto.hpp:389
unsigned int d_mac_size
The MAC size.
Definition: desfirecrypto.hpp:488
ByteVector d_sessionKey
The current session key.
Definition: desfirecrypto.hpp:493
ByteVector d_buf
The temporised buffer.
Definition: desfirecrypto.hpp:533
unsigned int d_currentAid
The current Application ID.
Definition: desfirecrypto.hpp:508
ByteVector d_authkey
The authentication key.
Definition: desfirecrypto.hpp:498
std::unique_ptr< IKSCryptoWrapper > iks_wrapper_
Definition: desfirecrypto.hpp:517
unsigned char d_currentKeyNo
The current Key number.
Definition: desfirecrypto.hpp:513
std::vector< uint8_t > ByteVector
Definition: lla_fwd.hpp:80
CryptoMethod
The cryptographic method.
Definition: desfirecrypto.hpp:26
@ CM_ISO
Definition: desfirecrypto.hpp:28
@ CM_EV2
Definition: desfirecrypto.hpp:29
@ CM_LEGACY
Definition: desfirecrypto.hpp:27
DESFireKeyType
The DESFire key type.
Definition: desfirekey.hpp:33
Definition: desfirecrypto.hpp:34
SignatureResult last_sig
Definition: desfirecrypto.hpp:42
std::string remote_key_name
Definition: desfirecrypto.hpp:38
Definition: RemoteCrypto.hpp:9