From 6bbd97d6c771b2e2c7cfcff6d5a823f0fb44d443 Mon Sep 17 00:00:00 2001 From: NIIBE Yutaka Date: Thu, 27 Oct 2016 11:56:18 +0900 Subject: [PATCH] scd: Add 0x41 prefix for x-coordinate only result. * scd/app-openpgp.c (do_decipher): When it's x-coordinate only, add the prefix 0x41. -- Card should return fixed size bytes, either in format of (04 || X || Y) or (X, x-coordinate only). Signed-off-by: NIIBE Yutaka --- scd/app-openpgp.c | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/scd/app-openpgp.c b/scd/app-openpgp.c index 4e042e728..d75721fc3 100644 --- a/scd/app-openpgp.c +++ b/scd/app-openpgp.c @@ -4406,20 +4406,29 @@ do_decipher (app_t app, const char *keyidstr, indata, indatalen, le_value, padind, outdata, outdatalen); xfree (fixbuf); - if (app->app_local->keyattr[1].key_type == KEY_TYPE_ECC - && (app->app_local->keyattr[1].ecc.flags & ECC_FLAG_DJB_TWEAK)) - { /* Add the prefix 0x40 */ - fixbuf = xtrymalloc (*outdatalen + 1); - if (!fixbuf) - { + if (app->app_local->keyattr[1].key_type == KEY_TYPE_ECC) + { + unsigned char prefix = 0; + + if (app->app_local->keyattr[1].ecc.flags & ECC_FLAG_DJB_TWEAK) + prefix = 0x40; + else if ((*outdatalen % 2) == 0) /* No 0x04 -> x-coordinate only */ + prefix = 0x41; + + if (prefix) + { /* Add the prefix */ + fixbuf = xtrymalloc (*outdatalen + 1); + if (!fixbuf) + { + xfree (*outdata); + return gpg_error_from_syserror (); + } + fixbuf[0] = prefix; + memcpy (fixbuf+1, *outdata, *outdatalen); xfree (*outdata); - return gpg_error_from_syserror (); + *outdata = fixbuf; + *outdatalen = *outdatalen + 1; } - fixbuf[0] = 0x40; - memcpy (fixbuf+1, *outdata, *outdatalen); - xfree (*outdata); - *outdata = fixbuf; - *outdatalen = *outdatalen + 1; } if (gpg_err_code (rc) == GPG_ERR_CARD /* actual SW is 0x640a */