aboutsummaryrefslogtreecommitdiffstats
path: root/scd/app-openpgp.c
diff options
context:
space:
mode:
authorNIIBE Yutaka <[email protected]>2016-10-27 02:56:18 +0000
committerNIIBE Yutaka <[email protected]>2016-10-27 04:04:29 +0000
commit6bbd97d6c771b2e2c7cfcff6d5a823f0fb44d443 (patch)
tree272fe450db0c363690b480092a4f253b89db208a /scd/app-openpgp.c
parentg10: ECDH shared point format. (diff)
downloadgnupg-6bbd97d6c771b2e2c7cfcff6d5a823f0fb44d443.tar.gz
gnupg-6bbd97d6c771b2e2c7cfcff6d5a823f0fb44d443.zip
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 <[email protected]>
Diffstat (limited to 'scd/app-openpgp.c')
-rw-r--r--scd/app-openpgp.c33
1 files 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 */