LibLogicalAccess  2.5.0
An Open Source RFID Library
Loading...
Searching...
No Matches
iso24727crypto.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <cstdint>
4#include <logicalaccess/plugins/crypto/lla_crypto_api.hpp>
8#include <string>
9#include <vector>
10
11namespace logicalaccess
12{
13class LLA_CRYPTO_API ISO24727Crypto
14{
15 public:
16 explicit ISO24727Crypto(const std::string &cipher = "3des",
17 const std::string &hash = "sha1");
18
30 ByteVector step1(const ByteVector &random_icc, ByteVector random_ifd = {},
31 ByteVector random_k_ifd = {});
32
39 bool step2(const ByteVector &auth_response);
40
44 bool secureMode() const;
45
46 ByteVector encrypt_apdu(const ByteVector &apdu);
47
48 ByteVector decrypt_rapdu(const ByteVector &rapdu);
49
50 ByteVector encrypt_apdu(std::shared_ptr<openssl::SymmetricCipher> cipher,
51 const ByteVector &apdu, const ByteVector &ks_enc,
52 const ByteVector &ks_mac, const ByteVector &ssc);
53
54 ByteVector decrypt_rapdu(std::shared_ptr<openssl::SymmetricCipher> cipher,
55 const ByteVector &rapdu, const ByteVector &ks_enc,
56 const ByteVector &ks_mac, const ByteVector &ssc);
57
58 ByteVector get_session_enc_key() const;
59 ByteVector get_session_mac_key() const;
60 ByteVector get_send_session_counter() const;
61
62 virtual ByteVector auth_pad(const ByteVector &data);
63
64 virtual void compute_session_keys(const ByteVector &k_icc,
65 const ByteVector &random_icc) = 0;
66
67 virtual ByteVector compute_mac(std::shared_ptr<openssl::SymmetricCipher> cipher,
68 const ByteVector &in, const ByteVector &k_mac,
69 const ByteVector &iv = {},
70 const ByteVector &scc = {}) = 0;
71
72 virtual void reset();
73
74 std::shared_ptr<openssl::SymmetricCipher> createCipher() const;
75
79 static ByteVector pad(const ByteVector &in, unsigned int padlen = 8);
80
84 static ByteVector unpad(const ByteVector &in);
85
90 static ByteVector increment_ssc(const ByteVector &in);
91
92 static ByteVector hash_data(const ByteVector &data,
93 const std::string hash_algo = "sha1");
94
95
98
99 protected:
100 std::string cipher_;
101 std::string hash_;
110
112
116};
117}
Definition: iso24727crypto.hpp:14
bool step2_success_
Definition: iso24727crypto.hpp:111
std::string cipher_
Definition: iso24727crypto.hpp:100
ByteVector random_k_ifd_
Definition: iso24727crypto.hpp:109
ByteVector k_enc_
Definition: iso24727crypto.hpp:96
ByteVector S_mac_
Definition: iso24727crypto.hpp:114
ByteVector S_enc_
Definition: iso24727crypto.hpp:113
virtual void compute_session_keys(const ByteVector &k_icc, const ByteVector &random_icc)=0
virtual ByteVector compute_mac(std::shared_ptr< openssl::SymmetricCipher > cipher, const ByteVector &in, const ByteVector &k_mac, const ByteVector &iv={}, const ByteVector &scc={})=0
ByteVector S_send_counter_
Definition: iso24727crypto.hpp:115
std::string hash_
Definition: iso24727crypto.hpp:101
ByteVector random_ifd_
Definition: iso24727crypto.hpp:105
ByteVector k_mac_
Definition: iso24727crypto.hpp:97
std::vector< uint8_t > ByteVector
Definition: lla_fwd.hpp:80
Definition: asn1.hpp:9
SHA hash functions.
Symmetric cipher base class.