[Pkg-gnupg-commit] [gnupg2] 173/292: scd: Add 0x41 prefix for x-coordinate only result.

Daniel Kahn Gillmor dkg at fifthhorseman.net
Mon Nov 21 06:31:39 UTC 2016


This is an automated email from the git hooks/post-receive script.

dkg pushed a commit to branch master
in repository gnupg2.

commit 6bbd97d6c771b2e2c7cfcff6d5a823f0fb44d443
Author: NIIBE Yutaka <gniibe at fsij.org>
Date:   Thu Oct 27 11:56:18 2016 +0900

    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 at fsij.org>
---
 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 4e042e7..d75721f 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 */

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-gnupg/gnupg2.git



More information about the Pkg-gnupg-commit mailing list