From 37daaf11929bdfea1b5249c195af0f0a8b52aee8 Mon Sep 17 00:00:00 2001 From: Frank Morgner Date: Wed, 7 Aug 2013 21:43:46 +0200 Subject: [PATCH] read/write chunks in short length SM APDUs --- npa/src/npa/iso-sm.h | 14 ++++++++++++++ npa/src/scutil.c | 9 ++------- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/npa/src/npa/iso-sm.h b/npa/src/npa/iso-sm.h index c495315..8c4a90f 100644 --- a/npa/src/npa/iso-sm.h +++ b/npa/src/npa/iso-sm.h @@ -30,6 +30,20 @@ extern "C" { #endif +/** @brief maximum length of response when targeting a SM RAPDU + * + * Using SM with authenticated data+le and encrypted data this is the biggest + * amount of the unencrypted response data we can receive. We assume AES block + * length for padding and MAC. */ +#define MAX_SM_APDU_RESP_SIZE 223 + +/** @brief maximum length of data when targeting a SM APDU + * + * Using SM with authenticated data+header and encrypted data this is the + * biggest amount of the unencrypted data we can send. We assume AES block + * length for padding and MAC. */ +#define MAX_SM_APDU_DATA_SIZE 239 + /** @brief Padding indicator: use ISO/IEC 9797-1 padding method 2 */ #define SM_ISO_PADDING 0x01 /** @brief Padding indicator: use no padding */ diff --git a/npa/src/scutil.c b/npa/src/scutil.c index 71a74eb..01f591e 100644 --- a/npa/src/scutil.c +++ b/npa/src/scutil.c @@ -148,16 +148,13 @@ int print_avail(int verbose) return r; } -#define maxresp SC_MAX_APDU_BUFFER_SIZE - 2 #define ISO_READ_BINARY 0xB0 #define ISO_P1_FLAG_SFID 0x80 int read_binary_rec(sc_card_t *card, unsigned char sfid, u8 **ef, size_t *ef_len) { int r; - /* we read less bytes than possible. this is a workaround for acr 122, - * which only supports apdus of max 250 bytes */ - size_t read = maxresp - 8; + size_t read = MAX_SM_APDU_RESP_SIZE; sc_apdu_t apdu; u8 *p; @@ -222,9 +219,7 @@ int write_binary_rec(sc_card_t *card, unsigned char sfid, u8 *ef, size_t ef_len) { int r; - /* we write less bytes than possible. this is a workaround for acr 122, - * which only supports apdus of max 250 bytes */ - size_t write = maxresp - 8, wrote = 0; + size_t write = MAX_SM_APDU_DATA_SIZE, wrote = 0; sc_apdu_t apdu; struct iso_sm_ctx *iso_sm_ctx = card->sm_ctx.info.cmd_data;