bug fix of OPENPGP.3 singing
authorNIIBE Yutaka <gniibe@fsij.org>
Wed, 25 Feb 2015 01:03:41 +0000 (10:03 +0900)
committerNIIBE Yutaka <gniibe@fsij.org>
Wed, 25 Feb 2015 01:03:41 +0000 (10:03 +0900)
ChangeLog
src/openpgp.c

index b0aac5c..3c952e7 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2015-02-25  Niibe Yutaka  <gniibe@fsij.org>
+
+       * src/openpgp.c (cmd_internal_authenticate): Fix storing to
+       res_APDU_size.
+
 2015-02-10  Niibe Yutaka  <gniibe@fsij.org>
 
        * src/openpgp.c (cmd_pso): Fix counter update for EdDSA.  Thanks
index c3107a0..43a0cdb 100644 (file)
@@ -988,6 +988,7 @@ cmd_internal_authenticate (void)
                                               GPG_KEY_PUBLIC);
   int len = apdu.cmd_apdu_data_len;
   int r = -1;
+  unsigned int result_len = 0;
 
   DEBUG_INFO (" - INTERNAL AUTHENTICATE\r\n");
 
@@ -1018,6 +1019,7 @@ cmd_internal_authenticate (void)
          return;
        }
 
+      result_len = pubkey_len;
       r = rsa_sign (apdu.cmd_apdu_data, res_APDU, len,
                    &kd[GPG_KEY_FOR_AUTHENTICATION], pubkey_len);
     }    
@@ -1030,7 +1032,7 @@ cmd_internal_authenticate (void)
          return;
        }
 
-      res_APDU_size = ECDSA_SIGNATURE_LENGTH;
+      result_len = ECDSA_SIGNATURE_LENGTH;
       r = ecdsa_sign_p256r1 (apdu.cmd_apdu_data, res_APDU,
                             kd[GPG_KEY_FOR_AUTHENTICATION].data);
     }
@@ -1043,7 +1045,7 @@ cmd_internal_authenticate (void)
          return;
        }
 
-      res_APDU_size = ECDSA_SIGNATURE_LENGTH;
+      result_len = ECDSA_SIGNATURE_LENGTH;
       r = ecdsa_sign_p256k1 (apdu.cmd_apdu_data, res_APDU,
                             kd[GPG_KEY_FOR_AUTHENTICATION].data);
     }
@@ -1058,7 +1060,7 @@ cmd_internal_authenticate (void)
          return;
        }
 
-      res_APDU_size = EDDSA_SIGNATURE_LENGTH;
+      result_len = EDDSA_SIGNATURE_LENGTH;
       r = eddsa_sign_25519 (apdu.cmd_apdu_data, len, output,
                            kd[GPG_KEY_FOR_AUTHENTICATION].data,
                            kd[GPG_KEY_FOR_AUTHENTICATION].data+32,
@@ -1066,7 +1068,9 @@ cmd_internal_authenticate (void)
       memcpy (res_APDU, output, EDDSA_SIGNATURE_LENGTH);
     }
 
-  if (r < 0)
+  if (r == 0)
+    res_APDU_size = result_len;
+  else
     GPG_ERROR ();
 
   DEBUG_INFO ("INTERNAL AUTHENTICATE done.\r\n");