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 <gniibe@fsij.org>
This commit is contained in:
NIIBE Yutaka 2016-10-27 11:56:18 +09:00
parent b648f28f9f
commit 6bbd97d6c7
1 changed files with 21 additions and 12 deletions

View File

@ -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 */