14#include "keyple/card/calypso/crypto/legacysam/CommandSamGenerateKey.hpp"
20#include "keyple/card/calypso/crypto/legacysam/AccessForbiddenException.hpp"
21#include "keyple/card/calypso/crypto/legacysam/CounterOverflowException.hpp"
22#include "keyple/card/calypso/crypto/legacysam/DataAccessException.hpp"
23#include "keyple/card/calypso/crypto/legacysam/IllegalParameterException.hpp"
24#include "keyple/card/calypso/crypto/legacysam/IncorrectInputDataException.hpp"
25#include "keyple/card/calypso/crypto/legacysam/LegacySamConstants.hpp"
26#include "keyple/core/util/ApduUtil.hpp"
27#include "keyple/core/util/ByteArrayUtil.hpp"
28#include "keyple/core/util/cpp/Arrays.hpp"
29#include "keyple/core/util/cpp/System.hpp"
37using keyple::core::util::ApduUtil;
38using keyple::core::util::ByteArrayUtil;
39using keyple::core::util::cpp::Arrays;
40using keyple::core::util::cpp::System;
42const std::map<int, const std::shared_ptr<StatusProperties>>
43 CommandSamGenerateKey::STATUS_TABLE = [] {
44 std::map<int, const std::shared_ptr<StatusProperties>> m(
45 Command::STATUS_TABLE);
49CommandSamGenerateKey::CommandSamGenerateKey(
50 std::shared_ptr<CommandContextDto> context,
51 std::uint8_t targetKeyReference,
52 std::uint8_t cipheringKvc,
53 std::uint8_t sourceKif,
54 std::uint8_t sourceKvc,
55 const std::vector<std::uint8_t>& keyParameters,
56 bool isTransferredObjectDiversified)
57: Command(CommandRef::SAM_GENERATE_KEY, 48, context)
59 const std::uint8_t cla = context->getTargetSam()->getClassByte();
60 const std::uint8_t inst = getCommandRef().getInstructionByte();
62 const std::uint8_t p1 = isTransferredObjectDiversified ? 0x01 : 0x00;
63 std::vector<std::uint8_t> dataIn(13);
64 dataIn[0] = cipheringKvc;
65 dataIn[1] = sourceKif;
66 dataIn[2] = sourceKvc;
67 System::arraycopy(keyParameters, 0, dataIn, 3, 10);
70 std::make_shared<ApduRequestAdapter>(
71 ApduUtil::build(cla, inst, p1, targetKeyReference, dataIn)));
74CommandSamGenerateKey::CommandSamGenerateKey(
75 std::shared_ptr<CommandContextDto> context,
76 std::uint8_t targetKeyReference,
77 std::uint8_t cipheringKvc,
78 std::uint8_t sourceKif,
79 std::uint8_t sourceKvc,
80 const std::vector<std::uint8_t>& keyParameters,
81 bool isTransferredObjectDiversified,
82 const std::vector<std::uint8_t>& arbitraryDiversifier)
83: Command(CommandRef::SAM_GENERATE_KEY, 48, context)
85 const std::uint8_t cla = context->getTargetSam()->getClassByte();
86 const std::uint8_t inst = getCommandRef().getInstructionByte();
88 const std::uint8_t p1 = isTransferredObjectDiversified ? 0x01 : 0x00;
89 std::vector<std::uint8_t> dataIn(13 + 8);
90 dataIn[0] = cipheringKvc;
91 dataIn[1] = sourceKif;
92 dataIn[2] = sourceKvc;
93 System::arraycopy(keyParameters, 0, dataIn, 3, 10);
94 System::arraycopy(arbitraryDiversifier, 0, dataIn, 13, 8);
97 std::make_shared<ApduRequestAdapter>(
98 ApduUtil::build(cla, inst, p1, targetKeyReference, dataIn)));
101const std::vector<std::uint8_t>&
102CommandSamGenerateKey::getCipheredData()
const
104 return mCipheredData;
108CommandSamGenerateKey::finalizeRequest()
114CommandSamGenerateKey::isControlSamRequiredToFinalizeRequest()
const
120CommandSamGenerateKey::parseResponse(
121 std::shared_ptr<ApduResponseApi> apduResponse)
123 setResponseAndCheckStatus(apduResponse);
124 mCipheredData = apduResponse->getDataOut();
127const std::map<int, const std::shared_ptr<StatusProperties>>&
128CommandSamGenerateKey::getStatusTable()
const