From bd02cbfdb08431282ce40b93cc54f9839351a8a7 Mon Sep 17 00:00:00 2001 From: NIIBE Yutaka Date: Tue, 2 Jun 2015 20:46:30 +0900 Subject: [PATCH] OpenPGPcard spec v3.0 change --- ChangeLog | 4 ++++ src/openpgp.c | 17 +++++++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 453c660..263ad46 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2015-06-02 Niibe Yutaka + + * src/openpgp.c (cmd_pso): Support OpenPGPcard spec v3.0. + 2015-04-20 Niibe Yutaka * chopstx: Upgrade to 0.05. diff --git a/src/openpgp.c b/src/openpgp.c index 43a0cdb..9468ee7 100644 --- a/src/openpgp.c +++ b/src/openpgp.c @@ -1,7 +1,7 @@ /* * openpgp.c -- OpenPGP card protocol support * - * Copyright (C) 2010, 2011, 2012, 2013, 2014 + * Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015 * Free Software Initiative of Japan * Author: NIIBE Yutaka * @@ -812,6 +812,8 @@ cmd_get_data (void) #define EDDSA_HASH_LEN_MAX 256 #define EDDSA_SIGNATURE_LENGTH 64 +#define ECC_CIPHER_DO_HEADER_SIZE 7 + static void cmd_pso (void) { @@ -940,8 +942,15 @@ cmd_pso (void) } else if (attr == ALGO_NISTP256R1 || attr == ALGO_SECP256K1) { + int header_size = -1; + + if (len == 65) + header_size = 0; + else if (len == 65 + ECC_CIPHER_DO_HEADER_SIZE) + header_size = ECC_CIPHER_DO_HEADER_SIZE; + /* Format is in big endian MPI: 04 || x || y */ - if (len != 65 || apdu.cmd_apdu_data[0] != 4) + if (header_size < 0 || apdu.cmd_apdu_data[header_size] != 4) { GPG_CONDITION_NOT_SATISFIED (); return; @@ -949,10 +958,10 @@ cmd_pso (void) result_len = 65; if (attr == ALGO_NISTP256R1) - r = ecdh_decrypt_p256r1 (apdu.cmd_apdu_data, res_APDU, + r = ecdh_decrypt_p256r1 (apdu.cmd_apdu_data + header_size, res_APDU, kd[GPG_KEY_FOR_DECRYPTION].data); else - r = ecdh_decrypt_p256k1 (apdu.cmd_apdu_data, res_APDU, + r = ecdh_decrypt_p256k1 (apdu.cmd_apdu_data + header_size, res_APDU, kd[GPG_KEY_FOR_DECRYPTION].data); } else