From cvs at cvs.gnupg.org Sun Mar 3 02:51:44 2013 From: cvs at cvs.gnupg.org (by David Shaw) Date: Sun, 03 Mar 2013 02:51:44 +0100 Subject: [git] GnuPG - branch, STABLE-BRANCH-1-4, updated. gnupg-1.4.13-7-g6f0ec6a Message-ID: This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "The GNU Privacy Guard". The branch, STABLE-BRANCH-1-4 has been updated via 6f0ec6ab485f48c8079ab2a16ed41ee7859f88ab (commit) via ca0b94d4d41c81045ed97fad0569ff4b64e5a6fe (commit) from 1edc1b3751496885b236f5ab1194ad667c96b174 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 6f0ec6ab485f48c8079ab2a16ed41ee7859f88ab Author: David Shaw Date: Sat Mar 2 20:39:48 2013 -0500 Differentiate between success (full or partial), not-found, and failure. * keyserver/gpgkeys_hkp.c (get_key): Use curl_easy_setinfo to get the HTTP status code so we can tell the difference between a successful retrieval, a partial retrieval, a not-found, or a server failed. diff --git a/keyserver/gpgkeys_hkp.c b/keyserver/gpgkeys_hkp.c index bc2f044..309e728 100644 --- a/keyserver/gpgkeys_hkp.c +++ b/keyserver/gpgkeys_hkp.c @@ -1,6 +1,6 @@ /* gpgkeys_hkp.c - talk to an HKP keyserver * Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, - * 2009, 2012 Free Software Foundation, Inc. + * 2009, 2012, 2013 Free Software Foundation, Inc. * * This file is part of GnuPG. * @@ -312,15 +312,49 @@ get_key(char *getkey) } else { + long status = 0; + curl_writer_finalize(&ctx); - if(!ctx.flags.done) + + curl_easy_getinfo (curl, CURLINFO_RESPONSE_CODE, &status); + + if (opt->verbose > 2) + fprintf (console, "gpgkeys: HTTP response code is %ld\n", status); + + if (status == 200) + { + if (!ctx.flags.done) + { + if (ctx.flags.begun) + { + fprintf (console, "gpgkeys: key %s partially retrieved" + " (probably corrupt)\n", getkey); + fprintf (output, "\nKEY 0x%s FAILED %d\n", + getkey, KEYSERVER_KEY_INCOMPLETE); + } + else + { + fprintf (console, "gpgkeys: key %s can't be retrieved\n", + getkey); + fprintf (output, "\nKEY 0x%s FAILED %d\n", + getkey, KEYSERVER_GENERAL_ERROR); + } + } + else + fprintf (output, "\nKEY 0x%s END\n", getkey); + } + else if (status == 404) { - fprintf(console,"gpgkeys: key %s not found on keyserver\n",getkey); - fprintf(output,"\nKEY 0x%s FAILED %d\n", - getkey,KEYSERVER_KEY_NOT_FOUND); + fprintf (console, "gpgkeys: key %s not found on keyserver\n", getkey); + fprintf (output, "\nKEY 0x%s FAILED %d\n", + getkey, KEYSERVER_KEY_NOT_FOUND); } else - fprintf(output,"\nKEY 0x%s END\n",getkey); + { + fprintf (console, "gpgkeys: key %s can't be retrieved\n", getkey); + fprintf (output, "\nKEY 0x%s FAILED %d\n", + getkey, KEYSERVER_GENERAL_ERROR); + } } return KEYSERVER_OK; @@ -383,16 +417,47 @@ get_name(const char *getkey) } else { + long status = 0; + curl_writer_finalize(&ctx); - if(!ctx.flags.done) + + curl_easy_getinfo (curl, CURLINFO_RESPONSE_CODE, &status); + + if (opt->verbose > 2) + fprintf (console, "gpgkeys: HTTP response code is %ld\n", status); + + if (status == 200) + { + if (!ctx.flags.done) + { + if (ctx.flags.begun) + { + fprintf (console, "gpgkeys: key %s partially retrieved" + " (probably corrupt)\n", getkey); + ret = KEYSERVER_KEY_INCOMPLETE; + } + else + { + fprintf (console, "gpgkeys: key %s can't be retrieved\n", + getkey); + ret = KEYSERVER_GENERAL_ERROR; + } + } + else + { + fprintf (output, "\nNAME %s END\n", getkey); + ret = KEYSERVER_OK; + } + } + else if (status == 404) { - fprintf(console,"gpgkeys: key %s not found on keyserver\n",getkey); - ret=KEYSERVER_KEY_NOT_FOUND; + fprintf (console, "gpgkeys: key %s not found on keyserver\n", getkey); + ret = KEYSERVER_KEY_NOT_FOUND; } else { - fprintf(output,"\nNAME %s END\n",getkey); - ret=KEYSERVER_OK; + fprintf (console, "gpgkeys: key %s can't be retrieved\n", getkey); + ret = KEYSERVER_GENERAL_ERROR; } } commit ca0b94d4d41c81045ed97fad0569ff4b64e5a6fe Author: David Shaw Date: Sat Mar 2 20:07:27 2013 -0500 Emulate curl_easy_getinfo and CURLINFO_RESPONSE_CODE in curl-shim. * keyserver/curl-shim.h, keyserver/curl-shim.c (curl_easy_getinfo): New. Return the HTTP status code for the last transfer. diff --git a/keyserver/curl-shim.c b/keyserver/curl-shim.c index 857b5c1..ce510cb 100644 --- a/keyserver/curl-shim.c +++ b/keyserver/curl-shim.c @@ -1,7 +1,8 @@ /* curl-shim.c - Implement a small subset of the curl API in terms of * the iobuf HTTP API * - * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2012 Free Software Foundation, Inc. + * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2012, + * 2013 Free Software Foundation, Inc. * * This file is part of GnuPG. * @@ -291,6 +292,27 @@ curl_easy_perform(CURL *curl) return handle_error(curl,err,errstr); } +CURLcode +curl_easy_getinfo(CURL *curl, CURLINFO info, ... ) +{ + va_list ap; + long *var; + + va_start(ap,info); + + switch(info) + { + case CURLINFO_RESPONSE_CODE: + var=va_arg(ap,long *); + *var=curl->status; + break; + default: + break; + } + + return handle_error(curl,CURLE_OK,NULL); +} + /* This is not the same exact set that is allowed according to RFC-2396, but it is what the real curl uses. */ #define VALID_URI_CHARS "abcdefghijklmnopqrstuvwxyz" \ diff --git a/keyserver/curl-shim.h b/keyserver/curl-shim.h index 0d378e8..a8609df 100644 --- a/keyserver/curl-shim.h +++ b/keyserver/curl-shim.h @@ -1,5 +1,6 @@ /* curl-shim.h - * Copyright (C) 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc. + * Copyright (C) 2005, 2006, 2007, 2008, 2009, + * 2013 Free Software Foundation, Inc. * * This file is part of GNUPG. * @@ -53,6 +54,11 @@ typedef enum CURLOPT_SRVTAG_GPG_HACK } CURLoption; +typedef enum + { + CURLINFO_RESPONSE_CODE + } CURLINFO; + typedef size_t (*write_func)(char *buffer,size_t size, size_t nitems,void *outstream); @@ -92,6 +98,7 @@ void curl_global_cleanup(void); CURL *curl_easy_init(void); CURLcode curl_easy_setopt(CURL *curl,CURLoption option,...); CURLcode curl_easy_perform(CURL *curl); +CURLcode curl_easy_getinfo(CURL *curl, CURLINFO info, ... ); void curl_easy_cleanup(CURL *curl); char *curl_easy_escape(CURL *curl,char *str,int len); #define curl_free(x) free(x) ----------------------------------------------------------------------- Summary of changes: keyserver/curl-shim.c | 24 ++++++++++++- keyserver/curl-shim.h | 9 ++++- keyserver/gpgkeys_hkp.c | 87 +++++++++++++++++++++++++++++++++++++++++------ 3 files changed, 107 insertions(+), 13 deletions(-) hooks/post-receive -- The GNU Privacy Guard http://git.gnupg.org From cvs at cvs.gnupg.org Sun Mar 3 03:08:00 2013 From: cvs at cvs.gnupg.org (by David Shaw) Date: Sun, 03 Mar 2013 03:08:00 +0100 Subject: [git] GnuPG - branch, STABLE-BRANCH-2-0, updated. gnupg-2.0.19-90-g6d0e418 Message-ID: This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "The GNU Privacy Guard". The branch, STABLE-BRANCH-2-0 has been updated via 6d0e41815a726ad4b170ed18cc772a1817559299 (commit) via 7808e4a763692b8bcd95264d39caf85fad32f0bd (commit) from fe85638284880805b80778fe87ae551d3de0ca32 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 6d0e41815a726ad4b170ed18cc772a1817559299 Author: David Shaw Date: Sat Mar 2 20:39:48 2013 -0500 Differentiate between success (full or partial), not-found, and failure. * keyserver/gpgkeys_hkp.c (get_key): Use curl_easy_setinfo to get the HTTP status code so we can tell the difference between a successful retrieval, a partial retrieval, a not-found, or a server failed. diff --git a/keyserver/gpgkeys_hkp.c b/keyserver/gpgkeys_hkp.c index d90027a..f0647d7 100644 --- a/keyserver/gpgkeys_hkp.c +++ b/keyserver/gpgkeys_hkp.c @@ -1,6 +1,6 @@ /* gpgkeys_hkp.c - talk to an HKP keyserver * Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, - * 2009, 2012 Free Software Foundation, Inc. + * 2009, 2012, 2013 Free Software Foundation, Inc. * * This file is part of GnuPG. * @@ -319,15 +319,49 @@ get_key(char *getkey) } else { + long status = 0; + curl_writer_finalize(&ctx); - if(!ctx.flags.done) + + curl_easy_getinfo (curl, CURLINFO_RESPONSE_CODE, &status); + + if (opt->verbose > 2) + fprintf (console, "gpgkeys: HTTP response code is %ld\n", status); + + if (status == 200) + { + if (!ctx.flags.done) + { + if (ctx.flags.begun) + { + fprintf (console, "gpgkeys: key %s partially retrieved" + " (probably corrupt)\n", getkey); + fprintf (output, "\nKEY 0x%s FAILED %d\n", + getkey, KEYSERVER_KEY_INCOMPLETE); + } + else + { + fprintf (console, "gpgkeys: key %s can't be retrieved\n", + getkey); + fprintf (output, "\nKEY 0x%s FAILED %d\n", + getkey, KEYSERVER_GENERAL_ERROR); + } + } + else + fprintf (output, "\nKEY 0x%s END\n", getkey); + } + else if (status == 404) { - fprintf(console,"gpgkeys: key %s not found on keyserver\n",getkey); - fprintf(output,"\nKEY 0x%s FAILED %d\n", - getkey,KEYSERVER_KEY_NOT_FOUND); + fprintf (console, "gpgkeys: key %s not found on keyserver\n", getkey); + fprintf (output, "\nKEY 0x%s FAILED %d\n", + getkey, KEYSERVER_KEY_NOT_FOUND); } else - fprintf(output,"\nKEY 0x%s END\n",getkey); + { + fprintf (console, "gpgkeys: key %s can't be retrieved\n", getkey); + fprintf (output, "\nKEY 0x%s FAILED %d\n", + getkey, KEYSERVER_GENERAL_ERROR); + } } return KEYSERVER_OK; @@ -388,16 +422,47 @@ get_name(const char *getkey) } else { + long status = 0; + curl_writer_finalize(&ctx); - if(!ctx.flags.done) + + curl_easy_getinfo (curl, CURLINFO_RESPONSE_CODE, &status); + + if (opt->verbose > 2) + fprintf (console, "gpgkeys: HTTP response code is %ld\n", status); + + if (status == 200) + { + if (!ctx.flags.done) + { + if (ctx.flags.begun) + { + fprintf (console, "gpgkeys: key %s partially retrieved" + " (probably corrupt)\n", getkey); + ret = KEYSERVER_KEY_INCOMPLETE; + } + else + { + fprintf (console, "gpgkeys: key %s can't be retrieved\n", + getkey); + ret = KEYSERVER_GENERAL_ERROR; + } + } + else + { + fprintf (output, "\nNAME %s END\n", getkey); + ret = KEYSERVER_OK; + } + } + else if (status == 404) { - fprintf(console,"gpgkeys: key %s not found on keyserver\n",getkey); - ret=KEYSERVER_KEY_NOT_FOUND; + fprintf (console, "gpgkeys: key %s not found on keyserver\n", getkey); + ret = KEYSERVER_KEY_NOT_FOUND; } else { - fprintf(output,"\nNAME %s END\n",getkey); - ret=KEYSERVER_OK; + fprintf (console, "gpgkeys: key %s can't be retrieved\n", getkey); + ret = KEYSERVER_GENERAL_ERROR; } } commit 7808e4a763692b8bcd95264d39caf85fad32f0bd Author: David Shaw Date: Sat Mar 2 20:07:27 2013 -0500 Emulate curl_easy_getinfo and CURLINFO_RESPONSE_CODE in curl-shim. * keyserver/curl-shim.h, keyserver/curl-shim.c (curl_easy_getinfo): New. Return the HTTP status code for the last transfer. diff --git a/keyserver/curl-shim.c b/keyserver/curl-shim.c index 136436a..be87780 100644 --- a/keyserver/curl-shim.c +++ b/keyserver/curl-shim.c @@ -1,8 +1,8 @@ /* curl-shim.c - Implement a small subset of the curl API in terms of * the iobuf HTTP API * - * Copyright (C) 2005, 2006, 2007, 2008, 2009, - * 2012 Free Software Foundation, Inc. + * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2012, + * 2013 Free Software Foundation, Inc. * * This file is part of GnuPG. * @@ -307,6 +307,27 @@ curl_easy_perform(CURL *curl) return handle_error(curl,err,errstr); } +CURLcode +curl_easy_getinfo(CURL *curl, CURLINFO info, ... ) +{ + va_list ap; + long *var; + + va_start(ap,info); + + switch(info) + { + case CURLINFO_RESPONSE_CODE: + var=va_arg(ap,long *); + *var=curl->status; + break; + default: + break; + } + + return handle_error(curl,CURLE_OK,NULL); +} + /* This is not the same exact set that is allowed according to RFC-2396, but it is what the real curl uses. */ #define VALID_URI_CHARS "abcdefghijklmnopqrstuvwxyz" \ diff --git a/keyserver/curl-shim.h b/keyserver/curl-shim.h index e37d816..df28fcc 100644 --- a/keyserver/curl-shim.h +++ b/keyserver/curl-shim.h @@ -1,5 +1,6 @@ /* curl-shim.h - * Copyright (C) 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc. + * Copyright (C) 2005, 2006, 2007, 2008, 2009, + * 2013 Free Software Foundation, Inc. * * This file is part of GNUPG. * @@ -54,6 +55,11 @@ typedef enum CURLOPT_SRVTAG_GPG_HACK } CURLoption; +typedef enum + { + CURLINFO_RESPONSE_CODE + } CURLINFO; + typedef size_t (*write_func)(char *buffer,size_t size, size_t nitems,void *outstream); @@ -93,6 +99,7 @@ void curl_global_cleanup(void); CURL *curl_easy_init(void); CURLcode curl_easy_setopt(CURL *curl,CURLoption option,...); CURLcode curl_easy_perform(CURL *curl); +CURLcode curl_easy_getinfo(CURL *curl, CURLINFO info, ... ); void curl_easy_cleanup(CURL *curl); char *curl_escape(char *str,int len); #define curl_free(x) free(x) ----------------------------------------------------------------------- Summary of changes: keyserver/curl-shim.c | 25 ++++++++++++- keyserver/curl-shim.h | 9 ++++- keyserver/gpgkeys_hkp.c | 87 +++++++++++++++++++++++++++++++++++++++++------ 3 files changed, 107 insertions(+), 14 deletions(-) hooks/post-receive -- The GNU Privacy Guard http://git.gnupg.org From cvs at cvs.gnupg.org Mon Mar 4 12:01:39 2013 From: cvs at cvs.gnupg.org (by Thomas Gries) Date: Mon, 04 Mar 2013 12:01:39 +0100 Subject: [git] Pinentry - branch, master, updated. pinentry-0.8.2-7-gc7c41b2 Message-ID: This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "The standard pinentry collection". The branch, master has been updated via c7c41b22c059c39916845061484999005c9483d1 (commit) from 462f00dfc6636fbfe2e453c1b820d919ec1d0c99 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit c7c41b22c059c39916845061484999005c9483d1 Author: Thomas Gries Date: Tue Feb 26 14:23:18 2013 +0100 Fix help output. -- diff --git a/pinentry/pinentry.c b/pinentry/pinentry.c index 13b45f2..19bea31 100644 --- a/pinentry/pinentry.c +++ b/pinentry/pinentry.c @@ -419,7 +419,7 @@ usage (void) " -e, --enhanced Ask for timeout and insurance, too\n" #endif " -g, --no-global-grab Grab keyboard only while window is focused\n" -" --parent-wid Parent window ID (for positioning)\n" +" --parent-wid Parent window ID (for positioning)\n" " -d, --debug Turn on debugging output\n" " -h, --help Display this help and exit\n" " --version Output version information and exit\n", this_pgmname); ----------------------------------------------------------------------- Summary of changes: pinentry/pinentry.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) hooks/post-receive -- The standard pinentry collection http://git.gnupg.org From cvs at cvs.gnupg.org Tue Mar 5 11:14:49 2013 From: cvs at cvs.gnupg.org (by Daniel Kahn Gillmor) Date: Tue, 05 Mar 2013 11:14:49 +0100 Subject: [git] GnuPG - branch, master, updated. gnupg-2.1.0beta3-165-g5132ea8 Message-ID: This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "The GNU Privacy Guard". The branch, master has been updated via 5132ea8a0d8517dd43cb5b4a4b0921c3b1ca291c (commit) via 5bac5040dc93343e1e89916b263390b0e52040bf (commit) from ef1983d58b913306e9bf02a7189e530123839c59 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 5132ea8a0d8517dd43cb5b4a4b0921c3b1ca291c Author: Daniel Kahn Gillmor Date: Tue Mar 5 04:24:54 2013 -0500 Update RFC references to RFC 4880 -- diff --git a/doc/gpg.texi b/doc/gpg.texi index cf647e1..0462c9e 100644 --- a/doc/gpg.texi +++ b/doc/gpg.texi @@ -2418,7 +2418,7 @@ check. @code{value} may be any printable string; it will be encoded in UTF8, so you should check that your @option{--display-charset} is set correctly. If you prefix @code{name} with an exclamation mark (!), the notation data will be flagged as critical -(rfc2440:5.2.3.15). @option{--sig-notation} sets a notation for data +(rfc4880:5.2.3.16). @option{--sig-notation} sets a notation for data signatures. @option{--cert-notation} sets a notation for key signatures (certifications). @option{--set-notation} sets both. @@ -2440,7 +2440,7 @@ meaningful when using the OpenPGP smartcard. @opindex sig-policy-url @opindex cert-policy-url @opindex set-policy-url -Use @code{string} as a Policy URL for signatures (rfc2440:5.2.3.19). If +Use @code{string} as a Policy URL for signatures (rfc4880:5.2.3.20). If you prefix it with an exclamation mark (!), the policy URL packet will be flagged as critical. @option{--sig-policy-url} sets a policy url for data signatures. @option{--cert-policy-url} sets a policy url for key commit 5bac5040dc93343e1e89916b263390b0e52040bf Author: Werner Koch Date: Mon Feb 25 13:40:10 2013 +0100 Require libgpg-error 1.11. * configure.ac: Require libgpg-error 1.11. * common/util.h (GPG_ERR_NO_KEYSERVER, GPG_ERR_INV_CURVE) (GPG_ERR_UNKNOWN_CURVE): Remove fallback definitions. diff --git a/common/util.h b/common/util.h index c8a008f..73ba84e 100644 --- a/common/util.h +++ b/common/util.h @@ -34,16 +34,6 @@ #include /* We need this for the memory function protos. */ #include /* We need errno. */ #include /* We need gpg_error_t. */ -/* Add error codes available only in newer versions of libgpg-error. */ -#ifndef GPG_ERR_NO_KEYSERVER -#define GPG_ERR_NO_KEYSERVER 186 -#endif -#ifndef GPG_ERR_INV_CURVE -#define GPG_ERR_INV_CURVE 187 -#endif -#ifndef GPG_ERR_UNKNOWN_CURVE -#define GPG_ERR_UNKNOWN_CURVE 188 -#endif /* Hash function used with libksba. */ diff --git a/configure.ac b/configure.ac index cf5ab3f..353546a 100644 --- a/configure.ac +++ b/configure.ac @@ -43,7 +43,7 @@ m4_define([mym4_full_version],[mym4_version[]mym4_betastring]) AC_INIT([gnupg],[mym4_full_version], [http://bugs.gnupg.org]) -NEED_GPG_ERROR_VERSION=1.10 +NEED_GPG_ERROR_VERSION=1.11 NEED_LIBGCRYPT_API=1 NEED_LIBGCRYPT_VERSION=1.5.0 ----------------------------------------------------------------------- Summary of changes: common/util.h | 10 ---------- configure.ac | 2 +- doc/gpg.texi | 4 ++-- 3 files changed, 3 insertions(+), 13 deletions(-) hooks/post-receive -- The GNU Privacy Guard http://git.gnupg.org From cvs at cvs.gnupg.org Thu Mar 7 14:35:45 2013 From: cvs at cvs.gnupg.org (by Werner Koch) Date: Thu, 07 Mar 2013 14:35:45 +0100 Subject: [git] GCRYPT - branch, master, updated. libgcrypt-1.5.0-89-g6782b2d Message-ID: This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "The GNU crypto library". The branch, master has been updated via 6782b2d7817c449fb2cf122cacd792b594f89d7c (commit) via c620099e4ab2f35e0196b395a805bb655c984ac2 (commit) from 70dcac663de06b012417015c175973d64e6980df (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 6782b2d7817c449fb2cf122cacd792b594f89d7c Author: Werner Koch Date: Thu Mar 7 14:15:12 2013 +0100 Add Christian to the list of authors. -- diff --git a/AUTHORS b/AUTHORS index a2c36da..b1bad22 100644 --- a/AUTHORS +++ b/AUTHORS @@ -112,6 +112,7 @@ DCO:2012-04-20:Rafa?l Carr? DCO:2012-11-14:Jussi Kivilinna DCO:2012-12-05:Werner Koch DCO:2012-12-14:Dmitry Kasatkin +DCO:2013-02-26:Christian Aistleitner More credits commit c620099e4ab2f35e0196b395a805bb655c984ac2 Author: Werner Koch Date: Thu Mar 7 14:13:33 2013 +0100 Pretty print the configure feedback. * acinclude.m4 (GNUPG_MSG_PRINT): Remove. (GCRY_MSG_SHOW, GCRY_MSG_WRAP): New. * configure.ac: Use new macros for the feedback. diff --git a/acinclude.m4 b/acinclude.m4 index e69291a..fdb2d17 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -1,6 +1,7 @@ dnl macros to configure Libgcrypt dnl Copyright (C) 1998, 1999, 2000, 2001, 2002, dnl 2003 Free Software Foundation, Inc. +dnl Copyright (C) 2013 g10 Code GmbH dnl dnl This file is part of Libgcrypt. dnl @@ -18,13 +19,43 @@ dnl You should have received a copy of the GNU Lesser General Public dnl License along with this program; if not, write to the Free Software dnl Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA -dnl GNUPG_MSG_PRINT(STRING) -dnl print a message +dnl GCRY_MSG_SHOW(PREFIX,STRING) +dnl Print a message with a prefix. dnl -define([GNUPG_MSG_PRINT], - [ echo $ac_n "$1"" $ac_c" 1>&AS_MESSAGE_FD([]) +define([GCRY_MSG_SHOW], + [ + echo " $1 $2" 1>&AS_MESSAGE_FD([]) + ]) + +dnl GCRY_MSG_WRAP(PREFIX, ALGOLIST) +dnl Print a nicely formatted list of algorithms +dnl with an approriate line wrap. +dnl +define([GCRY_MSG_WRAP], + [ + tmp=" $1" + tmpi="abc" + if test "${#tmpi}" -ne 3 >/dev/null 2>&1 ; then + dnl Without a POSIX shell, we don't botter to wrap it + echo "$tmp $2" 1>&AS_MESSAGE_FD([]) + else + tmpi=`echo "$tmp"| sed 's/./ /g'` + echo $2 EOF | tr ' ' '\n' | \ + while read word; do + if test "${#tmp}" -gt 70 ; then + echo "$tmp" 1>&AS_MESSAGE_FD([]) + tmp="$tmpi" + fi + if test "$word" = "EOF" ; then + echo "$tmp" 1>&AS_MESSAGE_FD([]) + else + tmp="$tmp $word" + fi + done + fi ]) + dnl GNUPG_CHECK_TYPEDEF(TYPE, HAVE_NAME) dnl Check whether a typedef exists and create a #define $2 if it exists dnl diff --git a/configure.ac b/configure.ac index 1f057f7..7afd83d 100644 --- a/configure.ac +++ b/configure.ac @@ -1380,21 +1380,21 @@ detection_module="${GCRYPT_HWF_MODULES%.lo}" test -n "$detection_module" || detection_module="none" # Give some feedback -echo " - Libgcrypt v${VERSION} has been configured as follows: - - Platform: $PRINTABLE_OS_NAME ($host) - Hardware detection module: $detection_module - Enabled cipher algorithms: $enabled_ciphers - Enabled digest algorithms: $enabled_digests - Enabled pubkey algorithms: $enabled_pubkey_ciphers - Random number generator: $random - Using linux capabilities: $use_capabilities - Try using Padlock crypto: $padlocksupport - Try using AES-NI crypto: $aesnisupport - Try using DRNG (RDRAND): $drngsupport - Try using Intel AVX: $avxsupport -" +GCRY_MSG_SHOW([],[]) +GCRY_MSG_SHOW([Libgcrypt],[v${VERSION} has been configured as follows:]) +GCRY_MSG_SHOW([],[]) +GCRY_MSG_SHOW([Platform: ],[$PRINTABLE_OS_NAME ($host)]) +GCRY_MSG_SHOW([Hardware detection module:],[$detection_module]) +GCRY_MSG_WRAP([Enabled cipher algorithms:],[$enabled_ciphers]) +GCRY_MSG_WRAP([Enabled digest algorithms:],[$enabled_digests]) +GCRY_MSG_WRAP([Enabled pubkey algorithms:],[$enabled_pubkey_ciphers]) +GCRY_MSG_SHOW([Random number generator: ],[$random]) +GCRY_MSG_SHOW([Using linux capabilities: ],[$use_capabilities]) +GCRY_MSG_SHOW([Try using Padlock crypto: ],[$padlocksupport]) +GCRY_MSG_SHOW([Try using AES-NI crypto: ],[$aesnisupport]) +GCRY_MSG_SHOW([Try using DRNG (RDRAND): ],[$drngsupport]) +GCRY_MSG_SHOW([Try using Intel AVX: ],[$avxsupport]) +GCRY_MSG_SHOW([],[]) if test "$print_egd_notice" = "yes"; then cat < This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "The GNU Privacy Guard". The branch, master has been updated via 010bc7f4f06d8affb98950e1adc76c68bfcc9abb (commit) from 5132ea8a0d8517dd43cb5b4a4b0921c3b1ca291c (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 010bc7f4f06d8affb98950e1adc76c68bfcc9abb Author: NIIBE Yutaka Date: Fri Mar 8 11:40:37 2013 +0900 scd: support ECDSA public key. * scd/app-openpgp.c (key_type_t): New. (CURVE_NIST_P256, CURVE_NIST_P384, CURVE_NIST_P521): New. (struct app_local_s): Change keyattr to have key_type and union. (get_ecc_key_parameters, get_curve_name): New. (send_key_attr, get_public_key): Support ECDSA. (build_privkey_template, do_writekey, do_genkey): Follow the change of the member KEY_ATTR. (parse_historical): New. (parse_algorithm_attribute): Support ECDSA. -- Add ECDSA support to OpenPGP card. diff --git a/scd/app-openpgp.c b/scd/app-openpgp.c index 23b28c3..8d507c4 100644 --- a/scd/app-openpgp.c +++ b/scd/app-openpgp.c @@ -116,6 +116,16 @@ static struct { }; +/* Type of keys. */ +typedef enum + { + KEY_TYPE_ECDH, + KEY_TYPE_ECDSA, + KEY_TYPE_RSA, + } +key_type_t; + + /* The format of RSA private keys. */ typedef enum { @@ -128,6 +138,15 @@ typedef enum rsa_key_format_t; +/* Elliptic Curves. */ +enum + { + CURVE_NIST_P256, + CURVE_NIST_P384, + CURVE_NIST_P521 + }; + + /* One cache item for DOs. */ struct cache_s { struct cache_s *next; @@ -199,15 +218,27 @@ struct app_local_s { int fixedlen_admin; } pinpad; - struct - { - unsigned int n_bits; /* Size of the modulus in bits. The rest - of this strucuire is only valid if - this is not 0. */ - unsigned int e_bits; /* Size of the public exponent in bits. */ - rsa_key_format_t format; - } keyattr[3]; - + struct + { + key_type_t key_type; + union { + struct { + unsigned int n_bits; /* Size of the modulus in bits. The rest + of this strucuire is only valid if + this is not 0. */ + unsigned int e_bits; /* Size of the public exponent in bits. */ + rsa_key_format_t format; + } rsa; + struct { + int curve; + } ecdsa; + struct { + int curve; + int hashalgo; + int cipheralgo; + } ecdh; + }; + } keyattr[3]; }; @@ -845,18 +876,59 @@ send_key_data (ctrl_t ctrl, const char *name, static void +get_ecc_key_parameters (int curve, int *r_n_bits, const char **r_curve_oid) +{ + if (curve == CURVE_NIST_P256) + { + *r_n_bits = 256; + *r_curve_oid = "1.2.840.10045.3.1.7"; + } + else if (curve == CURVE_NIST_P384) + { + *r_n_bits = 384; + *r_curve_oid = "1.3.132.0.34"; + } + else + { + *r_n_bits = 521; + *r_curve_oid = "1.3.132.0.35"; + } +} + +static void send_key_attr (ctrl_t ctrl, app_t app, const char *keyword, int number) { char buffer[200]; + int n_bits; + const char *curve_oid; assert (number >=0 && number < DIM(app->app_local->keyattr)); - /* We only support RSA thus the algo identifier is fixed to 1. */ - snprintf (buffer, sizeof buffer, "%d 1 %u %u %d", - number+1, - app->app_local->keyattr[number].n_bits, - app->app_local->keyattr[number].e_bits, - app->app_local->keyattr[number].format); + if (app->app_local->keyattr[number].key_type == KEY_TYPE_RSA) + snprintf (buffer, sizeof buffer, "%d 1 %u %u %d", + number+1, + app->app_local->keyattr[number].rsa.n_bits, + app->app_local->keyattr[number].rsa.e_bits, + app->app_local->keyattr[number].rsa.format); + else if (app->app_local->keyattr[number].key_type == KEY_TYPE_ECDSA) + { + get_ecc_key_parameters (app->app_local->keyattr[number].ecdsa.curve, + &n_bits, &curve_oid); + snprintf (buffer, sizeof buffer, "%d 19 %u %s", + number+1, n_bits, curve_oid); + } + else if (app->app_local->keyattr[number].key_type == KEY_TYPE_ECDH) + { + get_ecc_key_parameters (app->app_local->keyattr[number].ecdh.curve, + &n_bits, &curve_oid); + snprintf (buffer, sizeof buffer, "%d 18 %u %s %d %d", + number+1, n_bits, curve_oid, + app->app_local->keyattr[number].ecdh.hashalgo, + app->app_local->keyattr[number].ecdh.cipheralgo); + } + else + snprintf (buffer, sizeof buffer, "0 0 UNKNOWN"); + send_status_direct (ctrl, keyword, buffer); } @@ -1154,6 +1226,18 @@ retrieve_key_material (FILE *fp, const char *hexkeyid, #endif /*GNUPG_MAJOR_VERSION > 1*/ +static const char * +get_curve_name (int curve) +{ + if (curve == CURVE_NIST_P256) + return "NIST P-256"; + else if (curve == CURVE_NIST_P384) + return "NIST P-384"; + else + return "NIST P-521"; +} + + /* Get the public key for KEYNO and store it as an S-expresion with the APP handle. On error that field gets cleared. If we already know about the public key we will just return. Note that this does @@ -1171,11 +1255,14 @@ get_public_key (app_t app, int keyno) gpg_error_t err = 0; unsigned char *buffer; const unsigned char *keydata, *m, *e; - size_t buflen, keydatalen, mlen, elen; + size_t buflen, keydatalen; + size_t mlen = 0; + size_t elen = 0; unsigned char *mbuf = NULL; unsigned char *ebuf = NULL; char *keybuf = NULL; - char *keybuf_p; + gcry_sexp_t s_pkey; + size_t len; if (keyno < 1 || keyno > 3) return gpg_error (GPG_ERR_INV_ID); @@ -1227,51 +1314,34 @@ get_public_key (app_t app, int keyno) goto leave; } - m = find_tlv (keydata, keydatalen, 0x0081, &mlen); - if (!m) + if (app->app_local->keyattr[keyno].key_type == KEY_TYPE_RSA) { - err = gpg_error (GPG_ERR_CARD); - log_error (_("response does not contain the RSA modulus\n")); - goto leave; - } - - - e = find_tlv (keydata, keydatalen, 0x0082, &elen); - if (!e) - { - err = gpg_error (GPG_ERR_CARD); - log_error (_("response does not contain the RSA public exponent\n")); - goto leave; - } + m = find_tlv (keydata, keydatalen, 0x0081, &mlen); + if (!m) + { + err = gpg_error (GPG_ERR_CARD); + log_error (_("response does not contain the RSA modulus\n")); + goto leave; + } - /* Prepend numbers with a 0 if needed. */ - if (mlen && (*m & 0x80)) - { - mbuf = xtrymalloc ( mlen + 1); - if (!mbuf) + e = find_tlv (keydata, keydatalen, 0x0082, &elen); + if (!e) { - err = gpg_error_from_syserror (); + err = gpg_error (GPG_ERR_CARD); + log_error (_("response does not contain the RSA public exponent\n")); goto leave; } - *mbuf = 0; - memcpy (mbuf+1, m, mlen); - mlen++; - m = mbuf; } - if (elen && (*e & 0x80)) + else { - ebuf = xtrymalloc ( elen + 1); - if (!ebuf) + m = find_tlv (keydata, keydatalen, 0x0086, &mlen); + if (!m) { - err = gpg_error_from_syserror (); + err = gpg_error (GPG_ERR_CARD); + log_error (_("response does not contain the EC public point\n")); goto leave; } - *ebuf = 0; - memcpy (ebuf+1, e, elen); - elen++; - e = ebuf; } - } else { @@ -1328,29 +1398,88 @@ get_public_key (app_t app, int keyno) } } - /* Allocate a buffer to construct the S-expression. */ - /* FIXME: We should provide a generalized S-expression creation - mechanism. */ - keybuf = xtrymalloc (50 + 2*35 + mlen + elen + 1); - if (!keybuf) + + mbuf = xtrymalloc ( mlen + 1); + if (!mbuf) { err = gpg_error_from_syserror (); goto leave; } + /* Prepend numbers with a 0 if needed. */ + if (mlen && (*m & 0x80)) + { + *mbuf = 0; + memcpy (mbuf+1, m, mlen); + mlen++; + } + else + memcpy (mbuf, m, mlen); - sprintf (keybuf, "(10:public-key(3:rsa(1:n%u:", (unsigned int) mlen); - keybuf_p = keybuf + strlen (keybuf); - memcpy (keybuf_p, m, mlen); - keybuf_p += mlen; - sprintf (keybuf_p, ")(1:e%u:", (unsigned int)elen); - keybuf_p += strlen (keybuf_p); - memcpy (keybuf_p, e, elen); - keybuf_p += elen; - strcpy (keybuf_p, ")))"); - keybuf_p += strlen (keybuf_p); + ebuf = xtrymalloc ( elen + 1); + if (!ebuf) + { + err = gpg_error_from_syserror (); + goto leave; + } + /* Prepend numbers with a 0 if needed. */ + if (elen && (*e & 0x80)) + { + *ebuf = 0; + memcpy (ebuf+1, e, elen); + elen++; + } + else + memcpy (ebuf, e, elen); + + if (app->app_local->keyattr[keyno].key_type == KEY_TYPE_RSA) + { + err = gcry_sexp_build (&s_pkey, NULL, "(public-key(rsa(n%b)(e%b)))", + mlen, mbuf, elen, ebuf); + if (err) + goto leave; + + len = gcry_sexp_sprint (s_pkey, GCRYSEXP_FMT_CANON, NULL, 0); + keybuf = xtrymalloc (len); + if (!keybuf) + { + gcry_sexp_release (s_pkey); + err = gpg_error_from_syserror (); + goto leave; + } + gcry_sexp_sprint (s_pkey, GCRYSEXP_FMT_CANON, keybuf, len); + gcry_sexp_release (s_pkey); + } + else if (app->app_local->keyattr[keyno].key_type == KEY_TYPE_ECDSA) + { + const char *curve_name + = get_curve_name (app->app_local->keyattr[keyno].ecdsa.curve); + + err = gcry_sexp_build (&s_pkey, NULL, + "(public-key(ecdsa(curve%s)(q%b)))", + curve_name, mlen, mbuf); + if (err) + goto leave; + + len = gcry_sexp_sprint (s_pkey, GCRYSEXP_FMT_CANON, NULL, 0); + + keybuf = xtrymalloc (len); + if (!keybuf) + { + gcry_sexp_release (s_pkey); + err = gpg_error_from_syserror (); + goto leave; + } + gcry_sexp_sprint (s_pkey, GCRYSEXP_FMT_CANON, keybuf, len); + gcry_sexp_release (s_pkey); + } + else + { + err = gpg_error (GPG_ERR_NOT_IMPLEMENTED); + goto leave; + } app->app_local->pk[keyno].key = (unsigned char*)keybuf; - app->app_local->pk[keyno].keylen = (keybuf_p - keybuf); + app->app_local->pk[keyno].keylen = len - 1; /* Decrement for trailing '\0' */ leave: /* Set a flag to indicate that we tried to read the key. */ @@ -2395,7 +2524,7 @@ build_privkey_template (app_t app, int keyno, *result = NULL; *resultlen = 0; - switch (app->app_local->keyattr[keyno].format) + switch (app->app_local->keyattr[keyno].rsa.format) { case RSA_STD: case RSA_STD_N: @@ -2409,7 +2538,7 @@ build_privkey_template (app_t app, int keyno, } /* Get the required length for E. */ - rsa_e_reqlen = app->app_local->keyattr[keyno].e_bits/8; + rsa_e_reqlen = app->app_local->keyattr[keyno].rsa.e_bits/8; assert (rsa_e_len <= rsa_e_reqlen); /* Build the 7f48 cardholder private key template. */ @@ -2425,8 +2554,8 @@ build_privkey_template (app_t app, int keyno, tp += add_tlv (tp, 0x93, rsa_q_len); datalen += rsa_q_len; - if (app->app_local->keyattr[keyno].format == RSA_STD_N - || app->app_local->keyattr[keyno].format == RSA_CRT_N) + if (app->app_local->keyattr[keyno].rsa.format == RSA_STD_N + || app->app_local->keyattr[keyno].rsa.format == RSA_CRT_N) { tp += add_tlv (tp, 0x97, rsa_n_len); datalen += rsa_n_len; @@ -2478,8 +2607,8 @@ build_privkey_template (app_t app, int keyno, memcpy (tp, rsa_q, rsa_q_len); tp += rsa_q_len; - if (app->app_local->keyattr[keyno].format == RSA_STD_N - || app->app_local->keyattr[keyno].format == RSA_CRT_N) + if (app->app_local->keyattr[keyno].rsa.format == RSA_STD_N + || app->app_local->keyattr[keyno].rsa.format == RSA_CRT_N) { memcpy (tp, rsa_n, rsa_n_len); tp += rsa_n_len; @@ -2764,7 +2893,7 @@ do_writekey (app_t app, ctrl_t ctrl, goto leave; } - maxbits = app->app_local->keyattr[keyno].n_bits; + maxbits = app->app_local->keyattr[keyno].rsa.n_bits; nbits = rsa_n? count_bits (rsa_n, rsa_n_len) : 0; if (opt.verbose) log_info ("RSA modulus size is %u bits (%u bytes)\n", @@ -2775,7 +2904,7 @@ do_writekey (app_t app, ctrl_t ctrl, /* Try to switch the key to a new length. */ err = change_keyattr (app, keyno, nbits, pincb, pincb_arg); if (!err) - maxbits = app->app_local->keyattr[keyno].n_bits; + maxbits = app->app_local->keyattr[keyno].rsa.n_bits; } if (nbits != maxbits) { @@ -2785,7 +2914,7 @@ do_writekey (app_t app, ctrl_t ctrl, goto leave; } - maxbits = app->app_local->keyattr[keyno].e_bits; + maxbits = app->app_local->keyattr[keyno].rsa.e_bits; if (maxbits > 32 && !app->app_local->extcap.is_v2) maxbits = 32; /* Our code for v1 does only support 32 bits. */ nbits = rsa_e? count_bits (rsa_e, rsa_e_len) : 0; @@ -2797,7 +2926,7 @@ do_writekey (app_t app, ctrl_t ctrl, goto leave; } - maxbits = app->app_local->keyattr[keyno].n_bits/2; + maxbits = app->app_local->keyattr[keyno].rsa.n_bits/2; nbits = rsa_p? count_bits (rsa_p, rsa_p_len) : 0; if (nbits != maxbits) { @@ -2966,7 +3095,7 @@ do_genkey (app_t app, ctrl_t ctrl, const char *keynostr, unsigned int flags, to put a limit on the max. allowed keysize. 2048 bit will already lead to a 527 byte long status line and thus a 4096 bit key would exceed the Assuan line length limit. */ - keybits = app->app_local->keyattr[keyno].n_bits; + keybits = app->app_local->keyattr[keyno].rsa.n_bits; if (keybits > 4096) return gpg_error (GPG_ERR_TOO_LARGE); @@ -3753,6 +3882,22 @@ parse_historical (struct app_local_s *apploc, } +static int +parse_ecc_curve (const unsigned char *buffer, size_t buflen) +{ + int curve; + + if (buflen == 6 && buffer[5] == 0x22) + curve = CURVE_NIST_P384; + else if (buflen == 6 && buffer[5] == 0x23) + curve = CURVE_NIST_P521; + else + curve = CURVE_NIST_P256; + + return curve; +} + + /* Parse and optionally show the algorithm attributes for KEYNO. KEYNO must be in the range 0..2. */ static void @@ -3765,7 +3910,8 @@ parse_algorithm_attribute (app_t app, int keyno) assert (keyno >=0 && keyno <= 2); - app->app_local->keyattr[keyno].n_bits = 0; + app->app_local->keyattr[keyno].key_type = KEY_TYPE_RSA; + app->app_local->keyattr[keyno].rsa.n_bits = 0; relptr = get_one_do (app, 0xC1+keyno, &buffer, &buflen, NULL); if (!relptr) @@ -3784,27 +3930,41 @@ parse_algorithm_attribute (app_t app, int keyno) log_info ("Key-Attr-%s ..: ", desc[keyno]); if (*buffer == 1 && (buflen == 5 || buflen == 6)) { - app->app_local->keyattr[keyno].n_bits = (buffer[1]<<8 | buffer[2]); - app->app_local->keyattr[keyno].e_bits = (buffer[3]<<8 | buffer[4]); - app->app_local->keyattr[keyno].format = 0; + app->app_local->keyattr[keyno].rsa.n_bits = (buffer[1]<<8 | buffer[2]); + app->app_local->keyattr[keyno].rsa.e_bits = (buffer[3]<<8 | buffer[4]); + app->app_local->keyattr[keyno].rsa.format = 0; if (buflen < 6) - app->app_local->keyattr[keyno].format = RSA_STD; + app->app_local->keyattr[keyno].rsa.format = RSA_STD; else - app->app_local->keyattr[keyno].format = (buffer[5] == 0? RSA_STD : - buffer[5] == 1? RSA_STD_N : - buffer[5] == 2? RSA_CRT : - buffer[5] == 3? RSA_CRT_N : - RSA_UNKNOWN_FMT); + app->app_local->keyattr[keyno].rsa.format = (buffer[5] == 0? RSA_STD : + buffer[5] == 1? RSA_STD_N : + buffer[5] == 2? RSA_CRT : + buffer[5] == 3? RSA_CRT_N : + RSA_UNKNOWN_FMT); if (opt.verbose) log_printf ("RSA, n=%u, e=%u, fmt=%s\n", - app->app_local->keyattr[keyno].n_bits, - app->app_local->keyattr[keyno].e_bits, - app->app_local->keyattr[keyno].format == RSA_STD? "std" : - app->app_local->keyattr[keyno].format == RSA_STD_N?"std+n": - app->app_local->keyattr[keyno].format == RSA_CRT? "crt" : - app->app_local->keyattr[keyno].format == RSA_CRT_N?"crt+n":"?"); + app->app_local->keyattr[keyno].rsa.n_bits, + app->app_local->keyattr[keyno].rsa.e_bits, + app->app_local->keyattr[keyno].rsa.format == RSA_STD? "std" : + app->app_local->keyattr[keyno].rsa.format == RSA_STD_N?"std+n": + app->app_local->keyattr[keyno].rsa.format == RSA_CRT? "crt" : + app->app_local->keyattr[keyno].rsa.format == RSA_CRT_N?"crt+n":"?"); + } + else if (*buffer == 19) /* ECDSA */ + { + app->app_local->keyattr[keyno].key_type = KEY_TYPE_ECDSA; + app->app_local->keyattr[keyno].ecdsa.curve + = parse_ecc_curve (buffer + 1, buflen - 1); + } + else if (*buffer == 18 && buflen == 11) /* ECDH */ + { + app->app_local->keyattr[keyno].key_type = KEY_TYPE_ECDH; + app->app_local->keyattr[keyno].ecdh.curve + = parse_ecc_curve (buffer + 1, buflen - 1); + app->app_local->keyattr[keyno].ecdh.hashalgo = buffer[1]; + app->app_local->keyattr[keyno].ecdh.cipheralgo = buffer[2]; } else if (opt.verbose) log_printhex ("", buffer, buflen); ----------------------------------------------------------------------- Summary of changes: scd/app-openpgp.c | 348 ++++++++++++++++++++++++++++++++++++++-------------- 1 files changed, 254 insertions(+), 94 deletions(-) hooks/post-receive -- The GNU Privacy Guard http://git.gnupg.org From cvs at cvs.gnupg.org Sat Mar 9 01:48:45 2013 From: cvs at cvs.gnupg.org (by NIIBE Yutaka) Date: Sat, 09 Mar 2013 01:48:45 +0100 Subject: [git] GnuPG - branch, master, updated. gnupg-2.1.0beta3-167-g73ad742 Message-ID: This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "The GNU Privacy Guard". The branch, master has been updated via 73ad742deacfe2bf7d6efc7cc30f9ced2d83521a (commit) from 010bc7f4f06d8affb98950e1adc76c68bfcc9abb (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 73ad742deacfe2bf7d6efc7cc30f9ced2d83521a Author: NIIBE Yutaka Date: Sat Mar 9 09:36:21 2013 +0900 scd: support ECDSA signing. * scd/app-openpgp.c (do_sign): Only prepend message digest block for RSA or do_auth. (do_auth): Remove message digest block for ECDSA. -- If we don't need to check the message digest block by SCDaemon, we don't requite the message digest block for ECDSA by gpg-agent. diff --git a/scd/app-openpgp.c b/scd/app-openpgp.c index 8d507c4..1df35b2 100644 --- a/scd/app-openpgp.c +++ b/scd/app-openpgp.c @@ -3416,14 +3416,23 @@ do_sign (app_t app, const char *keyidstr, int hashalgo, memcpy (data + sizeof b ## _prefix, indata, indatalen); \ } - X(SHA1, sha1, 1) - else X(RMD160, rmd160, 1) - else X(SHA224, sha224, app->app_local->extcap.is_v2) - else X(SHA256, sha256, app->app_local->extcap.is_v2) - else X(SHA384, sha384, app->app_local->extcap.is_v2) - else X(SHA512, sha512, app->app_local->extcap.is_v2) + if (use_auth + || app->app_local->keyattr[use_auth? 2: 0].key_type == KEY_TYPE_RSA) + { + X(SHA1, sha1, 1) + else X(RMD160, rmd160, 1) + else X(SHA224, sha224, app->app_local->extcap.is_v2) + else X(SHA256, sha256, app->app_local->extcap.is_v2) + else X(SHA384, sha384, app->app_local->extcap.is_v2) + else X(SHA512, sha512, app->app_local->extcap.is_v2) + else + return gpg_error (GPG_ERR_UNSUPPORTED_ALGORITHM); + } else - return gpg_error (GPG_ERR_UNSUPPORTED_ALGORITHM); + { + datalen = indatalen; + memcpy (data, indata, indatalen); + } #undef X /* Redirect to the AUTH command if asked to. */ @@ -3515,6 +3524,14 @@ do_auth (app_t app, const char *keyidstr, if (indatalen > 101) /* For a 2048 bit key. */ return gpg_error (GPG_ERR_INV_VALUE); + if (app->app_local->keyattr[2].key_type == KEY_TYPE_ECDSA + && (indatalen == 51 || indatalen == 67 || indatalen == 83) + { + const char *p = (const char *)indata + 19; + indata = p; + indatalen -= 19; + } + /* Check whether an OpenPGP card of any version has been requested. */ if (!strcmp (keyidstr, "OPENPGP.3")) ; ----------------------------------------------------------------------- Summary of changes: scd/app-openpgp.c | 31 ++++++++++++++++++++++++------- 1 files changed, 24 insertions(+), 7 deletions(-) hooks/post-receive -- The GNU Privacy Guard http://git.gnupg.org From cvs at cvs.gnupg.org Mon Mar 11 16:09:58 2013 From: cvs at cvs.gnupg.org (by Werner Koch) Date: Mon, 11 Mar 2013 16:09:58 +0100 Subject: [git] GCRYPT - branch, master, updated. libgcrypt-1.5.0-93-g5e743bc Message-ID: This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "The GNU crypto library". The branch, master has been updated via 5e743bc72e3fee3d550d0d7ae98596b7de6b46f8 (commit) via 8ac9e756d3ca545a9b97e61ad3d42fc2e877d788 (commit) via 7cce620acddac2df024ca421ed3abc32a88f3738 (commit) via 6c4767637c512127a4362732b3ec51068554d328 (commit) from 6782b2d7817c449fb2cf122cacd792b594f89d7c (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 5e743bc72e3fee3d550d0d7ae98596b7de6b46f8 Author: Werner Koch Date: Mon Mar 11 15:54:47 2013 +0100 Document the new point and EC functions -- diff --git a/doc/gcrypt.texi b/doc/gcrypt.texi index 8bfcbfd..c986ec7 100644 --- a/doc/gcrypt.texi +++ b/doc/gcrypt.texi @@ -12,8 +12,9 @@ This manual is for Libgcrypt (version @value{VERSION}, @value{UPDATED}), which is GNU's library of cryptographic building blocks. -Copyright @copyright{} 2000, 2002, 2003, 2004, 2006, 2007, 2008, 2009, -2011, 2012 Free Software Foundation, Inc. + at noindent +Copyright @copyright{} 2000, 2002, 2003, 2004, 2006, 2007, 2008, 2009, 2011, 2012 Free Software Foundation, Inc. @* +Copyright @copyright{} 2012, 2013 g10 Code GmbH @quotation Permission is granted to copy, distribute and/or modify this document @@ -91,7 +92,7 @@ section entitled ``GNU General Public License''. * S-expressions:: How to manage S-expressions. * MPI library:: How to work with multi-precision-integers. * Prime numbers:: How to use the Prime number related functions. -* Utilities:: Utility functions. +* Utilities:: Utility functions. * Tools:: Utility tools * Architecture:: How Libgcrypt works internally. @@ -3523,6 +3524,7 @@ likely want to use @code{GCRYMPI_FMT_USG}. * Calculations:: Performing MPI calculations. * Comparisons:: How to compare MPI values. * Bit manipulations:: How to access single bits of MPI values. +* EC functions:: Elliptic curve related functions. * Miscellaneous:: Miscellaneous MPI functions. @end menu @@ -3540,6 +3542,10 @@ numbers are called MPIs (multi-precision-integers). This type represents an object to hold an MPI. @end deftp + at deftp {Data type} {gcry_mpi_point_t} +This type represents an object to hold a point for elliptic curve math. + at end deftp + @node Basic functions @section Basic functions @@ -3843,6 +3849,124 @@ Shift the value of @var{a} by @var{n} bits to the left and store the result in @var{x}. @end deftypefun + at node EC functions + at section EC functions + + at noindent +Libgcrypt provides an API to access low level functions used by its +elliptic curve implementation. These functions allow to implement +elliptic curve methods for which no explicit support is available. + + at deftypefun gcry_mpi_point_t gcry_mpi_point_new (@w{unsigned int @var{nbits}}) + +Allocate a new point object, initialize it to 0, and allocate enough +memory for a points of at least @var{nbits}. This pre-allocation +yields only a small performance win and is not really necessary +because Libgcrypt automatically re-allocates the required memory. +Using 0 for @var{nbits} is usually the right thing to do. + at end deftypefun + + at deftypefun void gcry_mpi_point_release (@w{gcry_mpi_point_t @var{point}}) + +Release @var{point} and free all associated resources. Passing + at code{NULL} is allowed and ignored. + at end deftypefun + + at deftypefun void gcry_mpi_point_get (@w{gcry_mpi_t @var{x}}, @ + @w{gcry_mpi_t @var{y}}, @w{gcry_mpi_t @var{z}}, @ + @w{gcry_mpi_point_t @var{point}}) + +Store the projective coordinates from @var{point} into the MPIs + at var{x}, @var{y}, and @var{z}. If a coordinate is not required, + at code{NULL} may be used for @var{x}, @var{y}, or @var{z}. + at end deftypefun + + at deftypefun void gcry_mpi_point_snatch_get (@w{gcry_mpi_t @var{x}}, @ + @w{gcry_mpi_t @var{y}}, @w{gcry_mpi_t @var{z}}, @ + @w{gcry_mpi_point_t @var{point}}) + +Store the projective coordinates from @var{point} into the MPIs + at var{x}, @var{y}, and @var{z}. If a coordinate is not required, + at code{NULL} may be used for @var{x}, @var{y}, or @var{z}. The object + at var{point} is then released. Using this function instead of + at code{gcry_mpi_point_get} and @code{gcry_mpi_point_release} has the +advantage of avoiding some extra memory allocations and copies. + at end deftypefun + + at deftypefun gcry_mpi_point_t gcry_mpi_point_set ( @ + @w{gcry_mpi_point_t @var{point}}, @ + @w{gcry_mpi_t @var{x}}, @w{gcry_mpi_t @var{y}}, @w{gcry_mpi_t @var{z}}) + +Store the projective coordinates from @var{x}, @var{y}, and @var{z} +into @var{point}. If a coordinate is given as @code{NULL}, the value +0 is used. If @code{NULL} is used for @var{point} a new point object +is allocated and returned. Returns @var{point} or the newly allocated +point object. + at end deftypefun + + at deftypefun gcry_mpi_point_t gcry_mpi_point_snatch_set ( @ + @w{gcry_mpi_point_t @var{point}}, @ + @w{gcry_mpi_t @var{x}}, @w{gcry_mpi_t @var{y}}, @w{gcry_mpi_t @var{z}}) + +Store the projective coordinates from @var{x}, @var{y}, and @var{z} +into @var{point}. If a coordinate is given as @code{NULL}, the value +0 is used. If @code{NULL} is used for @var{point} a new point object +is allocated and returned. The MPIs @var{x}, @var{y}, and @var{z} are +released. Using this function instead of @code{gcry_mpi_point_set} +and 3 calls to @code{gcry_mpi_release} has the advantage of avoiding +some extra memory allocations and copies. Returns @var{point} or the +newly allocated point object. + at end deftypefun + + at anchor{gcry_mpi_ec_p_new} + at deftypefun gcry_ctx_t gcry_mpi_ec_p_new (@w{gcry_mpi_t @var{p}}, @ + @w{gcry_mpi_t @var{a}} + +Allocate a new context for elliptic curve operations based on the +field GF(p). @var{p} is the prime specifying this field, @var{a} is +the first coefficient of the Weierstrass equation. The function +returns a context object which eventually needs to be released using + at ref{gcry_ctx_release}. On error this function returns @code{NULL} +and sets @code{errno}. + at end deftypefun + + at deftypefun int gcry_mpi_ec_get_affine ( @ + @w{gcry_mpi_t @var{x}}, @w{gcry_mpi_t @var{y}}, @ + @w{gcry_mpi_point_t @var{point}}, @w{gcry_ctx_t @var{ctx}}) + +Compute the affine coordinates from the projective coordinates in + at var{point} and store them into @var{x} and @var{y}. If one +coordinate is not required, @code{NULL} may be passed to @var{x} or + at var{y}. @var{ctx} is the context object which for example may have +been created using @ref{gcry_mpi_ec_p_new}. Returns 0 on success or +not 0 if @var{point} is at infinity. + at end deftypefun + + at deftypefun void gcry_mpi_ec_dup ( @ + @w{gcry_mpi_point_t @var{w}}, @w{gcry_mpi_point_t @var{u}}, @ + @w{gcry_ctx_t @var{ctx}}) + +Double the point @var{u} of the elliptic curve described by @var{ctx} +and store the result into @var{w}. + at end deftypefun + + at deftypefun void gcry_mpi_ec_add ( @ + @w{gcry_mpi_point_t @var{w}}, @w{gcry_mpi_point_t @var{u}}, @ + @w{gcry_mpi_point_t @var{v}}, @w{gcry_ctx_t @var{ctx}}) + +Add the points @var{u} and @var{v} of the elliptic curve described by + at var{ctx} and store the result into @var{w}. + at end deftypefun + + at deftypefun void gcry_mpi_ec_mul ( @ + @w{gcry_mpi_point_t @var{w}}, @w{gcry_mpi_t @var{n}}, @ + @w{gcry_mpi_point_t @var{u}}, @w{gcry_ctx_t @var{ctx}}) + +Multiply the point @var{u} of the elliptic curve described by + at var{ctx} by @var{n} and store the result into @var{w}. + at end deftypefun + + @node Miscellaneous @section Miscellaneous @@ -3950,7 +4074,8 @@ wrong. @chapter Utilities @menu -* Memory allocation:: Functions related with memory allocation. +* Memory allocation:: Functions related with memory allocation. +* Context management:: Functions related with context management. @end menu @node Memory allocation @@ -3992,6 +4117,25 @@ gcry_realloc tries to use secure memory as well. Release the memory area pointed to by @var{p}. @end deftypefun + + at node Context management + at section Context management + +Some function make use of a context object. As of now there are only +a few math functions. However, future versions of Libgcrypt may make +more use of this context object. + + at deftp {Data type} {gcry_ctx_t} +This type is used to refer to the general purpose context object. + at end deftp + + at anchor{gcry_ctx_release} + at deftypefun void gcry_ctx_release (gcry_ctx_t @var{ctx}) +Release the context object @var{ctx} and all associated resources. A + at code{NULL} passed as @var{ctx} is ignored. + at end deftypefun + + @c ********************************************************** @c ********************* Tools **************************** @c ********************************************************** commit 8ac9e756d3ca545a9b97e61ad3d42fc2e877d788 Author: Werner Koch Date: Fri Mar 8 22:10:23 2013 +0100 mpi: Add an API for EC math. * src/context.c, src/context.h: New. * src/Makefile.am (libgcrypt_la_SOURCES): Add new files. * src/gcrypt.h.in (struct gcry_context, gcry_ctx_t): New types. (gcry_ctx_release): New prototype. (gcry_mpi_ec_p_new, gcry_mpi_ec_get_affine, gcry_mpi_ec_dup) (gcry_mpi_ec_add, gcry_mpi_ec_mul): New prototypes. * mpi/ec.c: Include errno.h and context.h. (_gcry_mpi_ec_init): Rename to .. (ec_p_init): this, make static, remove allocation and add arg CTX. (_gcry_mpi_ec_p_internal_new): New; to replace _gcry_mpi_ec_init. Change all callers to use this func. (_gcry_mpi_ec_free): Factor code out to .. (ec_deinit): New func. (gcry_mpi_ec_p_new): New. * src/visibility.c: Include context.h and mpi.h. (gcry_mpi_ec_p_new, gcry_mpi_ec_get_affine, gcry_mpi_ec_dup) (gcry_mpi_ec_add, gcry_mpi_ec_mul) (gcry_ctx_release): New wrapper functions. * src/visibility.h: Mark new wrapper functions visible. * src/libgcrypt.def, src/libgcrypt.vers: Add new symbols. * tests/t-mpi-point.c (print_mpi, hex2mpi, cmp_mpihex): New. (context_alloc): New. (make_point, basic_ec_math): New. -- This part finishes the basic API to do EC math. It provides a wrapper around all internal functions. tests/t-mpi-point.c may be useful as sample code. Eventually we will add function to retrieve curve parameters etc. diff --git a/NEWS b/NEWS index e0ba536..733dd88 100644 --- a/NEWS +++ b/NEWS @@ -44,6 +44,12 @@ Noteworthy changes in version 1.6.0 (unreleased) gcry_mpi_point_snatch_get NEW. gcry_mpi_point_set NEW. gcry_mpi_point_snatch_set NEW. + gcry_ctx_t NEW. + gcry_ctx_release NEW. + gcry_mpi_ec_p_new NEW. + gcry_mpi_ec_dup NEW. + gcry_mpi_ec_add NEW. + gcry_mpi_ec_mul NEW. Noteworthy changes in version 1.5.0 (2011-06-29) diff --git a/cipher/ecc.c b/cipher/ecc.c index 789fc6c..4efbef4 100644 --- a/cipher/ecc.c +++ b/cipher/ecc.c @@ -547,7 +547,7 @@ generate_key (ECC_secret_key *sk, unsigned int nbits, const char *name, /* Compute Q. */ point_init (&Q); - ctx = _gcry_mpi_ec_init (E.p, E.a); + ctx = _gcry_mpi_ec_p_internal_new (E.p, E.a); _gcry_mpi_ec_mul_point (&Q, d, &E.G, ctx); /* Copy the stuff to the key structures. */ @@ -672,7 +672,7 @@ check_secret_key (ECC_secret_key * sk) goto leave; } - ctx = _gcry_mpi_ec_init (sk->E.p, sk->E.a); + ctx = _gcry_mpi_ec_p_internal_new (sk->E.p, sk->E.a); _gcry_mpi_ec_mul_point (&Q, sk->E.n, &sk->E.G, ctx); if (mpi_cmp_ui (Q.z, 0)) @@ -733,7 +733,7 @@ sign (gcry_mpi_t input, ECC_secret_key *skey, gcry_mpi_t r, gcry_mpi_t s) mpi_set_ui (s, 0); mpi_set_ui (r, 0); - ctx = _gcry_mpi_ec_init (skey->E.p, skey->E.a); + ctx = _gcry_mpi_ec_p_internal_new (skey->E.p, skey->E.a); while (!mpi_cmp_ui (s, 0)) /* s == 0 */ { @@ -805,7 +805,7 @@ verify (gcry_mpi_t input, ECC_public_key *pkey, gcry_mpi_t r, gcry_mpi_t s) point_init (&Q1); point_init (&Q2); - ctx = _gcry_mpi_ec_init (pkey->E.p, pkey->E.a); + ctx = _gcry_mpi_ec_p_internal_new (pkey->E.p, pkey->E.a); /* h = s^(-1) (mod n) */ mpi_invm (h, s, pkey->E.n); @@ -1095,7 +1095,7 @@ ecc_get_param (const char *name, gcry_mpi_t *pkey) g_x = mpi_new (0); g_y = mpi_new (0); - ctx = _gcry_mpi_ec_init (E.p, E.a); + ctx = _gcry_mpi_ec_p_internal_new (E.p, E.a); if (_gcry_mpi_ec_get_affine (g_x, g_y, &E.G, ctx)) log_fatal ("ecc get param: Failed to get affine coordinates\n"); _gcry_mpi_ec_free (ctx); @@ -1424,7 +1424,7 @@ ecc_encrypt_raw (int algo, gcry_mpi_t *resarr, gcry_mpi_t k, return err; } - ctx = _gcry_mpi_ec_init (pk.E.p, pk.E.a); + ctx = _gcry_mpi_ec_p_internal_new (pk.E.p, pk.E.a); /* The following is false: assert( mpi_cmp_ui( R.x, 1 )==0 );, so */ { @@ -1536,7 +1536,7 @@ ecc_decrypt_raw (int algo, gcry_mpi_t *result, gcry_mpi_t *data, } sk.d = skey[6]; - ctx = _gcry_mpi_ec_init (sk.E.p, sk.E.a); + ctx = _gcry_mpi_ec_p_internal_new (sk.E.p, sk.E.a); /* R = dkG */ point_init (&R); diff --git a/mpi/ec.c b/mpi/ec.c index bb9bea4..e85ec04 100644 --- a/mpi/ec.c +++ b/mpi/ec.c @@ -21,10 +21,12 @@ #include #include #include +#include #include "mpi-internal.h" #include "longlong.h" #include "g10lib.h" +#include "context.h" #define point_init(a) _gcry_mpi_point_init ((a)) @@ -348,16 +350,13 @@ ec_invm (gcry_mpi_t x, gcry_mpi_t a, mpi_ec_t ctx) -/* This function returns a new context for elliptic curve based on the - field GF(p). P is the prime specifying thuis field, A is the first - coefficient. - - This context needs to be released using _gcry_mpi_ec_free. */ -mpi_ec_t -_gcry_mpi_ec_init (gcry_mpi_t p, gcry_mpi_t a) +/* This function initialized a context for elliptic curve based on the + field GF(p). P is the prime specifying this field, A is the first + coefficient. CTX is expected to be zeroized. */ +static void +ec_p_init (mpi_ec_t ctx, gcry_mpi_t p, gcry_mpi_t a) { int i; - mpi_ec_t ctx; gcry_mpi_t tmp; mpi_normalize (p); @@ -367,8 +366,6 @@ _gcry_mpi_ec_init (gcry_mpi_t p, gcry_mpi_t a) a < p */ - ctx = gcry_xcalloc (1, sizeof *ctx); - ctx->p = mpi_copy (p); ctx->a = mpi_copy (a); @@ -408,18 +405,15 @@ _gcry_mpi_ec_init (gcry_mpi_t p, gcry_mpi_t a) /* ctx->s[i] = mpi_new (384); */ /* ctx->c = mpi_new (384*2); */ /* } */ - - return ctx; } -void -_gcry_mpi_ec_free (mpi_ec_t ctx) + +static void +ec_deinit (void *opaque) { + mpi_ec_t ctx = opaque; int i; - if (!ctx) - return; - mpi_free (ctx->p); mpi_free (ctx->a); @@ -446,8 +440,62 @@ _gcry_mpi_ec_free (mpi_ec_t ctx) /* mpi_free (ctx->s[i]); */ /* mpi_free (ctx->c); */ /* } */ +} + - gcry_free (ctx); +/* This function returns a new context for elliptic curve based on the + field GF(p). P is the prime specifying this field, A is the first + coefficient. This function is only used within Libgcrypt and not + part of the public API. + + This context needs to be released using _gcry_mpi_ec_free. */ +mpi_ec_t +_gcry_mpi_ec_p_internal_new (gcry_mpi_t p, gcry_mpi_t a) +{ + mpi_ec_t ctx; + + ctx = gcry_xcalloc (1, sizeof *ctx); + ec_p_init (ctx, p, a); + + return ctx; +} + + +void +_gcry_mpi_ec_free (mpi_ec_t ctx) +{ + if (ctx) + { + ec_deinit (ctx); + gcry_free (ctx); + } +} + + +/* This function returns a new context for elliptic curve operations + based on the field GF(p). P is the prime specifying this field, A + is the first coefficient. This function is part of the public API. + On error this function returns NULL and sets ERRNO. + The context needs to be released using gcry_ctx_release. */ +gcry_ctx_t +gcry_mpi_ec_p_new (gcry_mpi_t p, gcry_mpi_t a) +{ + gcry_ctx_t ctx; + mpi_ec_t ec; + + if (!p || !a || !mpi_cmp_ui (a, 0)) + { + gpg_err_set_errno (EINVAL); + return NULL; + } + + ctx = _gcry_ctx_alloc (CONTEXT_TYPE_EC, sizeof *ec, ec_deinit); + if (!ctx) + return NULL; + ec = _gcry_ctx_get_pointer (ctx, CONTEXT_TYPE_EC); + ec_p_init (ec, p, a); + + return ctx; } diff --git a/src/Makefile.am b/src/Makefile.am index 9e7dcd5..1869ad3 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -59,7 +59,7 @@ libgcrypt_la_SOURCES = g10lib.h visibility.c visibility.h types.h \ misc.c global.c sexp.c hwfeatures.c hwf-common.h \ stdmem.c stdmem.h secmem.c secmem.h \ mpi.h missing-string.c module.c fips.c \ - hmac256.c hmac256.h \ + hmac256.c hmac256.h context.c context.h \ ath.h ath.c EXTRA_libgcrypt_la_SOURCES = hwf-x86.c diff --git a/src/context.c b/src/context.c new file mode 100644 index 0000000..ae991c5 --- /dev/null +++ b/src/context.c @@ -0,0 +1,118 @@ +/* context.c - Context management + * Copyright (C) 2013 g10 Code GmbH + * + * This file is part of Libgcrypt. + * + * Libgcrypt is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * Libgcrypt is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this program; if not, see . + */ + +#include +#include +#include +#include +#include +#include + +#include "g10lib.h" +#include "mpi.h" +#include "context.h" + +#define CTX_MAGIC "cTx" +#define CTX_MAGIC_LEN 3 + + +/* The definition of the generic context object. The public typedef + gcry_ctx_t is used to access it. */ +struct gcry_context +{ + char magic[CTX_MAGIC_LEN]; /* Magic value to cross check that this + is really a context object. */ + char type; /* The type of the context (CONTEXT_TYPE_foo). */ + + void (*deinit)(void*); /* Function used to free the private part. */ + PROPERLY_ALIGNED_TYPE u; +}; + + +/* Allocate a fresh generic context of contect TYPE and allocate + LENGTH extra bytes for private use of the type handler. DEINIT is a + fucntion used called to deinitialize the private part; it may be + NULL if de-initialization is not required. Returns NULL and sets + ERRNO if memory allocation failed. */ +gcry_ctx_t +_gcry_ctx_alloc (int type, size_t length, void (*deinit)(void*)) +{ + gcry_ctx_t ctx; + + switch (type) + { + case CONTEXT_TYPE_EC: + break; + default: + log_bug ("bad context type %d given to _gcry_ctx_alloc\n", type); + break; + } + + if (length < sizeof (PROPERLY_ALIGNED_TYPE)) + length = sizeof (PROPERLY_ALIGNED_TYPE); + + ctx = gcry_calloc (1, sizeof *ctx - sizeof (PROPERLY_ALIGNED_TYPE) + length); + if (!ctx) + return NULL; + memcpy (ctx->magic, CTX_MAGIC, CTX_MAGIC_LEN); + ctx->type = type; + ctx->deinit = deinit; + + return ctx; +} + + +/* Return a pointer to the private part of the context CTX. TYPE is + the requested context type. Using an explicit type allows to cross + check the type and eventually allows to store several private + contexts in one context object. The function does not return an + error but aborts if the provided CTX is not valid. */ +void * +_gcry_ctx_get_pointer (gcry_ctx_t ctx, int type) +{ + if (memcmp (ctx->magic, CTX_MAGIC, CTX_MAGIC_LEN)) + log_fatal ("bad pointer %p passed to _gcry_ctx_get_pointer\n", ctx); + if (ctx->type != type) + log_fatal ("wrong context type %d request for context %p of type %d\n", + type, ctx, ctx->type); + return &ctx->u; +} + + +/* Release the generic context CTX. */ +void +gcry_ctx_release (gcry_ctx_t ctx) +{ + if (!ctx) + return; + if (memcmp (ctx->magic, CTX_MAGIC, CTX_MAGIC_LEN)) + log_fatal ("bad pointer %p passed to gcry_ctx_relase\n", ctx); + switch (ctx->type) + { + case CONTEXT_TYPE_EC: + break; + default: + log_fatal ("bad context type %d detected in gcry_ctx_relase\n", + ctx->type); + break; + } + if (ctx->deinit) + ctx->deinit (&ctx->u); + gcry_free (ctx); +} diff --git a/src/context.h b/src/context.h new file mode 100644 index 0000000..72f14d4 --- /dev/null +++ b/src/context.h @@ -0,0 +1,31 @@ +/* context.h - Declarations for the context management + * Copyright (C) 2013 g10 Code GmbH + * + * This file is part of Libgcrypt. + * + * Libgcrypt is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser general Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * Libgcrypt is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this program; if not, see . + */ + +#ifndef GCRY_CONTEXT_H +#define GCRY_CONTEXT_H + +/* Context types as used in struct gcry_context. */ +#define CONTEXT_TYPE_EC 1 /* The context is used with EC functions. */ + + +gcry_ctx_t _gcry_ctx_alloc (int type, size_t length, void (*deinit)(void*)); +void *_gcry_ctx_get_pointer (gcry_ctx_t ctx, int type); + + +#endif /*GCRY_CONTEXT_H*/ diff --git a/src/gcrypt.h.in b/src/gcrypt.h.in index 5d2a779..57b841e 100644 --- a/src/gcrypt.h.in +++ b/src/gcrypt.h.in @@ -212,6 +212,10 @@ struct gcry_thread_cbs +/* A generic context object as used by some functions. */ +struct gcry_context; +typedef struct gcry_context *gcry_ctx_t; + /* The data objects used to hold multi precision integers. */ struct gcry_mpi; typedef struct gcry_mpi *gcry_mpi_t; @@ -599,6 +603,26 @@ gcry_mpi_point_t gcry_mpi_point_snatch_set (gcry_mpi_point_t point, gcry_mpi_t x, gcry_mpi_t y, gcry_mpi_t z); +/* Allocate a new context for elliptic curve operations based on the + field GF(p). P is the prime specifying this field, A is the first + coefficient. Returns NULL on error. */ +gcry_ctx_t gcry_mpi_ec_p_new (gcry_mpi_t p, gcry_mpi_t a); + +/* Store the affine coordinates of POINT into X and Y. */ +int gcry_mpi_ec_get_affine (gcry_mpi_t x, gcry_mpi_t y, gcry_mpi_point_t point, + gcry_ctx_t ctx); + +/* W = 2 * U. */ +void gcry_mpi_ec_dup (gcry_mpi_point_t w, gcry_mpi_point_t u, gcry_ctx_t ctx); + +/* W = U + V. */ +void gcry_mpi_ec_add (gcry_mpi_point_t w, + gcry_mpi_point_t u, gcry_mpi_point_t v, gcry_ctx_t ctx); + +/* W = N * U. */ +void gcry_mpi_ec_mul (gcry_mpi_point_t w, gcry_mpi_t n, gcry_mpi_point_t u, + gcry_ctx_t ctx); + /* Return the number of bits required to represent A. */ unsigned int gcry_mpi_get_nbits (gcry_mpi_t a); @@ -1294,6 +1318,9 @@ gcry_error_t gcry_prime_check (gcry_mpi_t x, unsigned int flags); * * ************************************/ +/* Release the context object CTX. */ +void gcry_ctx_release (gcry_ctx_t ctx); + /* Log levels used by the internal logging facility. */ enum gcry_log_levels { diff --git a/src/libgcrypt.def b/src/libgcrypt.def index 8f14dff..611f10f 100644 --- a/src/libgcrypt.def +++ b/src/libgcrypt.def @@ -220,3 +220,11 @@ EXPORTS gcry_mpi_point_snatch_get @199 gcry_mpi_point_set @200 gcry_mpi_point_snatch_set @201 + + gcry_ctx_release @202 + + gcry_mpi_ec_p_new @203 + gcry_mpi_ec_get_affine @204 + gcry_mpi_ec_dup @205 + gcry_mpi_ec_add @206 + gcry_mpi_ec_mul @207 diff --git a/src/libgcrypt.vers b/src/libgcrypt.vers index 5c43b95..4a375b2 100644 --- a/src/libgcrypt.vers +++ b/src/libgcrypt.vers @@ -90,7 +90,11 @@ GCRYPT_1.6 { gcry_mpi_point_new; gcry_mpi_point_release; gcry_mpi_point_get; gcry_mpi_point_snatch_get; gcry_mpi_point_set; gcry_mpi_point_snatch_set; + gcry_mpi_ec_p_new; + gcry_mpi_ec_get_affine; + gcry_mpi_ec_dup; gcry_mpi_ec_add; gcry_mpi_ec_mul; + gcry_ctx_release; local: *; diff --git a/src/mpi.h b/src/mpi.h index b3f19e5..23afa68 100644 --- a/src/mpi.h +++ b/src/mpi.h @@ -251,7 +251,7 @@ void _gcry_mpi_snatch_point (gcry_mpi_t x, gcry_mpi_t y, gcry_mpi_t z, struct mpi_ec_ctx_s; typedef struct mpi_ec_ctx_s *mpi_ec_t; -mpi_ec_t _gcry_mpi_ec_init (gcry_mpi_t p, gcry_mpi_t a); +mpi_ec_t _gcry_mpi_ec_p_internal_new (gcry_mpi_t p, gcry_mpi_t a); void _gcry_mpi_ec_free (mpi_ec_t ctx); int _gcry_mpi_ec_get_affine (gcry_mpi_t x, gcry_mpi_t y, mpi_point_t point, mpi_ec_t ctx); diff --git a/src/visibility.c b/src/visibility.c index 1fb29f2..5c3216d 100644 --- a/src/visibility.c +++ b/src/visibility.c @@ -24,8 +24,8 @@ #define _GCRY_INCLUDED_BY_VISIBILITY_C #include "g10lib.h" #include "cipher-proto.h" - - +#include "context.h" +#include "mpi.h" const char * gcry_strerror (gcry_error_t err) @@ -461,6 +461,42 @@ gcry_mpi_point_snatch_set (gcry_mpi_point_t point, return _gcry_mpi_point_snatch_set (point, x, y, z); } +gcry_ctx_t +gcry_mpi_ec_p_new (gcry_mpi_t p, gcry_mpi_t a) +{ + return _gcry_mpi_ec_p_new (p, a); +} + +int +gcry_mpi_ec_get_affine (gcry_mpi_t x, gcry_mpi_t y, gcry_mpi_point_t point, + gcry_ctx_t ctx) +{ + return _gcry_mpi_ec_get_affine (x, y, point, + _gcry_ctx_get_pointer (ctx, CONTEXT_TYPE_EC)); +} + +void +gcry_mpi_ec_dup (gcry_mpi_point_t w, gcry_mpi_point_t u, gcry_ctx_t ctx) +{ + _gcry_mpi_ec_dup_point (w, u, _gcry_ctx_get_pointer (ctx, CONTEXT_TYPE_EC)); +} + +void +gcry_mpi_ec_add (gcry_mpi_point_t w, + gcry_mpi_point_t u, gcry_mpi_point_t v, gcry_ctx_t ctx) +{ + _gcry_mpi_ec_add_points (w, u, v, + _gcry_ctx_get_pointer (ctx, CONTEXT_TYPE_EC)); +} + +void +gcry_mpi_ec_mul (gcry_mpi_point_t w, gcry_mpi_t n, gcry_mpi_point_t u, + gcry_ctx_t ctx) +{ + _gcry_mpi_ec_mul_point (w, n, u, + _gcry_ctx_get_pointer (ctx, CONTEXT_TYPE_EC)); +} + unsigned int gcry_mpi_get_nbits (gcry_mpi_t a) { @@ -1067,6 +1103,12 @@ gcry_prime_check (gcry_mpi_t x, unsigned int flags) } void +gcry_ctx_release (gcry_ctx_t ctx) +{ + _gcry_ctx_release (ctx); +} + +void gcry_set_progress_handler (gcry_handler_progress_t cb, void *cb_data) { _gcry_set_progress_handler (cb, cb_data); diff --git a/src/visibility.h b/src/visibility.h index f4507ce..90c6ad1 100644 --- a/src/visibility.h +++ b/src/visibility.h @@ -154,6 +154,7 @@ #define gcry_mpi_copy _gcry_mpi_copy #define gcry_mpi_div _gcry_mpi_div #define gcry_mpi_dump _gcry_mpi_dump +#define gcry_mpi_ec_p_new _gcry_mpi_ec_p_new #define gcry_mpi_gcd _gcry_mpi_gcd #define gcry_mpi_get_flag _gcry_mpi_get_flag #define gcry_mpi_get_nbits _gcry_mpi_get_nbits @@ -192,6 +193,8 @@ #define gcry_mpi_swap _gcry_mpi_swap #define gcry_mpi_test_bit _gcry_mpi_test_bit +#define gcry_ctx_release _gcry_ctx_release + /* Include the main header here so that public symbols are mapped to the internal underscored ones. */ @@ -367,6 +370,7 @@ gcry_err_code_t gcry_md_get (gcry_md_hd_t hd, int algo, #undef gcry_mpi_copy #undef gcry_mpi_div #undef gcry_mpi_dump +#undef gcry_mpi_ec_p_new #undef gcry_mpi_gcd #undef gcry_mpi_get_flag #undef gcry_mpi_get_nbits @@ -405,6 +409,8 @@ gcry_err_code_t gcry_md_get (gcry_md_hd_t hd, int algo, #undef gcry_mpi_swap #undef gcry_mpi_test_bit +#undef gcry_ctx_release + /* Now mark all symbols. */ @@ -540,6 +546,11 @@ MARK_VISIBLE (gcry_mpi_cmp_ui) MARK_VISIBLE (gcry_mpi_copy) MARK_VISIBLE (gcry_mpi_div) MARK_VISIBLE (gcry_mpi_dump) +MARK_VISIBLEX(gcry_mpi_ec_add) +MARK_VISIBLEX(gcry_mpi_ec_dup) +MARK_VISIBLEX(gcry_mpi_ec_get_affine) +MARK_VISIBLEX(gcry_mpi_ec_mul) +MARK_VISIBLE (gcry_mpi_ec_p_new) MARK_VISIBLE (gcry_mpi_gcd) MARK_VISIBLE (gcry_mpi_get_flag) MARK_VISIBLE (gcry_mpi_get_nbits) @@ -578,6 +589,7 @@ MARK_VISIBLE (gcry_mpi_subm) MARK_VISIBLE (gcry_mpi_swap) MARK_VISIBLE (gcry_mpi_test_bit) +MARK_VISIBLE (gcry_ctx_release) #undef MARK_VISIBLE diff --git a/tests/t-mpi-point.c b/tests/t-mpi-point.c index 548d6c7..8714d38 100644 --- a/tests/t-mpi-point.c +++ b/tests/t-mpi-point.c @@ -32,8 +32,10 @@ static const char *wherestr; static int verbose; +static int debug; static int error_count; + #define xmalloc(a) gcry_xmalloc ((a)) #define xcalloc(a,b) gcry_xcalloc ((a),(b)) #define xfree(a) gcry_free ((a)) @@ -83,6 +85,52 @@ die (const char *format, ...) } +static void +print_mpi (const char *text, gcry_mpi_t a) +{ + gcry_error_t err; + char *buf; + void *bufaddr = &buf; + + err = gcry_mpi_aprint (GCRYMPI_FMT_HEX, bufaddr, NULL, a); + if (err) + fprintf (stderr, "%s: [error printing number: %s]\n", + text, gpg_strerror (err)); + else + { + fprintf (stderr, "%s: %s\n", text, buf); + gcry_free (buf); + } +} + + +static gcry_mpi_t +hex2mpi (const char *string) +{ + gpg_error_t err; + gcry_mpi_t val; + + err = gcry_mpi_scan (&val, GCRYMPI_FMT_HEX, string, 0, NULL); + if (err) + die ("hex2mpi '%s' failed: %s\n", gpg_strerror (err)); + return val; +} + + +/* Compare A to B, where B is given as a hex string. */ +static int +cmp_mpihex (gcry_mpi_t a, const char *b) +{ + gcry_mpi_t bval; + int res; + + bval = hex2mpi (b); + res = gcry_mpi_cmp (a, bval); + gcry_mpi_release (bval); + return res; +} + + static void set_get_point (void) @@ -138,10 +186,127 @@ set_get_point (void) } +static void +context_alloc (void) +{ + gcry_ctx_t ctx; + gcry_mpi_t p, a; + + wherestr = "context_alloc"; + show ("checking context functions\n"); + + p = gcry_mpi_set_ui (NULL, 1); + a = gcry_mpi_set_ui (NULL, 1); + ctx = gcry_mpi_ec_p_new (p, a); + if (!ctx) + die ("gcry_mpi_ec_p_new returned an error: %s\n", + gpg_strerror (gpg_error_from_syserror ())); + gcry_mpi_release (p); + gcry_mpi_release (a); + gcry_ctx_release (ctx); + + p = gcry_mpi_set_ui (NULL, 0); + a = gcry_mpi_set_ui (NULL, 0); + ctx = gcry_mpi_ec_p_new (p, a); + if (ctx || gpg_err_code_from_syserror () != GPG_ERR_EINVAL) + fail ("gcry_mpi_ec_p_new: bad parameter detection failed (1)\n"); + + gcry_mpi_set_ui (p, 1); + ctx = gcry_mpi_ec_p_new (p, a); + if (ctx || gpg_err_code_from_syserror () != GPG_ERR_EINVAL) + fail ("gcry_mpi_ec_p_new: bad parameter detection failed (2)\n"); + + gcry_mpi_release (p); + p = NULL; + ctx = gcry_mpi_ec_p_new (p, a); + if (ctx || gpg_err_code_from_syserror () != GPG_ERR_EINVAL) + fail ("gcry_mpi_ec_p_new: bad parameter detection failed (3)\n"); + + gcry_mpi_release (a); + a = NULL; + ctx = gcry_mpi_ec_p_new (p, a); + if (ctx || gpg_err_code_from_syserror () != GPG_ERR_EINVAL) + fail ("gcry_mpi_ec_p_new: bad parameter detection failed (4)\n"); + +} + + +/* Create a new point from (X,Y,Z) given as hex strings. */ +gcry_mpi_point_t +make_point (const char *x, const char *y, const char *z) +{ + gcry_mpi_point_t point; + + point = gcry_mpi_point_new (0); + gcry_mpi_point_snatch_set (point, hex2mpi (x), hex2mpi (y), hex2mpi (z)); + + return point; +} + + +static void +basic_ec_math (void) +{ + gcry_ctx_t ctx; + gcry_mpi_t P, A; + gcry_mpi_point_t G, Q; + gcry_mpi_t d; + gcry_mpi_t x, y, z; + + wherestr = "set_get_point"; + show ("checking basic math functions for EC\n"); + + P = hex2mpi ("0xfffffffffffffffffffffffffffffffeffffffffffffffff"); + A = hex2mpi ("0xfffffffffffffffffffffffffffffffefffffffffffffffc"); + G = make_point ("188DA80EB03090F67CBF20EB43A18800F4FF0AFD82FF1012", + "7192B95FFC8DA78631011ED6B24CDD573F977A11E794811", + "1"); + d = hex2mpi ("D4EF27E32F8AD8E2A1C6DDEBB1D235A69E3CEF9BCE90273D"); + Q = gcry_mpi_point_new (0); + + ctx = gcry_mpi_ec_p_new (P, A); + gcry_mpi_ec_mul (Q, d, G, ctx); + + x = gcry_mpi_new (0); + y = gcry_mpi_new (0); + z = gcry_mpi_new (0); + gcry_mpi_point_get (x, y, z, Q); + if (cmp_mpihex (x, "222D9EC717C89D047E0898C9185B033CD11C0A981EE6DC66") + || cmp_mpihex (y, "605DE0A82D70D3E0F84A127D0739ED33D657DF0D054BFDE8") + || cmp_mpihex (z, "00B06B519071BC536999AC8F2D3934B3C1FC9EACCD0A31F88F")) + fail ("computed public key does not match\n"); + if (debug) + { + print_mpi ("Q.x", x); + print_mpi ("Q.y", y); + print_mpi ("Q.z", z); + } + + if (gcry_mpi_ec_get_affine (x, y, Q, ctx)) + fail ("failed to get affine coordinates\n"); + if (cmp_mpihex (x, "008532093BA023F4D55C0424FA3AF9367E05F309DC34CDC3FE") + || cmp_mpihex (y, "00C13CA9E617C6C8487BFF6A726E3C4F277913D97117939966")) + fail ("computed affine coordinates of public key do not match\n"); + if (debug) + { + print_mpi ("q.x", x); + print_mpi ("q.y", y); + } + + gcry_mpi_release (z); + gcry_mpi_release (y); + gcry_mpi_release (x); + gcry_mpi_point_release (Q); + gcry_mpi_release (d); + gcry_mpi_point_release (G); + gcry_mpi_release (A); + gcry_mpi_release (P); +} + + int main (int argc, char **argv) { - int debug = 0; if (argc > 1 && !strcmp (argv[1], "--verbose")) verbose = 1; @@ -158,7 +323,8 @@ main (int argc, char **argv) gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0); set_get_point (); - + context_alloc (); + basic_ec_math (); show ("All tests completed. Errors: %d\n", error_count); return error_count ? 1 : 0; commit 7cce620acddac2df024ca421ed3abc32a88f3738 Author: Werner Koch Date: Fri Mar 8 15:06:20 2013 +0100 mpi: Add an API for EC point operations. * mpi/ec.c (gcry_mpi_point_new, gcry_mpi_point_release): New. (gcry_mpi_point_get, gcry_mpi_point_snatch_get): New. (gcry_mpi_point_set, gcry_mpi_point_snatch_set): New. * src/visibility.h, src/visibility.c: Add corresponding macros and wrappers. * src/gcrypt.h.in (struct gcry_mpi_point, gcry_mpi_point_t): New. (gcry_mpi_point_new, gcry_mpi_point_release, gcry_mpi_point_get) (gcry_mpi_point_snatch_get, gcry_mpi_point_set) (gcry_mpi_point_snatch_set): New prototypes. (mpi_point_new, mpi_point_release, mpi_point_get, mpi_point_snatch_get) (mpi_point_set, mpi_point_snatch_set): New macros. * src/libgcrypt.vers (gcry_mpi_point_new, gcry_mpi_point_release) (gcry_mpi_point_get, gcry_mpi_point_snatch_get, gcry_mpi_point_set) (gcry_mpi_point_snatch_set): New symbols. * src/libgcrypt.def: Ditto. * tests/t-mpi-point.c: New. * tests/Makefile.am (TESTS): Add t-mpi-point diff --git a/NEWS b/NEWS index 1db71e9..e0ba536 100644 --- a/NEWS +++ b/NEWS @@ -37,6 +37,13 @@ Noteworthy changes in version 1.6.0 (unreleased) GCRY_RNG_TYPE_FIPS NEW. GCRY_RNG_TYPE_SYSTEM NEW. gcry_mpi_snatch NEW. + gcry_mpi_point_t NEW. + gcry_mpi_point_new NEW. + gcry_mpi_point_release NEW. + gcry_mpi_point_get NEW. + gcry_mpi_point_snatch_get NEW. + gcry_mpi_point_set NEW. + gcry_mpi_point_snatch_set NEW. Noteworthy changes in version 1.5.0 (2011-06-29) diff --git a/mpi/ec.c b/mpi/ec.c index 7b1ef2b..bb9bea4 100644 --- a/mpi/ec.c +++ b/mpi/ec.c @@ -62,6 +62,33 @@ struct mpi_ec_ctx_s }; +/* Create a new point option. NBITS gives the size in bits of one + coordinate; it is only used to pre-allocate some resources and + might also be passed as 0 to use a default value. */ +mpi_point_t +gcry_mpi_point_new (unsigned int nbits) +{ + mpi_point_t p; + + (void)nbits; /* Currently not used. */ + + p = gcry_xmalloc (sizeof *p); + _gcry_mpi_point_init (p); + return p; +} + + +/* Release the point object P. P may be NULL. */ +void +gcry_mpi_point_release (mpi_point_t p) +{ + if (p) + { + _gcry_mpi_point_free_parts (p); + gcry_free (p); + } +} + /* Initialize the fields of a point object. gcry_mpi_point_free_parts may be used to release the fields. */ @@ -93,6 +120,90 @@ point_set (mpi_point_t d, mpi_point_t s) mpi_set (d->z, s->z); } +/* Set the projective coordinates from POINT into X, Y, and Z. If a + coordinate is not required, X, Y, or Z may be passed as NULL. */ +void +gcry_mpi_point_get (gcry_mpi_t x, gcry_mpi_t y, gcry_mpi_t z, + mpi_point_t point) +{ + if (x) + mpi_set (x, point->x); + if (y) + mpi_set (y, point->y); + if (z) + mpi_set (z, point->z); +} + + +/* Set the projective coordinates from POINT into X, Y, and Z and + release POINT. If a coordinate is not required, X, Y, or Z may be + passed as NULL. */ +void +gcry_mpi_point_snatch_get (gcry_mpi_t x, gcry_mpi_t y, gcry_mpi_t z, + mpi_point_t point) +{ + mpi_snatch (x, point->x); + mpi_snatch (y, point->y); + mpi_snatch (z, point->z); + gcry_free (point); +} + + +/* Set the projective coordinates from X, Y, and Z into POINT. If a + coordinate is given as NULL, the value 0 is stored into point. If + POINT is given as NULL a new point object is allocated. Returns + POINT or the newly allocated point object. */ +mpi_point_t +gcry_mpi_point_set (mpi_point_t point, + gcry_mpi_t x, gcry_mpi_t y, gcry_mpi_t z) +{ + if (!point) + point = gcry_mpi_point_new (0); + + if (x) + mpi_set (point->x, x); + else + mpi_clear (point->x); + if (y) + mpi_set (point->y, y); + else + mpi_clear (point->y); + if (z) + mpi_set (point->z, z); + else + mpi_clear (point->z); + + return point; +} + + +/* Set the projective coordinates from X, Y, and Z into POINT. If a + coordinate is given as NULL, the value 0 is stored into point. If + POINT is given as NULL a new point object is allocated. The + coordinates X, Y, and Z are released. Returns POINT or the newly + allocated point object. */ +mpi_point_t +gcry_mpi_point_snatch_set (mpi_point_t point, + gcry_mpi_t x, gcry_mpi_t y, gcry_mpi_t z) +{ + if (!point) + point = gcry_mpi_point_new (0); + + if (x) + mpi_snatch (point->x, x); + else + mpi_clear (point->x); + if (y) + mpi_snatch (point->y, y); + else + mpi_clear (point->y); + if (z) + mpi_snatch (point->z, z); + else + mpi_clear (point->z); + + return point; +} static void diff --git a/src/gcrypt.h.in b/src/gcrypt.h.in index 7d2b89d..5d2a779 100644 --- a/src/gcrypt.h.in +++ b/src/gcrypt.h.in @@ -212,9 +212,11 @@ struct gcry_thread_cbs -/* The data object used to hold a multi precision integer. */ +/* The data objects used to hold multi precision integers. */ struct gcry_mpi; typedef struct gcry_mpi *gcry_mpi_t; +struct gcry_mpi_point; +typedef struct gcry_mpi_point *gcry_mpi_point_t; #ifndef GCRYPT_NO_DEPRECATED typedef struct gcry_mpi *GCRY_MPI _GCRY_GCC_ATTR_DEPRECATED; @@ -572,6 +574,31 @@ int gcry_mpi_gcd (gcry_mpi_t g, gcry_mpi_t a, gcry_mpi_t b); Return true if the value exists. */ int gcry_mpi_invm (gcry_mpi_t x, gcry_mpi_t a, gcry_mpi_t m); +/* Create a new point object. NBITS is usually 0. */ +gcry_mpi_point_t gcry_mpi_point_new (unsigned int nbits); + +/* Release the object POINT. POINT may be NULL. */ +void gcry_mpi_point_release (gcry_mpi_point_t point); + +/* Store the projective coordinates from POINT into X, Y, and Z. */ +void gcry_mpi_point_get (gcry_mpi_t x, gcry_mpi_t y, gcry_mpi_t z, + gcry_mpi_point_t point); + +/* Store the projective coordinates from POINT into X, Y, and Z and + release POINT. */ +void gcry_mpi_point_snatch_get (gcry_mpi_t x, gcry_mpi_t y, gcry_mpi_t z, + gcry_mpi_point_t point); + +/* Store the projective coordinates X, Y, and Z into POINT. */ +gcry_mpi_point_t gcry_mpi_point_set (gcry_mpi_point_t point, + gcry_mpi_t x, gcry_mpi_t y, gcry_mpi_t z); + +/* Store the projective coordinates X, Y, and Z into POINT and release + X, Y, and Z. */ +gcry_mpi_point_t gcry_mpi_point_snatch_set (gcry_mpi_point_t point, + gcry_mpi_t x, gcry_mpi_t y, + gcry_mpi_t z); + /* Return the number of bits required to represent A. */ unsigned int gcry_mpi_get_nbits (gcry_mpi_t a); @@ -656,6 +683,19 @@ int gcry_mpi_get_flag (gcry_mpi_t a, enum gcry_mpi_flag flag); #define mpi_gcd(g,a,b) gcry_mpi_gcd ( (g), (a), (b) ) #define mpi_invm(g,a,b) gcry_mpi_invm ( (g), (a), (b) ) +#define mpi_point_new(n) gcry_mpi_point_new((n)) +#define mpi_point_release(p) \ + do \ + { \ + gcry_mpi_point_release ((p)); \ + (p) = NULL; \ + } \ + while (0) +#define mpi_point_get(x,y,z,p) gcry_mpi_point_get((x),(y),(z),(p)) +#define mpi_point_snatch_get(x,y,z,p) gcry_mpi_point_snatch_get((x),(y),(z),(p)) +#define mpi_point_set(p,x,y,z) gcry_mpi_point_set((p),(x),(y),(z)) +#define mpi_point_snatch_set(p,x,y,z) gcry_mpi_point_snatch_set((p),(x),(y),(z)) + #define mpi_get_nbits(a) gcry_mpi_get_nbits ((a)) #define mpi_test_bit(a,b) gcry_mpi_test_bit ((a),(b)) #define mpi_set_bit(a,b) gcry_mpi_set_bit ((a),(b)) diff --git a/src/libgcrypt.def b/src/libgcrypt.def index cc49e74..8f14dff 100644 --- a/src/libgcrypt.def +++ b/src/libgcrypt.def @@ -213,3 +213,10 @@ EXPORTS gcry_kdf_derive @194 gcry_mpi_snatch @195 + + gcry_mpi_point_new @196 + gcry_mpi_point_release @197 + gcry_mpi_point_get @198 + gcry_mpi_point_snatch_get @199 + gcry_mpi_point_set @200 + gcry_mpi_point_snatch_set @201 diff --git a/src/libgcrypt.vers b/src/libgcrypt.vers index 200f04e..5c43b95 100644 --- a/src/libgcrypt.vers +++ b/src/libgcrypt.vers @@ -87,6 +87,10 @@ GCRYPT_1.6 { gcry_mpi_set_ui; gcry_mpi_snew; gcry_mpi_sub; gcry_mpi_sub_ui; gcry_mpi_subm; gcry_mpi_swap; gcry_mpi_test_bit; gcry_mpi_lshift; gcry_mpi_snatch; + gcry_mpi_point_new; gcry_mpi_point_release; + gcry_mpi_point_get; gcry_mpi_point_snatch_get; + gcry_mpi_point_set; gcry_mpi_point_snatch_set; + local: *; diff --git a/src/visibility.c b/src/visibility.c index 732f058..1fb29f2 100644 --- a/src/visibility.c +++ b/src/visibility.c @@ -421,6 +421,45 @@ gcry_mpi_invm (gcry_mpi_t x, gcry_mpi_t a, gcry_mpi_t m) return _gcry_mpi_invm (x, a, m); } +gcry_mpi_point_t +gcry_mpi_point_new (unsigned int nbits) +{ + return _gcry_mpi_point_new (nbits); +} + +void +gcry_mpi_point_release (gcry_mpi_point_t point) +{ + _gcry_mpi_point_release (point); +} + +void +gcry_mpi_point_get (gcry_mpi_t x, gcry_mpi_t y, gcry_mpi_t z, + gcry_mpi_point_t point) +{ + _gcry_mpi_point_get (x, y, z, point); +} + +void +gcry_mpi_point_snatch_get (gcry_mpi_t x, gcry_mpi_t y, gcry_mpi_t z, + gcry_mpi_point_t point) +{ + _gcry_mpi_point_snatch_get (x, y, z, point); +} + +gcry_mpi_point_t +gcry_mpi_point_set (gcry_mpi_point_t point, + gcry_mpi_t x, gcry_mpi_t y, gcry_mpi_t z) +{ + return _gcry_mpi_point_set (point, x, y, z); +} + +gcry_mpi_point_t +gcry_mpi_point_snatch_set (gcry_mpi_point_t point, + gcry_mpi_t x, gcry_mpi_t y, gcry_mpi_t z) +{ + return _gcry_mpi_point_snatch_set (point, x, y, z); +} unsigned int gcry_mpi_get_nbits (gcry_mpi_t a) diff --git a/src/visibility.h b/src/visibility.h index 429c246..f4507ce 100644 --- a/src/visibility.h +++ b/src/visibility.h @@ -165,6 +165,12 @@ #define gcry_mpi_mul_ui _gcry_mpi_mul_ui #define gcry_mpi_mulm _gcry_mpi_mulm #define gcry_mpi_new _gcry_mpi_new +#define gcry_mpi_point_get _gcry_mpi_point_get +#define gcry_mpi_point_new _gcry_mpi_point_new +#define gcry_mpi_point_release _gcry_mpi_point_release +#define gcry_mpi_point_set _gcry_mpi_point_set +#define gcry_mpi_point_snatch_get _gcry_mpi_point_snatch_get +#define gcry_mpi_point_snatch_set _gcry_mpi_point_snatch_set #define gcry_mpi_powm _gcry_mpi_powm #define gcry_mpi_print _gcry_mpi_print #define gcry_mpi_randomize _gcry_mpi_randomize @@ -172,13 +178,13 @@ #define gcry_mpi_rshift _gcry_mpi_rshift #define gcry_mpi_lshift _gcry_mpi_lshift #define gcry_mpi_scan _gcry_mpi_scan -#define gcry_mpi_snatch _gcry_mpi_snatch #define gcry_mpi_set _gcry_mpi_set #define gcry_mpi_set_bit _gcry_mpi_set_bit #define gcry_mpi_set_flag _gcry_mpi_set_flag #define gcry_mpi_set_highbit _gcry_mpi_set_highbit #define gcry_mpi_set_opaque _gcry_mpi_set_opaque #define gcry_mpi_set_ui _gcry_mpi_set_ui +#define gcry_mpi_snatch _gcry_mpi_snatch #define gcry_mpi_snew _gcry_mpi_snew #define gcry_mpi_sub _gcry_mpi_sub #define gcry_mpi_sub_ui _gcry_mpi_sub_ui @@ -372,6 +378,12 @@ gcry_err_code_t gcry_md_get (gcry_md_hd_t hd, int algo, #undef gcry_mpi_mul_ui #undef gcry_mpi_mulm #undef gcry_mpi_new +#undef gcry_mpi_point_get +#undef gcry_mpi_point_new +#undef gcry_mpi_point_release +#undef gcry_mpi_point_set +#undef gcry_mpi_point_snatch_get +#undef gcry_mpi_point_snatch_set #undef gcry_mpi_powm #undef gcry_mpi_print #undef gcry_mpi_randomize @@ -539,6 +551,12 @@ MARK_VISIBLE (gcry_mpi_mul_2exp) MARK_VISIBLE (gcry_mpi_mul_ui) MARK_VISIBLE (gcry_mpi_mulm) MARK_VISIBLE (gcry_mpi_new) +MARK_VISIBLE (gcry_mpi_point_get) +MARK_VISIBLE (gcry_mpi_point_new) +MARK_VISIBLE (gcry_mpi_point_release) +MARK_VISIBLE (gcry_mpi_point_set) +MARK_VISIBLE (gcry_mpi_point_snatch_get) +MARK_VISIBLE (gcry_mpi_point_snatch_set) MARK_VISIBLE (gcry_mpi_powm) MARK_VISIBLE (gcry_mpi_print) MARK_VISIBLE (gcry_mpi_randomize) diff --git a/tests/Makefile.am b/tests/Makefile.am index d337840..c18142e 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -18,7 +18,7 @@ ## Process this file with automake to produce Makefile.in -TESTS = version t-mpi-bit prime basic \ +TESTS = version t-mpi-bit t-mpi-point prime basic \ mpitests tsexp keygen pubkey hmac keygrip fips186-dsa aeswrap \ curves t-kdf pkcs1v2 random diff --git a/tests/t-mpi-point.c b/tests/t-mpi-point.c new file mode 100644 index 0000000..548d6c7 --- /dev/null +++ b/tests/t-mpi-point.c @@ -0,0 +1,165 @@ +/* t-mpi-point.c - Tests for mpi point functions + * Copyright (C) 2013 g10 Code GmbH + * + * This file is part of Libgcrypt. + * + * Libgcrypt is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * Libgcrypt is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this program; if not, see . + */ + +#ifdef HAVE_CONFIG_H +# include +#endif +#include +#include +#include +#include +#include + +#include "../src/gcrypt.h" + +#define PGM "t-mpi-point" + +static const char *wherestr; +static int verbose; +static int error_count; + +#define xmalloc(a) gcry_xmalloc ((a)) +#define xcalloc(a,b) gcry_xcalloc ((a),(b)) +#define xfree(a) gcry_free ((a)) +#define pass() do { ; } while (0) + +static void +show (const char *format, ...) +{ + va_list arg_ptr; + + if (!verbose) + return; + fprintf (stderr, "%s: ", PGM); + va_start (arg_ptr, format); + vfprintf (stderr, format, arg_ptr); + va_end (arg_ptr); +} + +static void +fail (const char *format, ...) +{ + va_list arg_ptr; + + fflush (stdout); + fprintf (stderr, "%s: ", PGM); + if (wherestr) + fprintf (stderr, "%s: ", wherestr); + va_start (arg_ptr, format); + vfprintf (stderr, format, arg_ptr); + va_end (arg_ptr); + error_count++; +} + +static void +die (const char *format, ...) +{ + va_list arg_ptr; + + fflush (stdout); + fprintf (stderr, "%s: ", PGM); + if (wherestr) + fprintf (stderr, "%s: ", wherestr); + va_start (arg_ptr, format); + vfprintf (stderr, format, arg_ptr); + va_end (arg_ptr); + exit (1); +} + + + +static void +set_get_point (void) +{ + gcry_mpi_point_t point; + gcry_mpi_t x, y, z; + + wherestr = "set_get_point"; + show ("checking point setting functions\n"); + + point = gcry_mpi_point_new (0); + x = gcry_mpi_set_ui (NULL, 17); + y = gcry_mpi_set_ui (NULL, 42); + z = gcry_mpi_set_ui (NULL, 11371); + gcry_mpi_point_get (x, y, z, point); + if (gcry_mpi_cmp_ui (x, 0) + || gcry_mpi_cmp_ui (y, 0) || gcry_mpi_cmp_ui (z, 0)) + fail ("new point not initialized to (0,0,0)\n"); + gcry_mpi_point_snatch_get (x, y, z, point); + point = NULL; + if (gcry_mpi_cmp_ui (x, 0) + || gcry_mpi_cmp_ui (y, 0) || gcry_mpi_cmp_ui (z, 0)) + fail ("snatch_get failed\n"); + gcry_mpi_release (x); + gcry_mpi_release (y); + gcry_mpi_release (z); + + point = gcry_mpi_point_new (0); + x = gcry_mpi_set_ui (NULL, 17); + y = gcry_mpi_set_ui (NULL, 42); + z = gcry_mpi_set_ui (NULL, 11371); + gcry_mpi_point_set (point, x, y, z); + gcry_mpi_set_ui (x, 23); + gcry_mpi_set_ui (y, 24); + gcry_mpi_set_ui (z, 25); + gcry_mpi_point_get (x, y, z, point); + if (gcry_mpi_cmp_ui (x, 17) + || gcry_mpi_cmp_ui (y, 42) || gcry_mpi_cmp_ui (z, 11371)) + fail ("point_set/point_get failed\n"); + gcry_mpi_point_snatch_set (point, x, y, z); + x = gcry_mpi_new (0); + y = gcry_mpi_new (0); + z = gcry_mpi_new (0); + gcry_mpi_point_get (x, y, z, point); + if (gcry_mpi_cmp_ui (x, 17) + || gcry_mpi_cmp_ui (y, 42) || gcry_mpi_cmp_ui (z, 11371)) + fail ("point_snatch_set/point_get failed\n"); + + gcry_mpi_point_release (point); + gcry_mpi_release (x); + gcry_mpi_release (y); + gcry_mpi_release (z); +} + + +int +main (int argc, char **argv) +{ + int debug = 0; + + if (argc > 1 && !strcmp (argv[1], "--verbose")) + verbose = 1; + else if (argc > 1 && !strcmp (argv[1], "--debug")) + verbose = debug = 1; + + if (!gcry_check_version (GCRYPT_VERSION)) + die ("version mismatch\n"); + + gcry_control (GCRYCTL_DISABLE_SECMEM, 0); + gcry_control (GCRYCTL_ENABLE_QUICK_RANDOM, 0); + if (debug) + gcry_control (GCRYCTL_SET_DEBUG_FLAGS, 1u, 0); + gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0); + + set_get_point (); + + + show ("All tests completed. Errors: %d\n", error_count); + return error_count ? 1 : 0; +} commit 6c4767637c512127a4362732b3ec51068554d328 Author: Werner Koch Date: Thu Mar 7 19:04:10 2013 +0100 mpi: Add mpi_snatch and change an internal typedef. * src/mpi.h (struct mpi_point_s): Rename to struct gcry_mpi_point. (mpi_point_struct): New typedef. (mpi_point_t): Change typedef to a pointer. Replace all occurrences to use mpi_point_struct. * mpi/ec.c (_gcry_mpi_ec_point_init): Rename to .. (_gcry_mpi_point_init): this. Change all callers. (_gcry_mpi_ec_point_free): Rename to .. (_gcry_mpi_point_free_parts): this. Change all callers. * mpi/mpiutil.c (gcry_mpi_snatch): New function. * src/gcrypt.h.in (gcry_mpi_snatch, mpi_snatch): Add protoype and macro. * src/visibility.c (gcry_mpi_snatch): Add wrapper. * src/visibility.h (gcry_mpi_snatch): Add macro magic. * src/libgcrypt.def, src/libgcrypt.vers: Add new function. -- This patch is a prerequisite to implement a public point API. The new function gcry_mpi_snatch is actually not needed for this but is useful anyway and will be used to implement the point API. diff --git a/NEWS b/NEWS index 45b892f..1db71e9 100644 --- a/NEWS +++ b/NEWS @@ -36,6 +36,7 @@ Noteworthy changes in version 1.6.0 (unreleased) GCRY_RNG_TYPE_STANDARD NEW. GCRY_RNG_TYPE_FIPS NEW. GCRY_RNG_TYPE_SYSTEM NEW. + gcry_mpi_snatch NEW. Noteworthy changes in version 1.5.0 (2011-06-29) @@ -705,6 +706,7 @@ Noteworthy changes in version 1.1.3 (2001-05-31) Copyright 2001, 2002, 2003, 2004, 2007, 2008, 2009, 2011 Free Software Foundation, Inc. +Copyright 2013 g10 Code GmbH This file is free software; as a special exception the author gives unlimited permission to copy and/or distribute it, with or without diff --git a/cipher/ecc.c b/cipher/ecc.c index 22de3d8..789fc6c 100644 --- a/cipher/ecc.c +++ b/cipher/ecc.c @@ -1,22 +1,22 @@ /* ecc.c - Elliptic Curve Cryptography - Copyright (C) 2007, 2008, 2010, 2011 Free Software Foundation, Inc. - - This file is part of Libgcrypt. - - Libgcrypt is free software; you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as - published by the Free Software Foundation; either version 2.1 of - the License, or (at your option) any later version. - - Libgcrypt is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, - USA. */ + * Copyright (C) 2007, 2008, 2010, 2011 Free Software Foundation, Inc. + * Copyright (C) 2013 g10 Code GmbH + * + * This file is part of Libgcrypt. + * + * Libgcrypt is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * Libgcrypt is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this program; if not, see . + */ /* This code is originally based on the Patch 0.1.6 for the gnupg 1.4.x branch as retrieved on 2007-03-21 from @@ -46,8 +46,6 @@ - In mpi/ec.c we use mpi_powm for x^2 mod p: Either implement a special case in mpi_powm or check whether mpi_mulm is faster. - - - Decide whether we should hide the mpi_point_t definition. */ @@ -63,25 +61,25 @@ /* Definition of a curve. */ typedef struct { - gcry_mpi_t p; /* Prime specifying the field GF(p). */ - gcry_mpi_t a; /* First coefficient of the Weierstrass equation. */ - gcry_mpi_t b; /* Second coefficient of the Weierstrass equation. */ - mpi_point_t G; /* Base point (generator). */ - gcry_mpi_t n; /* Order of G. */ - const char *name; /* Name of curve or NULL. */ + gcry_mpi_t p; /* Prime specifying the field GF(p). */ + gcry_mpi_t a; /* First coefficient of the Weierstrass equation. */ + gcry_mpi_t b; /* Second coefficient of the Weierstrass equation. */ + mpi_point_struct G; /* Base point (generator). */ + gcry_mpi_t n; /* Order of G. */ + const char *name; /* Name of the curve or NULL. */ } elliptic_curve_t; typedef struct { elliptic_curve_t E; - mpi_point_t Q; /* Q = [d]G */ + mpi_point_struct Q; /* Q = [d]G */ } ECC_public_key; typedef struct { elliptic_curve_t E; - mpi_point_t Q; + mpi_point_struct Q; gcry_mpi_t d; } ECC_secret_key; @@ -292,8 +290,8 @@ static void (*progress_cb) (void *, const char*, int, int, int); static void *progress_cb_data; -#define point_init(a) _gcry_mpi_ec_point_init ((a)) -#define point_free(a) _gcry_mpi_ec_point_free ((a)) +#define point_init(a) _gcry_mpi_point_init ((a)) +#define point_free(a) _gcry_mpi_point_free_parts ((a)) @@ -333,7 +331,7 @@ _gcry_register_pk_ecc_progress (void (*cb) (void *, const char *, /* Set the value from S into D. */ static void -point_set (mpi_point_t *d, mpi_point_t *s) +point_set (mpi_point_t d, mpi_point_t s) { mpi_set (d->x, s->x); mpi_set (d->y, s->y); @@ -521,7 +519,7 @@ generate_key (ECC_secret_key *sk, unsigned int nbits, const char *name, gpg_err_code_t err; elliptic_curve_t E; gcry_mpi_t d; - mpi_point_t Q; + mpi_point_struct Q; mpi_ec_t ctx; gcry_random_level_t random_level; @@ -600,7 +598,7 @@ test_keys (ECC_secret_key *sk, unsigned int nbits) { ECC_public_key pk; gcry_mpi_t test = mpi_new (nbits); - mpi_point_t R_; + mpi_point_struct R_; gcry_mpi_t c = mpi_new (nbits); gcry_mpi_t out = mpi_new (nbits); gcry_mpi_t r = mpi_new (nbits); @@ -648,7 +646,7 @@ static int check_secret_key (ECC_secret_key * sk) { int rc = 1; - mpi_point_t Q; + mpi_point_struct Q; gcry_mpi_t y_2, y2; mpi_ec_t ctx = NULL; @@ -719,7 +717,7 @@ sign (gcry_mpi_t input, ECC_secret_key *skey, gcry_mpi_t r, gcry_mpi_t s) { gpg_err_code_t err = 0; gcry_mpi_t k, dr, sum, k_1, x; - mpi_point_t I; + mpi_point_struct I; mpi_ec_t ctx; if (DBG_CIPHER) @@ -790,7 +788,7 @@ verify (gcry_mpi_t input, ECC_public_key *pkey, gcry_mpi_t r, gcry_mpi_t s) { gpg_err_code_t err = 0; gcry_mpi_t h, h1, h2, x, y; - mpi_point_t Q, Q1, Q2; + mpi_point_struct Q, Q1, Q2; mpi_ec_t ctx; if( !(mpi_cmp_ui (r, 0) > 0 && mpi_cmp (r, pkey->E.n) < 0) ) @@ -925,7 +923,7 @@ ec2os (gcry_mpi_t x, gcry_mpi_t y, gcry_mpi_t p) /* RESULT must have been initialized and is set on success to the point given by VALUE. */ static gcry_error_t -os2ec (mpi_point_t *result, gcry_mpi_t value) +os2ec (mpi_point_t result, gcry_mpi_t value) { gcry_error_t err; size_t n; @@ -1430,7 +1428,7 @@ ecc_encrypt_raw (int algo, gcry_mpi_t *resarr, gcry_mpi_t k, /* The following is false: assert( mpi_cmp_ui( R.x, 1 )==0 );, so */ { - mpi_point_t R; /* Result that we return. */ + mpi_point_struct R; /* Result that we return. */ gcry_mpi_t x, y; x = mpi_new (0); @@ -1490,8 +1488,8 @@ ecc_decrypt_raw (int algo, gcry_mpi_t *result, gcry_mpi_t *data, gcry_mpi_t *skey, int flags) { ECC_secret_key sk; - mpi_point_t R; /* Result that we return. */ - mpi_point_t kG; + mpi_point_struct R; /* Result that we return. */ + mpi_point_struct kG; mpi_ec_t ctx; gcry_mpi_t r; int err; diff --git a/doc/gcrypt.texi b/doc/gcrypt.texi index fa24def..8bfcbfd 100644 --- a/doc/gcrypt.texi +++ b/doc/gcrypt.texi @@ -3600,6 +3600,13 @@ small values (usually up to the word size of the CPU). Swap the values of @var{a} and @var{b}. @end deftypefun + at deftypefun void gcry_mpi_snatch (@w{gcry_mpi_t @var{w}}, @ + @w{const gcry_mpi_t @var{u}}) + +Set @var{u} into @var{w} and release @var{u}. If @var{w} is + at code{NULL} only @var{u} will be released. + at end deftypefun + @node MPI formats @section MPI formats diff --git a/mpi/ec.c b/mpi/ec.c index e325358..7b1ef2b 100644 --- a/mpi/ec.c +++ b/mpi/ec.c @@ -1,23 +1,22 @@ /* ec.c - Elliptic Curve functions - Copyright (C) 2007 Free Software Foundation, Inc. - - This file is part of Libgcrypt. - - Libgcrypt is free software; you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as - published by the Free Software Foundation; either version 2.1 of - the License, or (at your option) any later version. - - Libgcrypt is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, - USA. */ - + * Copyright (C) 2007 Free Software Foundation, Inc. + * Copyright (C) 2013 g10 Code GmbH + * + * This file is part of Libgcrypt. + * + * Libgcrypt is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * Libgcrypt is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this program; if not, see . + */ #include #include @@ -28,8 +27,8 @@ #include "g10lib.h" -#define point_init(a) _gcry_mpi_ec_point_init ((a)) -#define point_free(a) _gcry_mpi_ec_point_free ((a)) +#define point_init(a) _gcry_mpi_point_init ((a)) +#define point_free(a) _gcry_mpi_point_free_parts ((a)) /* Object to represent a point in projective coordinates. */ @@ -64,10 +63,10 @@ struct mpi_ec_ctx_s -/* Initialized a point object. gcry_mpi_ec_point_free shall be used - to release this object. */ +/* Initialize the fields of a point object. gcry_mpi_point_free_parts + may be used to release the fields. */ void -_gcry_mpi_ec_point_init (mpi_point_t *p) +_gcry_mpi_point_init (mpi_point_t p) { p->x = mpi_new (0); p->y = mpi_new (0); @@ -75,18 +74,19 @@ _gcry_mpi_ec_point_init (mpi_point_t *p) } -/* Release a point object. */ +/* Release the parts of a point object. */ void -_gcry_mpi_ec_point_free (mpi_point_t *p) +_gcry_mpi_point_free_parts (mpi_point_t p) { mpi_free (p->x); p->x = NULL; mpi_free (p->y); p->y = NULL; mpi_free (p->z); p->z = NULL; } + /* Set the value from S into D. */ static void -point_set (mpi_point_t *d, mpi_point_t *s) +point_set (mpi_point_t d, mpi_point_t s) { mpi_set (d->x, s->x); mpi_set (d->y, s->y); @@ -339,12 +339,13 @@ _gcry_mpi_ec_free (mpi_ec_t ctx) gcry_free (ctx); } + /* Compute the affine coordinates from the projective coordinates in POINT. Set them into X and Y. If one coordinate is not required, X or Y may be passed as NULL. CTX is the usual context. Returns: 0 on success or !0 if POINT is at infinity. */ int -_gcry_mpi_ec_get_affine (gcry_mpi_t x, gcry_mpi_t y, mpi_point_t *point, +_gcry_mpi_ec_get_affine (gcry_mpi_t x, gcry_mpi_t y, mpi_point_t point, mpi_ec_t ctx) { gcry_mpi_t z1, z2, z3; @@ -374,12 +375,10 @@ _gcry_mpi_ec_get_affine (gcry_mpi_t x, gcry_mpi_t y, mpi_point_t *point, } - - /* RESULT = 2 * POINT */ void -_gcry_mpi_ec_dup_point (mpi_point_t *result, mpi_point_t *point, mpi_ec_t ctx) +_gcry_mpi_ec_dup_point (mpi_point_t result, mpi_point_t point, mpi_ec_t ctx) { #define x3 (result->x) #define y3 (result->y) @@ -463,8 +462,8 @@ _gcry_mpi_ec_dup_point (mpi_point_t *result, mpi_point_t *point, mpi_ec_t ctx) /* RESULT = P1 + P2 */ void -_gcry_mpi_ec_add_points (mpi_point_t *result, - mpi_point_t *p1, mpi_point_t *p2, +_gcry_mpi_ec_add_points (mpi_point_t result, + mpi_point_t p1, mpi_point_t p2, mpi_ec_t ctx) { #define x1 (p1->x ) @@ -608,8 +607,8 @@ _gcry_mpi_ec_add_points (mpi_point_t *result, an integer SCALAR and a POINT as well as the usual context CTX. RESULT will be set to the resulting point. */ void -_gcry_mpi_ec_mul_point (mpi_point_t *result, - gcry_mpi_t scalar, mpi_point_t *point, +_gcry_mpi_ec_mul_point (mpi_point_t result, + gcry_mpi_t scalar, mpi_point_t point, mpi_ec_t ctx) { #if 0 @@ -632,7 +631,7 @@ _gcry_mpi_ec_mul_point (mpi_point_t *result, #else gcry_mpi_t x1, y1, z1, k, h, yy; unsigned int i, loops; - mpi_point_t p1, p2, p1inv; + mpi_point_struct p1, p2, p1inv; x1 = mpi_alloc_like (ctx->p); y1 = mpi_alloc_like (ctx->p); diff --git a/mpi/mpiutil.c b/mpi/mpiutil.c index 76630a6..d410d90 100644 --- a/mpi/mpiutil.c +++ b/mpi/mpiutil.c @@ -1,6 +1,7 @@ /* mpiutil.ac - Utility functions for MPI * Copyright (C) 1998, 2000, 2001, 2002, 2003, * 2007 Free Software Foundation, Inc. + * Copyright (C) 2013 g10 Code GmbH * * This file is part of Libgcrypt. * @@ -296,6 +297,24 @@ _gcry_mpi_alloc_like( gcry_mpi_t a ) } +/* Set U into W and release U. If W is NULL only U will be released. */ +void +gcry_mpi_snatch (gcry_mpi_t w, gcry_mpi_t u) +{ + if (w) + { + _gcry_mpi_assign_limb_space (w, u->d, u->alloced); + w->nlimbs = u->nlimbs; + w->sign = u->sign; + w->flags = u->flags; + u->alloced = 0; + u->nlimbs = 0; + u->d = NULL; + } + _gcry_mpi_free (u); +} + + gcry_mpi_t gcry_mpi_set( gcry_mpi_t w, gcry_mpi_t u) { diff --git a/src/gcrypt.h.in b/src/gcrypt.h.in index dae8d1c..7d2b89d 100644 --- a/src/gcrypt.h.in +++ b/src/gcrypt.h.in @@ -2,6 +2,7 @@ * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, * 2006, 2007, 2008, 2009, 2010, 2011, * 2012 Free Software Foundation, Inc. + * Copyright (C) 2012, 2013 g10 Code GmbH * * This file is part of Libgcrypt. * @@ -466,6 +467,9 @@ void gcry_mpi_release (gcry_mpi_t a); /* Create a new number with the same value as A. */ gcry_mpi_t gcry_mpi_copy (const gcry_mpi_t a); +/* Store the big integer value U in W and release U. */ +void gcry_mpi_snatch (gcry_mpi_t w, gcry_mpi_t u); + /* Store the big integer value U in W. */ gcry_mpi_t gcry_mpi_set (gcry_mpi_t w, const gcry_mpi_t u); @@ -629,6 +633,7 @@ int gcry_mpi_get_flag (gcry_mpi_t a, enum gcry_mpi_flag flag); while (0) #define mpi_copy( a ) gcry_mpi_copy( (a) ) +#define mpi_snatch( w, u) gcry_mpi_snatch( (w), (u) ) #define mpi_set( w, u) gcry_mpi_set( (w), (u) ) #define mpi_set_ui( w, u) gcry_mpi_set_ui( (w), (u) ) #define mpi_cmp( u, v ) gcry_mpi_cmp( (u), (v) ) diff --git a/src/libgcrypt.def b/src/libgcrypt.def index 9bf0167..cc49e74 100644 --- a/src/libgcrypt.def +++ b/src/libgcrypt.def @@ -211,3 +211,5 @@ EXPORTS gcry_pk_get_param @193 gcry_kdf_derive @194 + + gcry_mpi_snatch @195 diff --git a/src/libgcrypt.vers b/src/libgcrypt.vers index dcb3749..200f04e 100644 --- a/src/libgcrypt.vers +++ b/src/libgcrypt.vers @@ -86,7 +86,7 @@ GCRYPT_1.6 { gcry_mpi_set_flag; gcry_mpi_set_highbit; gcry_mpi_set_opaque; gcry_mpi_set_ui; gcry_mpi_snew; gcry_mpi_sub; gcry_mpi_sub_ui; gcry_mpi_subm; gcry_mpi_swap; gcry_mpi_test_bit; - gcry_mpi_lshift; + gcry_mpi_lshift; gcry_mpi_snatch; local: *; diff --git a/src/mpi.h b/src/mpi.h index 65a4f97..b3f19e5 100644 --- a/src/mpi.h +++ b/src/mpi.h @@ -108,6 +108,7 @@ struct gcry_mpi #define mpi_is_secure(a) ((a) && ((a)->flags&1)) #define mpi_clear(a) _gcry_mpi_clear ((a)) #define mpi_alloc_like(a) _gcry_mpi_alloc_like((a)) +#define mpi_snatch(a,b) _gcry_mpi_snatch ((a),(b)) #define mpi_set(a,b) _gcry_mpi_set ((a),(b)) #define mpi_set_ui(a,b) _gcry_mpi_set_ui ((a),(b)) #define mpi_get_ui(a,b) _gcry_mpi_get_ui ((a),(b)) @@ -230,32 +231,37 @@ void _gcry_mpi_normalize( gcry_mpi_t a ); /*-- ec.c --*/ /* Object to represent a point in projective coordinates. */ -struct mpi_point_s; -typedef struct mpi_point_s mpi_point_t; -struct mpi_point_s +struct gcry_mpi_point { gcry_mpi_t x; gcry_mpi_t y; gcry_mpi_t z; }; +typedef struct gcry_mpi_point mpi_point_struct; +typedef struct gcry_mpi_point *mpi_point_t; + +void _gcry_mpi_point_init (mpi_point_t p); +void _gcry_mpi_point_free_parts (mpi_point_t p); +void _gcry_mpi_get_point (gcry_mpi_t x, gcry_mpi_t y, gcry_mpi_t z, + mpi_point_t point); +void _gcry_mpi_snatch_point (gcry_mpi_t x, gcry_mpi_t y, gcry_mpi_t z, + mpi_point_t point); /* Context used with elliptic curve functions. */ struct mpi_ec_ctx_s; typedef struct mpi_ec_ctx_s *mpi_ec_t; -void _gcry_mpi_ec_point_init (mpi_point_t *p); -void _gcry_mpi_ec_point_free (mpi_point_t *p); mpi_ec_t _gcry_mpi_ec_init (gcry_mpi_t p, gcry_mpi_t a); void _gcry_mpi_ec_free (mpi_ec_t ctx); -int _gcry_mpi_ec_get_affine (gcry_mpi_t x, gcry_mpi_t y, mpi_point_t *point, +int _gcry_mpi_ec_get_affine (gcry_mpi_t x, gcry_mpi_t y, mpi_point_t point, mpi_ec_t ctx); -void _gcry_mpi_ec_dup_point (mpi_point_t *result, - mpi_point_t *point, mpi_ec_t ctx); -void _gcry_mpi_ec_add_points (mpi_point_t *result, - mpi_point_t *p1, mpi_point_t *p2, +void _gcry_mpi_ec_dup_point (mpi_point_t result, + mpi_point_t point, mpi_ec_t ctx); +void _gcry_mpi_ec_add_points (mpi_point_t result, + mpi_point_t p1, mpi_point_t p2, mpi_ec_t ctx); -void _gcry_mpi_ec_mul_point (mpi_point_t *result, - gcry_mpi_t scalar, mpi_point_t *point, +void _gcry_mpi_ec_mul_point (mpi_point_t result, + gcry_mpi_t scalar, mpi_point_t point, mpi_ec_t ctx); diff --git a/src/visibility.c b/src/visibility.c index 2d3edbc..732f058 100644 --- a/src/visibility.c +++ b/src/visibility.c @@ -1,5 +1,6 @@ /* visibility.c - Wrapper for all public functions. * Copyright (C) 2007, 2008, 2011 Free Software Foundation, Inc. + * Copyright (C) 2013 g10 Code GmbH * * This file is part of Libgcrypt. * @@ -261,6 +262,12 @@ gcry_mpi_copy (const gcry_mpi_t a) return _gcry_mpi_copy (a); } +void +gcry_mpi_snatch (gcry_mpi_t w, const gcry_mpi_t u) +{ + return _gcry_mpi_snatch (w, u); +} + gcry_mpi_t gcry_mpi_set (gcry_mpi_t w, const gcry_mpi_t u) { diff --git a/src/visibility.h b/src/visibility.h index 4606a20..429c246 100644 --- a/src/visibility.h +++ b/src/visibility.h @@ -172,6 +172,7 @@ #define gcry_mpi_rshift _gcry_mpi_rshift #define gcry_mpi_lshift _gcry_mpi_lshift #define gcry_mpi_scan _gcry_mpi_scan +#define gcry_mpi_snatch _gcry_mpi_snatch #define gcry_mpi_set _gcry_mpi_set #define gcry_mpi_set_bit _gcry_mpi_set_bit #define gcry_mpi_set_flag _gcry_mpi_set_flag @@ -378,6 +379,7 @@ gcry_err_code_t gcry_md_get (gcry_md_hd_t hd, int algo, #undef gcry_mpi_rshift #undef gcry_mpi_lshift #undef gcry_mpi_scan +#undef gcry_mpi_snatch #undef gcry_mpi_set #undef gcry_mpi_set_bit #undef gcry_mpi_set_flag @@ -544,6 +546,7 @@ MARK_VISIBLE (gcry_mpi_release) MARK_VISIBLE (gcry_mpi_rshift) MARK_VISIBLE (gcry_mpi_lshift) MARK_VISIBLE (gcry_mpi_scan) +MARK_VISIBLE (gcry_mpi_snatch) MARK_VISIBLE (gcry_mpi_set) MARK_VISIBLE (gcry_mpi_set_bit) MARK_VISIBLE (gcry_mpi_set_flag) ----------------------------------------------------------------------- Summary of changes: NEWS | 15 ++ cipher/ecc.c | 92 +++++----- doc/gcrypt.texi | 159 ++++++++++++++++- mpi/ec.c | 266 ++++++++++++++++++++++------ mpi/mpiutil.c | 19 ++ src/Makefile.am | 2 +- src/context.c | 118 +++++++++++++ compat/libcompat.h => src/context.h | 24 +-- src/gcrypt.h.in | 74 ++++++++- src/libgcrypt.def | 17 ++ src/libgcrypt.vers | 10 +- src/mpi.h | 32 ++-- src/visibility.c | 92 ++++++++++- src/visibility.h | 33 ++++ tests/Makefile.am | 2 +- tests/t-mpi-point.c | 331 +++++++++++++++++++++++++++++++++++ 16 files changed, 1147 insertions(+), 139 deletions(-) create mode 100644 src/context.c copy compat/libcompat.h => src/context.h (62%) create mode 100644 tests/t-mpi-point.c hooks/post-receive -- The GNU crypto library http://git.gnupg.org From cvs at cvs.gnupg.org Fri Mar 15 00:51:10 2013 From: cvs at cvs.gnupg.org (by NIIBE Yutaka) Date: Fri, 15 Mar 2013 00:51:10 +0100 Subject: [git] GnuPG - branch, STABLE-BRANCH-2-0, updated. gnupg-2.0.19-91-g91423a8 Message-ID: This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "The GNU Privacy Guard". The branch, STABLE-BRANCH-2-0 has been updated via 91423a826e3cefd78fc0006e65b56559dd578784 (commit) from 6d0e41815a726ad4b170ed18cc772a1817559299 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 91423a826e3cefd78fc0006e65b56559dd578784 Author: NIIBE Yutaka Date: Fri Mar 15 08:34:32 2013 +0900 scd: ccid-driver supporting larger APDU. * scd/ccid-driver.c (ccid_transceive_apdu_level): Support larger APDU. -- This is still ad hoc change, but it's OK. Supporting full extended APDU exchange level is not worth yet. diff --git a/scd/ccid-driver.c b/scd/ccid-driver.c index ccf579c..dd9fabe 100644 --- a/scd/ccid-driver.c +++ b/scd/ccid-driver.c @@ -2840,7 +2840,7 @@ ccid_transceive_apdu_level (ccid_driver_t handle, /* The maximum length for a short APDU T=1 block is 261. For an extended APDU T=1 block the maximum length 65544; however extended APDU exchange level is not fully supported yet. */ - if (apdulen > 289) + if (apdulen > sizeof (send_buffer) - 10) return CCID_DRIVER_ERR_INV_VALUE; /* Invalid length. */ msg[0] = PC_to_RDR_XfrBlock; ----------------------------------------------------------------------- Summary of changes: scd/ccid-driver.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) hooks/post-receive -- The GNU Privacy Guard http://git.gnupg.org From cvs at cvs.gnupg.org Fri Mar 15 00:51:24 2013 From: cvs at cvs.gnupg.org (by NIIBE Yutaka) Date: Fri, 15 Mar 2013 00:51:24 +0100 Subject: [git] GnuPG - branch, master, updated. gnupg-2.1.0beta3-169-g76dc5c0 Message-ID: This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "The GNU Privacy Guard". The branch, master has been updated via 76dc5c08dc2686eef32e1bd221c60fe91201246f (commit) via 006782068e4d2a9413770400494421a2e9726ee7 (commit) from 73ad742deacfe2bf7d6efc7cc30f9ced2d83521a (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 76dc5c08dc2686eef32e1bd221c60fe91201246f Author: NIIBE Yutaka Date: Fri Mar 15 08:34:32 2013 +0900 scd: ccid-driver supporting larger APDU. * scd/ccid-driver.c (ccid_transceive_apdu_level): Support larger APDU. -- This is still ad hoc change, but it's OK. Supporting full extended APDU exchange level is not worth yet. diff --git a/scd/ccid-driver.c b/scd/ccid-driver.c index 2d1ef8d..da5fac9 100644 --- a/scd/ccid-driver.c +++ b/scd/ccid-driver.c @@ -2839,7 +2839,7 @@ ccid_transceive_apdu_level (ccid_driver_t handle, /* The maximum length for a short APDU T=1 block is 261. For an extended APDU T=1 block the maximum length 65544; however extended APDU exchange level is not fully supported yet. */ - if (apdulen > 289) + if (apdulen > sizeof (send_buffer) - 10) return CCID_DRIVER_ERR_INV_VALUE; /* Invalid length. */ msg[0] = PC_to_RDR_XfrBlock; commit 006782068e4d2a9413770400494421a2e9726ee7 Author: NIIBE Yutaka Date: Fri Mar 15 08:33:13 2013 +0900 scd: fix missing close paren. * scd/app-openpgp.c (du_auth): Fix. -- diff --git a/scd/app-openpgp.c b/scd/app-openpgp.c index 1df35b2..673570d 100644 --- a/scd/app-openpgp.c +++ b/scd/app-openpgp.c @@ -3525,7 +3525,7 @@ do_auth (app_t app, const char *keyidstr, return gpg_error (GPG_ERR_INV_VALUE); if (app->app_local->keyattr[2].key_type == KEY_TYPE_ECDSA - && (indatalen == 51 || indatalen == 67 || indatalen == 83) + && (indatalen == 51 || indatalen == 67 || indatalen == 83)) { const char *p = (const char *)indata + 19; indata = p; ----------------------------------------------------------------------- Summary of changes: scd/app-openpgp.c | 2 +- scd/ccid-driver.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) hooks/post-receive -- The GNU Privacy Guard http://git.gnupg.org From cvs at cvs.gnupg.org Fri Mar 15 15:08:58 2013 From: cvs at cvs.gnupg.org (by Werner Koch) Date: Fri, 15 Mar 2013 15:08:58 +0100 Subject: [git] GCRYPT - branch, master, updated. libgcrypt-1.5.0-96-g229f321 Message-ID: This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "The GNU crypto library". The branch, master has been updated via 229f3219f80c9369ed9624242c0436ae6d293201 (commit) via e005629bd7bebb3e13945645c6e1230b44ab16a2 (commit) via 1fecae98ee7e0fa49b29f98efa6817ca121ed98a (commit) from 5e743bc72e3fee3d550d0d7ae98596b7de6b46f8 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 229f3219f80c9369ed9624242c0436ae6d293201 Author: Werner Koch Date: Fri Mar 15 14:43:19 2013 +0100 mpi: Add functions to manipulate an EC context. * src/gcrypt.h.in (gcry_mpi_ec_p_new): Remove. (gcry_mpi_ec_new): New. (gcry_mpi_ec_get_mpi): New. (gcry_mpi_ec_get_point): New. (gcry_mpi_ec_set_mpi): New. (gcry_mpi_ec_set_point): New. * src/visibility.c (gcry_mpi_ec_p_new): Remove. * mpi/ec.c (_gcry_mpi_ec_p_new): Make it an internal function and change to return an error code. (_gcry_mpi_ec_get_mpi): New. (_gcry_mpi_ec_get_point): New. (_gcry_mpi_ec_set_mpi): New. (_gcry_mpi_ec_set_point): New. * src/mpi.h: Add new prototypes. * src/ec-context.h: New. * mpi/ec.c: Include that header. (mpi_ec_ctx_s): Move to ec-context.h, add new fields, and put some fields into an inner struct. (point_copy): New. * cipher/ecc.c (fill_in_curve): Allow passing NULL for R_NBITS. (mpi_from_keyparam, point_from_keyparam): New. (_gcry_mpi_ec_new): New. * tests/t-mpi-point.c (test-curve): New. (ec_p_new): New. Use it instead of the removed gcry_mpi_ec_p_new. (get_and_cmp_mpi, get_and_cmp_point): New. (context_param): New test. (basic_ec_math_simplified): New test. (main): Call new tests. * src/context.c (_gcry_ctx_get_pointer): Check for a NULL CTX. -- gcry_mpi_ec_p_new() was a specialized version of the more general new gcry_mpi_ec_new(). It was added to master only a few days ago, thus there should be no problem to remove it. A replacement can easily be written (cf. t-mpi-point.c). Note that gcry_mpi_ec_set_mpi and gcry_mpi_ec_set_point have not yet been tested. diff --git a/NEWS b/NEWS index c0a7e8e..429f666 100644 --- a/NEWS +++ b/NEWS @@ -46,7 +46,12 @@ Noteworthy changes in version 1.6.0 (unreleased) gcry_mpi_point_snatch_set NEW. gcry_ctx_t NEW. gcry_ctx_release NEW. - gcry_mpi_ec_p_new NEW. + gcry_mpi_ec_new NEW. + gcry_mpi_ec_get_mpi NEW. + gcry_mpi_ec_get_point NEW. + gcry_mpi_ec_set_mpi NEW. + gcry_mpi_ec_set_point NEW. + gcry_mpi_ec_get_affine NEW. gcry_mpi_ec_dup NEW. gcry_mpi_ec_add NEW. gcry_mpi_ec_mul NEW. diff --git a/cipher/ecc.c b/cipher/ecc.c index 4efbef4..c95a57a 100644 --- a/cipher/ecc.c +++ b/cipher/ecc.c @@ -46,6 +46,12 @@ - In mpi/ec.c we use mpi_powm for x^2 mod p: Either implement a special case in mpi_powm or check whether mpi_mulm is faster. + + - Split this up into several files. For example the curve + management and gcry_mpi_ec_new are independent of the actual ECDSA + implementation. This will also help to support optimized versions + of some curves. + */ @@ -53,10 +59,13 @@ #include #include #include +#include #include "g10lib.h" #include "mpi.h" #include "cipher.h" +#include "context.h" +#include "ec-context.h" /* Definition of a curve. */ typedef struct @@ -440,8 +449,8 @@ gen_k (gcry_mpi_t p, int security_level) /* Generate the crypto system setup. This function takes the NAME of a curve or the desired number of bits and stores at R_CURVE the - parameters of the named curve or those of a suitable curve. The - chosen number of bits is stored on R_NBITS. */ + parameters of the named curve or those of a suitable curve. If + R_NBITS is not NULL, the chosen number of bits is stored there. */ static gpg_err_code_t fill_in_curve (unsigned int nbits, const char *name, elliptic_curve_t *curve, unsigned int *r_nbits) @@ -491,7 +500,8 @@ fill_in_curve (unsigned int nbits, const char *name, if (fips_mode () && !domain_parms[idx].fips ) return GPG_ERR_NOT_SUPPORTED; - *r_nbits = domain_parms[idx].nbits; + if (r_nbits) + *r_nbits = domain_parms[idx].nbits; curve->p = scanval (domain_parms[idx].p); curve->a = scanval (domain_parms[idx].a); curve->b = scanval (domain_parms[idx].b); @@ -1689,6 +1699,277 @@ compute_keygrip (gcry_md_hd_t md, gcry_sexp_t keyparam) } + +/* + Low-level API helper functions. + */ + +/* Helper to extract an MPI from key parameters. */ +static gpg_err_code_t +mpi_from_keyparam (gcry_mpi_t *r_a, gcry_sexp_t keyparam, const char *name) +{ + gcry_err_code_t ec = 0; + gcry_sexp_t l1; + + l1 = gcry_sexp_find_token (keyparam, name, 0); + if (l1) + { + *r_a = gcry_sexp_nth_mpi (l1, 1, GCRYMPI_FMT_USG); + gcry_sexp_release (l1); + if (!*r_a) + ec = GPG_ERR_INV_OBJ; + } + return ec; +} + +/* Helper to extract a point from key parameters. If no parameter + with NAME is found, the functions tries to find a non-encoded point + by appending ".x", ".y" and ".z" to NAME. ".z" is in this case + optional and defaults to 1. */ +static gpg_err_code_t +point_from_keyparam (gcry_mpi_point_t *r_a, + gcry_sexp_t keyparam, const char *name) +{ + gcry_err_code_t ec; + gcry_mpi_t a = NULL; + gcry_mpi_point_t point; + + ec = mpi_from_keyparam (&a, keyparam, name); + if (ec) + return ec; + + if (a) + { + point = gcry_mpi_point_new (0); + ec = os2ec (point, a); + if (ec) + { + gcry_mpi_point_release (point); + mpi_free (a); + return ec; + } + } + else + { + char *tmpname; + gcry_mpi_t x = NULL; + gcry_mpi_t y = NULL; + gcry_mpi_t z = NULL; + + tmpname = gcry_malloc (strlen (name) + 2 + 1); + if (!tmpname) + return gpg_err_code_from_syserror (); + strcpy (stpcpy (tmpname, name), ".x"); + ec = mpi_from_keyparam (&x, keyparam, tmpname); + if (ec) + { + gcry_free (tmpname); + return ec; + } + strcpy (stpcpy (tmpname, name), ".y"); + ec = mpi_from_keyparam (&y, keyparam, tmpname); + if (ec) + { + mpi_free (x); + gcry_free (tmpname); + return ec; + } + strcpy (stpcpy (tmpname, name), ".z"); + ec = mpi_from_keyparam (&z, keyparam, tmpname); + if (ec) + { + mpi_free (y); + mpi_free (x); + gcry_free (tmpname); + return ec; + } + if (!z) + z = mpi_set_ui (NULL, 1); + if (x && y) + point = gcry_mpi_point_snatch_set (NULL, x, y, z); + else + { + mpi_free (x); + mpi_free (y); + mpi_free (z); + point = NULL; + } + gcry_free (tmpname); + } + + if (point) + *r_a = point; + return 0; +} + + +/* This function creates a new context for elliptic curve operations. + Either KEYPARAM or CURVENAME must be given. If both are given and + KEYPARAM has no curve parameter CURVENAME is used to add missing + parameters. On success 0 is returned and the new context stored at + R_CTX. On error NULL is stored at R_CTX and an error code is + returned. The context needs to be released using + gcry_ctx_release. */ +gpg_err_code_t +_gcry_mpi_ec_new (gcry_ctx_t *r_ctx, + gcry_sexp_t keyparam, const char *curvename) +{ + gpg_err_code_t errc; + gcry_ctx_t ctx = NULL; + gcry_mpi_t p = NULL; + gcry_mpi_t a = NULL; + gcry_mpi_t b = NULL; + gcry_mpi_point_t G = NULL; + gcry_mpi_t n = NULL; + gcry_mpi_point_t Q = NULL; + gcry_mpi_t d = NULL; + gcry_sexp_t l1; + + *r_ctx = NULL; + + if (keyparam) + { + errc = mpi_from_keyparam (&p, keyparam, "p"); + if (errc) + goto leave; + errc = mpi_from_keyparam (&a, keyparam, "a"); + if (errc) + goto leave; + errc = mpi_from_keyparam (&b, keyparam, "b"); + if (errc) + goto leave; + errc = point_from_keyparam (&G, keyparam, "G"); + if (errc) + goto leave; + errc = mpi_from_keyparam (&n, keyparam, "n"); + if (errc) + goto leave; + errc = point_from_keyparam (&Q, keyparam, "Q"); + if (errc) + goto leave; + errc = mpi_from_keyparam (&d, keyparam, "d"); + if (errc) + goto leave; + } + + + /* Check whether a curve parameter is available and use that to fill + in missing values. If no curve parameter is available try an + optional provided curvename. If only the curvename has been + given use that one. */ + if (keyparam) + l1 = gcry_sexp_find_token (keyparam, "curve", 5); + else + l1 = NULL; + if (l1 || curvename) + { + char *name; + elliptic_curve_t *E; + + if (l1) + { + name = _gcry_sexp_nth_string (l1, 1); + gcry_sexp_release (l1); + if (!name) + { + errc = GPG_ERR_INV_OBJ; /* Name missing or out of core. */ + goto leave; + } + } + else + name = NULL; + + E = gcry_calloc (1, sizeof *E); + if (!E) + { + errc = gpg_err_code_from_syserror (); + gcry_free (name); + goto leave; + } + + errc = fill_in_curve (0, name? name : curvename, E, NULL); + gcry_free (name); + if (errc) + { + gcry_free (E); + goto leave; + } + + if (!p) + { + p = E->p; + E->p = NULL; + } + if (!a) + { + a = E->a; + E->a = NULL; + } + if (!b) + { + b = E->b; + E->b = NULL; + } + if (!G) + { + G = gcry_mpi_point_snatch_set (NULL, E->G.x, E->G.y, E->G.z); + E->G.x = NULL; + E->G.y = NULL; + E->G.z = NULL; + } + if (!n) + { + n = E->n; + E->n = NULL; + } + curve_free (E); + gcry_free (E); + } + + errc = _gcry_mpi_ec_p_new (&ctx, p, a); + if (!errc) + { + mpi_ec_t ec = _gcry_ctx_get_pointer (ctx, CONTEXT_TYPE_EC); + + if (b) + { + ec->b = b; + b = NULL; + } + if (G) + { + ec->G = G; + G = NULL; + } + if (n) + { + ec->n = n; + n = NULL; + } + if (Q) + { + ec->Q = Q; + Q = NULL; + } + if (d) + { + ec->d = d; + d = NULL; + } + + *r_ctx = ctx; + } + + leave: + mpi_free (p); + mpi_free (a); + mpi_free (b); + gcry_mpi_point_release (G); + mpi_free (n); + gcry_mpi_point_release (Q); + mpi_free (d); + return errc; +} diff --git a/doc/gcrypt.texi b/doc/gcrypt.texi index a56d527..4d48eb4 100644 --- a/doc/gcrypt.texi +++ b/doc/gcrypt.texi @@ -2058,6 +2058,7 @@ and no @var{x-mpi}. @node ECC key parameters @subsection ECC key parameters + at anchor{ecc_keyparam} @noindent An ECC private key is described by this S-expression: @@ -2084,7 +2085,7 @@ Base point @math{g}. @item n-mpi Order of @math{g} @item q-point -The point representing the public key @math{Q = dP}. +The point representing the public key @math{Q = dG}. @item d-mpi The private key @math{d} @end table @@ -3919,16 +3920,71 @@ some extra memory allocations and copies. Returns @var{point} or the newly allocated point object. @end deftypefun - at anchor{gcry_mpi_ec_p_new} - at deftypefun gcry_ctx_t gcry_mpi_ec_p_new (@w{gcry_mpi_t @var{p}}, @ - @w{gcry_mpi_t @var{a}} + at anchor{gcry_mpi_ec_new} + at deftypefun gpg_error_t gcry_mpi_ec_p_new (@w{gpg_ctx_t *@var{r_ctx}}, @ + @w{gcry_sexp_t @var{keyparam}}, @w{const char *@var{curvename}}) -Allocate a new context for elliptic curve operations based on the -field GF(p). @var{p} is the prime specifying this field, @var{a} is -the first coefficient of the Weierstrass equation. The function -returns a context object which eventually needs to be released using - at ref{gcry_ctx_release}. On error this function returns @code{NULL} -and sets @code{errno}. +Allocate a new context for elliptic curve operations. If + at var{keyparam} is given it specifies the parameters of the curve +(@pxref{ecc_keyparam}). If @var{curvename} is given in addition to + at var{keyparam} and the key parameters do not include a named curve +reference, the string @var{curvename} is used to fill in missing +parameters. If only @var{curvename} is given, the context is +initialized for this named curve. + +If a parameter specifying a point (e.g. @code{g} or @code{q}) is not +found, the parser looks for a non-encoded point by appending + at code{.x}, @code{.y}, and @code{.z} to the parameter name and looking +them all up to create a point. A parameter with the suffix @code{.z} +is optional and defaults to 1. + +On success the function returns 0 and stores the new context object at + at var{r_ctx}; this object eventually needs to be released +(@pxref{gcry_ctx_release}). On error the function stores @code{NULL} at + at var{r_ctx} and returns an error code. + at end deftypefun + + at deftypefun gcry_mpi_t gcry_mpi_ec_get_mpi ( @ + @w{const char *@var{name}}, @w{gcry_ctx_t @var{ctx}}, @w{int @var{copy}}) + +Return the MPI with @var{name} from the context @var{ctx}. If not +found @code{NULL} is returned. If the returned MPI may later be +modified, it is suggested to pass @code{1} to @var{copy}, so that the +function guarantees that a modifiable copy of the MPI is returned. If + at code{0} is used for @var{copy}, this function may return a constant +flagged MPI. In any case @code{gcry_mpi_release} needs to be called +to release the result. For valid names @ref{ecc_keyparam}. + at end deftypefun + + at deftypefun gcry_mpi_point_t gcry_mpi_ec_get_point ( @ + @w{const char *@var{name}}, @w{gcry_ctx_t @var{ctx}}, @w{int @var{copy}}) + +Return the point with @var{name} from the context @var{ctx}. If not +found @code{NULL} is returned. If the returned MPI may later be +modified, it is suggested to pass @code{1} to @var{copy}, so that the +function guarantees that a modifiable copy of the MPI is returned. If + at code{0} is used for @var{copy}, this function may return a constant +flagged point. In any case @code{gcry_mpi_point_release} needs to be +called to release the result. + at end deftypefun + + at deftypefun gpg_error_t gcry_mpi_ec_set_mpi ( @ + @w{const char *@var{name}}, @w{gcry_mpi_t @var{newvalue}}, @ + @w{gcry_ctx_t @var{ctx}}) + +Store the MPI @var{newvalue} at @var{name} into the context @var{ctx}. +On success @code{0} is returned; on error an error code. Valid names +are the MPI parameters of an elliptic curve (@pxref{ecc_keyparam}). + at end deftypefun + + at deftypefun gpg_error_t gcry_mpi_ec_set_point ( @ + @w{const char *@var{name}}, @w{gcry_mpi_point_t @var{newvalue}}, @ + @w{gcry_ctx_t @var{ctx}}) + +Store the point @var{newvalue} at @var{name} into the context + at var{ctx}. On success @code{0} is returned; on error an error code. +Valid names are the point parameters of an elliptic curve +(@pxref{ecc_keyparam}). @end deftypefun @deftypefun int gcry_mpi_ec_get_affine ( @ @@ -3938,9 +3994,9 @@ and sets @code{errno}. Compute the affine coordinates from the projective coordinates in @var{point} and store them into @var{x} and @var{y}. If one coordinate is not required, @code{NULL} may be passed to @var{x} or - at var{y}. @var{ctx} is the context object which for example may have -been created using @ref{gcry_mpi_ec_p_new}. Returns 0 on success or -not 0 if @var{point} is at infinity. + at var{y}. @var{ctx} is the context object which has been created using + at code{gcry_mpi_ec_new}. Returns 0 on success or not 0 if @var{point} +is at infinity. @end deftypefun @deftypefun void gcry_mpi_ec_dup ( @ diff --git a/mpi/ec.c b/mpi/ec.c index 7f310ea..9a6868b 100644 --- a/mpi/ec.c +++ b/mpi/ec.c @@ -27,37 +27,13 @@ #include "longlong.h" #include "g10lib.h" #include "context.h" +#include "ec-context.h" #define point_init(a) _gcry_mpi_point_init ((a)) #define point_free(a) _gcry_mpi_point_free_parts ((a)) -/* Object to represent a point in projective coordinates. */ -/* Currently defined in mpi.h */ - -/* This context is used with all our EC functions. */ -struct mpi_ec_ctx_s -{ - /* Domain parameters. */ - gcry_mpi_t p; /* Prime specifying the field GF(p). */ - gcry_mpi_t a; /* First coefficient of the Weierstrass equation. */ - - int a_is_pminus3; /* True if A = P - 3. */ - - gcry_mpi_t two_inv_p; - - /* Scratch variables. */ - gcry_mpi_t scratch[11]; - - /* Helper for fast reduction. */ -/* int nist_nbits; /\* If this is a NIST curve, the number of bits. *\/ */ -/* gcry_mpi_t s[10]; */ -/* gcry_mpi_t c; */ - -}; - - /* Create a new point option. NBITS gives the size in bits of one coordinate; it is only used to pre-allocate some resources and might also be passed as 0 to use a default value. */ @@ -116,6 +92,24 @@ point_set (mpi_point_t d, mpi_point_t s) mpi_set (d->z, s->z); } + +/* Return a copy of POINT. */ +static gcry_mpi_point_t +point_copy (gcry_mpi_point_t point) +{ + gcry_mpi_point_t newpoint; + + if (point) + { + newpoint = gcry_mpi_point_new (0); + point_set (newpoint, point); + } + else + newpoint = NULL; + return newpoint; +} + + /* Set the projective coordinates from POINT into X, Y, and Z. If a coordinate is not required, X, Y, or Z may be passed as NULL. */ void @@ -353,27 +347,22 @@ ec_p_init (mpi_ec_t ctx, gcry_mpi_t p, gcry_mpi_t a) int i; gcry_mpi_t tmp; - mpi_normalize (p); - mpi_normalize (a); - - /* Fixme: Do we want to check some constraints? e.g. - a < p - */ + /* Fixme: Do we want to check some constraints? e.g. a < p */ ctx->p = mpi_copy (p); ctx->a = mpi_copy (a); tmp = mpi_alloc_like (ctx->p); mpi_sub_ui (tmp, ctx->p, 3); - ctx->a_is_pminus3 = !mpi_cmp (ctx->a, tmp); + ctx->t.a_is_pminus3 = !mpi_cmp (ctx->a, tmp); mpi_free (tmp); - ctx->two_inv_p = mpi_alloc (0); - ec_invm (ctx->two_inv_p, mpi_const (MPI_C_TWO), ctx); + ctx->t.two_inv_p = mpi_alloc (0); + ec_invm (ctx->t.two_inv_p, mpi_const (MPI_C_TWO), ctx); /* Allocate scratch variables. */ - for (i=0; i< DIM(ctx->scratch); i++) - ctx->scratch[i] = mpi_alloc_like (ctx->p); + for (i=0; i< DIM(ctx->t.scratch); i++) + ctx->t.scratch[i] = mpi_alloc_like (ctx->p); /* Prepare for fast reduction. */ /* FIXME: need a test for NIST values. However it does not gain us @@ -401,13 +390,22 @@ ec_deinit (void *opaque) mpi_ec_t ctx = opaque; int i; + /* Domain parameter. */ mpi_free (ctx->p); mpi_free (ctx->a); + mpi_free (ctx->b); + gcry_mpi_point_release (ctx->G); + mpi_free (ctx->n); + + /* The key. */ + gcry_mpi_point_release (ctx->Q); + mpi_free (ctx->d); - mpi_free (ctx->two_inv_p); + /* Private data of ec.c. */ + mpi_free (ctx->t.two_inv_p); - for (i=0; i< DIM(ctx->scratch); i++) - mpi_free (ctx->scratch[i]); + for (i=0; i< DIM(ctx->t.scratch); i++) + mpi_free (ctx->t.scratch[i]); /* if (ctx->nist_nbits == 192) */ /* { */ @@ -455,28 +453,128 @@ _gcry_mpi_ec_free (mpi_ec_t ctx) /* This function returns a new context for elliptic curve operations based on the field GF(p). P is the prime specifying this field, A - is the first coefficient. This function is part of the public API. - On error this function returns NULL and sets ERRNO. - The context needs to be released using gcry_ctx_release. */ -gcry_ctx_t -gcry_mpi_ec_p_new (gcry_mpi_t p, gcry_mpi_t a) + is the first coefficient. On success the new context is stored at + R_CTX and 0 is returned; on error NULL is stored at R_CTX and an + error code is returned. The context needs to be released using + gcry_ctx_release. This is an internal fucntions. */ +gpg_err_code_t +_gcry_mpi_ec_p_new (gcry_ctx_t *r_ctx, gcry_mpi_t p, gcry_mpi_t a) { gcry_ctx_t ctx; mpi_ec_t ec; + *r_ctx = NULL; if (!p || !a || !mpi_cmp_ui (a, 0)) - { - gpg_err_set_errno (EINVAL); - return NULL; - } + return GPG_ERR_EINVAL; ctx = _gcry_ctx_alloc (CONTEXT_TYPE_EC, sizeof *ec, ec_deinit); if (!ctx) - return NULL; + return gpg_err_code_from_syserror (); ec = _gcry_ctx_get_pointer (ctx, CONTEXT_TYPE_EC); ec_p_init (ec, p, a); - return ctx; + *r_ctx = ctx; + return 0; +} + +gcry_mpi_t +_gcry_mpi_ec_get_mpi (const char *name, gcry_ctx_t ctx, int copy) +{ + mpi_ec_t ec = _gcry_ctx_get_pointer (ctx, CONTEXT_TYPE_EC); + + if (!strcmp (name, "p") && ec->p) + return mpi_is_const (ec->p) && !copy? ec->p : mpi_copy (ec->p); + if (!strcmp (name, "a") && ec->a) + return mpi_is_const (ec->a) && !copy? ec->a : mpi_copy (ec->a); + if (!strcmp (name, "b") && ec->b) + return mpi_is_const (ec->b) && !copy? ec->b : mpi_copy (ec->b); + if (!strcmp (name, "n") && ec->n) + return mpi_is_const (ec->n) && !copy? ec->n : mpi_copy (ec->n); + if (!strcmp (name, "d") && ec->d) + return mpi_is_const (ec->d) && !copy? ec->d : mpi_copy (ec->d); + if (!strcmp (name, "g.x") && ec->G && ec->G->x) + return mpi_is_const (ec->G->x) && !copy? ec->G->x : mpi_copy (ec->G->x); + if (!strcmp (name, "g.y") && ec->G && ec->G->y) + return mpi_is_const (ec->G->y) && !copy? ec->G->y : mpi_copy (ec->G->y); + + return NULL; +} + + +gcry_mpi_point_t +_gcry_mpi_ec_get_point (const char *name, gcry_ctx_t ctx, int copy) +{ + mpi_ec_t ec = _gcry_ctx_get_pointer (ctx, CONTEXT_TYPE_EC); + + (void)copy; /* Not used. */ + + if (!strcmp (name, "g") && ec->G) + return point_copy (ec->G); + if (!strcmp (name, "q") && ec->Q) + return point_copy (ec->Q); + + return NULL; +} + + +gpg_err_code_t +_gcry_mpi_ec_set_mpi (const char *name, gcry_mpi_t newvalue, + gcry_ctx_t ctx) +{ + mpi_ec_t ec = _gcry_ctx_get_pointer (ctx, CONTEXT_TYPE_EC); + + if (!strcmp (name, "p")) + { + mpi_free (ec->p); + ec->p = mpi_copy (newvalue); + } + else if (!strcmp (name, "a")) + { + mpi_free (ec->a); + ec->a = mpi_copy (newvalue); + } + else if (!strcmp (name, "b")) + { + mpi_free (ec->b); + ec->b = mpi_copy (newvalue); + } + else if (!strcmp (name, "n")) + { + mpi_free (ec->n); + ec->n = mpi_copy (newvalue); + } + else if (!strcmp (name, "d")) + { + mpi_free (ec->d); + ec->d = mpi_copy (newvalue); + } + else + return GPG_ERR_UNKNOWN_NAME; + + return 0; +} + + +gpg_err_code_t +_gcry_mpi_ec_set_point (const char *name, gcry_mpi_point_t newvalue, + gcry_ctx_t ctx) +{ + mpi_ec_t ec = _gcry_ctx_get_pointer (ctx, CONTEXT_TYPE_EC); + + if (!strcmp (name, "g")) + { + gcry_mpi_point_release (ec->G); + ec->G = point_copy (newvalue); + } + else if (!strcmp (name, "q")) + { + gcry_mpi_point_release (ec->Q); + ec->Q = point_copy (newvalue); + } + else + return GPG_ERR_UNKNOWN_NAME; + + return 0; } @@ -523,12 +621,12 @@ _gcry_mpi_ec_dup_point (mpi_point_t result, mpi_point_t point, mpi_ec_t ctx) #define x3 (result->x) #define y3 (result->y) #define z3 (result->z) -#define t1 (ctx->scratch[0]) -#define t2 (ctx->scratch[1]) -#define t3 (ctx->scratch[2]) -#define l1 (ctx->scratch[3]) -#define l2 (ctx->scratch[4]) -#define l3 (ctx->scratch[5]) +#define t1 (ctx->t.scratch[0]) +#define t2 (ctx->t.scratch[1]) +#define t3 (ctx->t.scratch[2]) +#define l1 (ctx->t.scratch[3]) +#define l2 (ctx->t.scratch[4]) +#define l3 (ctx->t.scratch[5]) if (!mpi_cmp_ui (point->y, 0) || !mpi_cmp_ui (point->z, 0)) { @@ -539,7 +637,7 @@ _gcry_mpi_ec_dup_point (mpi_point_t result, mpi_point_t point, mpi_ec_t ctx) } else { - if (ctx->a_is_pminus3) /* Use the faster case. */ + if (ctx->t.a_is_pminus3) /* Use the faster case. */ { /* L1 = 3(X - Z^2)(X + Z^2) */ /* T1: used for Z^2. */ @@ -615,17 +713,17 @@ _gcry_mpi_ec_add_points (mpi_point_t result, #define x3 (result->x) #define y3 (result->y) #define z3 (result->z) -#define l1 (ctx->scratch[0]) -#define l2 (ctx->scratch[1]) -#define l3 (ctx->scratch[2]) -#define l4 (ctx->scratch[3]) -#define l5 (ctx->scratch[4]) -#define l6 (ctx->scratch[5]) -#define l7 (ctx->scratch[6]) -#define l8 (ctx->scratch[7]) -#define l9 (ctx->scratch[8]) -#define t1 (ctx->scratch[9]) -#define t2 (ctx->scratch[10]) +#define l1 (ctx->t.scratch[0]) +#define l2 (ctx->t.scratch[1]) +#define l3 (ctx->t.scratch[2]) +#define l4 (ctx->t.scratch[3]) +#define l5 (ctx->t.scratch[4]) +#define l6 (ctx->t.scratch[5]) +#define l7 (ctx->t.scratch[6]) +#define l8 (ctx->t.scratch[7]) +#define l9 (ctx->t.scratch[8]) +#define t1 (ctx->t.scratch[9]) +#define t2 (ctx->t.scratch[10]) if ( (!mpi_cmp (x1, x2)) && (!mpi_cmp (y1, y2)) && (!mpi_cmp (z1, z2)) ) { @@ -715,7 +813,7 @@ _gcry_mpi_ec_add_points (mpi_point_t result, ec_powm (t1, l3, mpi_const (MPI_C_THREE), ctx); /* fixme: Use saved value*/ ec_mulm (t1, t1, l8, ctx); ec_subm (y3, l9, t1, ctx); - ec_mulm (y3, y3, ctx->two_inv_p, ctx); + ec_mulm (y3, y3, ctx->t.two_inv_p, ctx); } } diff --git a/src/Makefile.am b/src/Makefile.am index 1869ad3..713e616 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -60,6 +60,7 @@ libgcrypt_la_SOURCES = g10lib.h visibility.c visibility.h types.h \ stdmem.c stdmem.h secmem.c secmem.h \ mpi.h missing-string.c module.c fips.c \ hmac256.c hmac256.h context.c context.h \ + ec-context.h \ ath.h ath.c EXTRA_libgcrypt_la_SOURCES = hwf-x86.c diff --git a/src/context.c b/src/context.c index ae991c5..2c02c9c 100644 --- a/src/context.c +++ b/src/context.c @@ -86,7 +86,7 @@ _gcry_ctx_alloc (int type, size_t length, void (*deinit)(void*)) void * _gcry_ctx_get_pointer (gcry_ctx_t ctx, int type) { - if (memcmp (ctx->magic, CTX_MAGIC, CTX_MAGIC_LEN)) + if (!ctx || memcmp (ctx->magic, CTX_MAGIC, CTX_MAGIC_LEN)) log_fatal ("bad pointer %p passed to _gcry_ctx_get_pointer\n", ctx); if (ctx->type != type) log_fatal ("wrong context type %d request for context %p of type %d\n", diff --git a/src/ec-context.h b/src/ec-context.h new file mode 100644 index 0000000..88742bf --- /dev/null +++ b/src/ec-context.h @@ -0,0 +1,57 @@ +/* ec-context.h - Private definitions for CONTEXT_TYPE_EC. + * Copyright (C) 2013 g10 Code GmbH + * + * This file is part of Libgcrypt. + * + * Libgcrypt is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser general Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * Libgcrypt is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this program; if not, see . + */ + +#ifndef GCRY_EC_CONTEXT_H +#define GCRY_EC_CONTEXT_H + +/* This context is used with all our EC functions. */ +struct mpi_ec_ctx_s +{ + /* Domain parameters. Note that they may not all be set and if set + the MPIs may be flaged as constant.*/ + gcry_mpi_t p; /* Prime specifying the field GF(p). */ + gcry_mpi_t a; /* First coefficient of the Weierstrass equation. */ + gcry_mpi_t b; /* Second coefficient of the Weierstrass equation. */ + gcry_mpi_point_t G; /* Base point (generator). */ + gcry_mpi_t n; /* Order of G. */ + + /* The actual key. May not be set. */ + gcry_mpi_point_t Q; /* Public key. */ + gcry_mpi_t d; /* Private key. */ + + + /* This structure is private to mpi/ec.c! */ + struct { + int a_is_pminus3; /* True if A = P - 3. */ + + gcry_mpi_t two_inv_p; + + /* Scratch variables. */ + gcry_mpi_t scratch[11]; + + /* Helper for fast reduction. */ + /* int nist_nbits; /\* If this is a NIST curve, the # of bits. *\/ */ + /* gcry_mpi_t s[10]; */ + /* gcry_mpi_t c; */ + } t; +}; + + + +#endif /*GCRY_EC_CONTEXT_H*/ diff --git a/src/gcrypt.h.in b/src/gcrypt.h.in index eb9a11d..ad4da04 100644 --- a/src/gcrypt.h.in +++ b/src/gcrypt.h.in @@ -606,9 +606,24 @@ gcry_mpi_point_t gcry_mpi_point_snatch_set (gcry_mpi_point_t point, gcry_mpi_t z); /* Allocate a new context for elliptic curve operations based on the - field GF(p). P is the prime specifying this field, A is the first - coefficient. Returns NULL on error. */ -gcry_ctx_t gcry_mpi_ec_p_new (gcry_mpi_t p, gcry_mpi_t a); + parameters given by KEYPARAM or using CURVENAME. */ +gpg_error_t gcry_mpi_ec_new (gcry_ctx_t *r_ctx, + gcry_sexp_t keyparam, const char *curvename); + +/* Get a named MPI from an elliptic curve context. */ +gcry_mpi_t gcry_mpi_ec_get_mpi (const char *name, gcry_ctx_t ctx, int copy); + +/* Get a named point from an elliptic curve context. */ +gcry_mpi_point_t gcry_mpi_ec_get_point (const char *name, + gcry_ctx_t ctx, int copy); + +/* Store a named MPI into an elliptic curve context. */ +gpg_error_t gcry_mpi_ec_set_mpi (const char *name, gcry_mpi_t newvalue, + gcry_ctx_t ctx); + +/* Store a named point into an elliptic curve context. */ +gpg_error_t gcry_mpi_ec_set_point (const char *name, gcry_mpi_point_t newvalue, + gcry_ctx_t ctx); /* Store the affine coordinates of POINT into X and Y. */ int gcry_mpi_ec_get_affine (gcry_mpi_t x, gcry_mpi_t y, gcry_mpi_point_t point, diff --git a/src/libgcrypt.def b/src/libgcrypt.def index 611f10f..061c7e3 100644 --- a/src/libgcrypt.def +++ b/src/libgcrypt.def @@ -223,8 +223,12 @@ EXPORTS gcry_ctx_release @202 - gcry_mpi_ec_p_new @203 - gcry_mpi_ec_get_affine @204 - gcry_mpi_ec_dup @205 - gcry_mpi_ec_add @206 - gcry_mpi_ec_mul @207 + gcry_mpi_ec_new @203 + gcry_mpi_ec_get_mpi @204 + gcry_mpi_ec_get_point @205 + gcry_mpi_ec_set_mpi @206 + gcry_mpi_ec_set_point @207 + gcry_mpi_ec_get_affine @208 + gcry_mpi_ec_dup @209 + gcry_mpi_ec_add @210 + gcry_mpi_ec_mul @211 diff --git a/src/libgcrypt.vers b/src/libgcrypt.vers index 4a375b2..65959d3 100644 --- a/src/libgcrypt.vers +++ b/src/libgcrypt.vers @@ -90,7 +90,9 @@ GCRYPT_1.6 { gcry_mpi_point_new; gcry_mpi_point_release; gcry_mpi_point_get; gcry_mpi_point_snatch_get; gcry_mpi_point_set; gcry_mpi_point_snatch_set; - gcry_mpi_ec_p_new; + gcry_mpi_ec_new; + gcry_mpi_ec_get_mpi; gcry_mpi_ec_get_point; + gcry_mpi_ec_set_mpi; gcry_mpi_ec_set_point; gcry_mpi_ec_get_affine; gcry_mpi_ec_dup; gcry_mpi_ec_add; gcry_mpi_ec_mul; diff --git a/src/mpi.h b/src/mpi.h index 9c22141..b727d5f 100644 --- a/src/mpi.h +++ b/src/mpi.h @@ -289,6 +289,19 @@ void _gcry_mpi_ec_mul_point (mpi_point_t result, gcry_mpi_t scalar, mpi_point_t point, mpi_ec_t ctx); +gpg_err_code_t _gcry_mpi_ec_p_new (gcry_ctx_t *r_ctx, + gcry_mpi_t p, gcry_mpi_t a); +gpg_err_code_t _gcry_mpi_ec_new (gcry_ctx_t *r_ctx, + gcry_sexp_t keyparam, const char *curvename); +gcry_mpi_t _gcry_mpi_ec_get_mpi (const char *name, gcry_ctx_t ctx, int copy); +gcry_mpi_point_t _gcry_mpi_ec_get_point (const char *name, + gcry_ctx_t ctx, int copy); +gpg_err_code_t _gcry_mpi_ec_set_mpi (const char *name, gcry_mpi_t newvalue, + gcry_ctx_t ctx); +gpg_err_code_t _gcry_mpi_ec_set_point (const char *name, + gcry_mpi_point_t newvalue, + gcry_ctx_t ctx); + #endif /*G10_MPI_H*/ diff --git a/src/visibility.c b/src/visibility.c index 5c3216d..ed68b86 100644 --- a/src/visibility.c +++ b/src/visibility.c @@ -461,10 +461,36 @@ gcry_mpi_point_snatch_set (gcry_mpi_point_t point, return _gcry_mpi_point_snatch_set (point, x, y, z); } -gcry_ctx_t -gcry_mpi_ec_p_new (gcry_mpi_t p, gcry_mpi_t a) +gpg_error_t +gcry_mpi_ec_new (gcry_ctx_t *r_ctx, + gcry_sexp_t keyparam, const char *curvename) +{ + return gpg_error (_gcry_mpi_ec_new (r_ctx, keyparam, curvename)); +} + +gcry_mpi_t +gcry_mpi_ec_get_mpi (const char *name, gcry_ctx_t ctx, int copy) +{ + return _gcry_mpi_ec_get_mpi (name, ctx, copy); +} + +gcry_mpi_point_t +gcry_mpi_ec_get_point (const char *name, gcry_ctx_t ctx, int copy) +{ + return _gcry_mpi_ec_get_point (name, ctx, copy); +} + +gpg_error_t +gcry_mpi_ec_set_mpi (const char *name, gcry_mpi_t newvalue, gcry_ctx_t ctx) +{ + return gpg_error (_gcry_mpi_ec_set_mpi (name, newvalue, ctx)); +} + +gpg_error_t +gcry_mpi_ec_set_point (const char *name, gcry_mpi_point_t newvalue, + gcry_ctx_t ctx) { - return _gcry_mpi_ec_p_new (p, a); + return gpg_error (_gcry_mpi_ec_set_point (name, newvalue, ctx)); } int diff --git a/src/visibility.h b/src/visibility.h index 90c6ad1..031537a 100644 --- a/src/visibility.h +++ b/src/visibility.h @@ -154,7 +154,6 @@ #define gcry_mpi_copy _gcry_mpi_copy #define gcry_mpi_div _gcry_mpi_div #define gcry_mpi_dump _gcry_mpi_dump -#define gcry_mpi_ec_p_new _gcry_mpi_ec_p_new #define gcry_mpi_gcd _gcry_mpi_gcd #define gcry_mpi_get_flag _gcry_mpi_get_flag #define gcry_mpi_get_nbits _gcry_mpi_get_nbits @@ -370,7 +369,6 @@ gcry_err_code_t gcry_md_get (gcry_md_hd_t hd, int algo, #undef gcry_mpi_copy #undef gcry_mpi_div #undef gcry_mpi_dump -#undef gcry_mpi_ec_p_new #undef gcry_mpi_gcd #undef gcry_mpi_get_flag #undef gcry_mpi_get_nbits @@ -550,7 +548,11 @@ MARK_VISIBLEX(gcry_mpi_ec_add) MARK_VISIBLEX(gcry_mpi_ec_dup) MARK_VISIBLEX(gcry_mpi_ec_get_affine) MARK_VISIBLEX(gcry_mpi_ec_mul) -MARK_VISIBLE (gcry_mpi_ec_p_new) +MARK_VISIBLEX(gcry_mpi_ec_new) +MARK_VISIBLEX(gcry_mpi_ec_get_mpi) +MARK_VISIBLEX(gcry_mpi_ec_get_point) +MARK_VISIBLEX(gcry_mpi_ec_set_mpi) +MARK_VISIBLEX(gcry_mpi_ec_set_point) MARK_VISIBLE (gcry_mpi_gcd) MARK_VISIBLE (gcry_mpi_get_flag) MARK_VISIBLE (gcry_mpi_get_nbits) diff --git a/tests/t-mpi-point.c b/tests/t-mpi-point.c index 8714d38..31df12b 100644 --- a/tests/t-mpi-point.c +++ b/tests/t-mpi-point.c @@ -41,6 +41,84 @@ static int error_count; #define xfree(a) gcry_free ((a)) #define pass() do { ; } while (0) + +static struct +{ + const char *desc; /* Description of the curve. */ + const char *p; /* Order of the prime field. */ + const char *a, *b; /* The coefficients. */ + const char *n; /* The order of the base point. */ + const char *g_x, *g_y; /* Base point. */ +} test_curve[] = + { + { + "NIST P-192", + "0xfffffffffffffffffffffffffffffffeffffffffffffffff", + "0xfffffffffffffffffffffffffffffffefffffffffffffffc", + "0x64210519e59c80e70fa7e9ab72243049feb8deecc146b9b1", + "0xffffffffffffffffffffffff99def836146bc9b1b4d22831", + + "0x188da80eb03090f67cbf20eb43a18800f4ff0afd82ff1012", + "0x07192b95ffc8da78631011ed6b24cdd573f977a11e794811" + }, + { + "NIST P-224", + "0xffffffffffffffffffffffffffffffff000000000000000000000001", + "0xfffffffffffffffffffffffffffffffefffffffffffffffffffffffe", + "0xb4050a850c04b3abf54132565044b0b7d7bfd8ba270b39432355ffb4", + "0xffffffffffffffffffffffffffff16a2e0b8f03e13dd29455c5c2a3d" , + + "0xb70e0cbd6bb4bf7f321390b94a03c1d356c21122343280d6115c1d21", + "0xbd376388b5f723fb4c22dfe6cd4375a05a07476444d5819985007e34" + }, + { + "NIST P-256", + "0xffffffff00000001000000000000000000000000ffffffffffffffffffffffff", + "0xffffffff00000001000000000000000000000000fffffffffffffffffffffffc", + "0x5ac635d8aa3a93e7b3ebbd55769886bc651d06b0cc53b0f63bce3c3e27d2604b", + "0xffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551", + + "0x6b17d1f2e12c4247f8bce6e563a440f277037d812deb33a0f4a13945d898c296", + "0x4fe342e2fe1a7f9b8ee7eb4a7c0f9e162bce33576b315ececbb6406837bf51f5" + }, + { + "NIST P-384", + "0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe" + "ffffffff0000000000000000ffffffff", + "0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe" + "ffffffff0000000000000000fffffffc", + "0xb3312fa7e23ee7e4988e056be3f82d19181d9c6efe8141120314088f5013875a" + "c656398d8a2ed19d2a85c8edd3ec2aef", + "0xffffffffffffffffffffffffffffffffffffffffffffffffc7634d81f4372ddf" + "581a0db248b0a77aecec196accc52973", + + "0xaa87ca22be8b05378eb1c71ef320ad746e1d3b628ba79b9859f741e082542a38" + "5502f25dbf55296c3a545e3872760ab7", + "0x3617de4a96262c6f5d9e98bf9292dc29f8f41dbd289a147ce9da3113b5f0b8c0" + "0a60b1ce1d7e819d7a431d7c90ea0e5f" + }, + { + "NIST P-521", + "0x01ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" + "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", + "0x01ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" + "fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc", + "0x051953eb9618e1c9a1f929a21a0b68540eea2da725b99b315f3b8b489918ef10" + "9e156193951ec7e937b1652c0bd3bb1bf073573df883d2c34f1ef451fd46b503f00", + "0x1fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" + "ffa51868783bf2f966b7fcc0148f709a5d03bb5c9b8899c47aebb6fb71e91386409", + + "0xc6858e06b70404e9cd9e3ecb662395b4429c648139053fb521f828af606b4d3d" + "baa14b5e77efe75928fe1dc127a2ffa8de3348b3c1856a429bf97e7e31c2e5bd66", + "0x11839296a789a3bc0045c8a5fb42c7d1bd998f54449579b446817afbd17273e6" + "62c97ee72995ef42640c550b9013fad0761353c7086a272c24088be94769fd16650" + }, + { NULL, NULL, NULL, NULL, NULL } + }; + + + + static void show (const char *format, ...) { @@ -131,6 +209,30 @@ cmp_mpihex (gcry_mpi_t a, const char *b) } +/* Wrapper to emulate the libgcrypt internal EC context allocation + function. */ +static gpg_error_t +ec_p_new (gcry_ctx_t *r_ctx, gcry_mpi_t p, gcry_mpi_t a) +{ + gpg_error_t err; + gcry_sexp_t sexp; + + if (p && a) + err = gcry_sexp_build (&sexp, NULL, "(ecdsa (p %m)(a %m))", p, a); + else if (p) + err = gcry_sexp_build (&sexp, NULL, "(ecdsa (p %m))", p); + else if (a) + err = gcry_sexp_build (&sexp, NULL, "(ecdsa (a %m))", a); + else + err = gcry_sexp_build (&sexp, NULL, "(ecdsa)"); + if (err) + return err; + err = gcry_mpi_ec_new (r_ctx, sexp, NULL); + gcry_sexp_release (sexp); + return err; +} + + static void set_get_point (void) @@ -189,6 +291,7 @@ set_get_point (void) static void context_alloc (void) { + gpg_error_t err; gcry_ctx_t ctx; gcry_mpi_t p, a; @@ -197,40 +300,153 @@ context_alloc (void) p = gcry_mpi_set_ui (NULL, 1); a = gcry_mpi_set_ui (NULL, 1); - ctx = gcry_mpi_ec_p_new (p, a); - if (!ctx) - die ("gcry_mpi_ec_p_new returned an error: %s\n", - gpg_strerror (gpg_error_from_syserror ())); + err = ec_p_new (&ctx, p, a); + if (err) + die ("ec_p_new returned an error: %s\n", gpg_strerror (err)); gcry_mpi_release (p); gcry_mpi_release (a); gcry_ctx_release (ctx); p = gcry_mpi_set_ui (NULL, 0); a = gcry_mpi_set_ui (NULL, 0); - ctx = gcry_mpi_ec_p_new (p, a); - if (ctx || gpg_err_code_from_syserror () != GPG_ERR_EINVAL) - fail ("gcry_mpi_ec_p_new: bad parameter detection failed (1)\n"); + err = ec_p_new (&ctx, p, a); + if (!err || gpg_err_code (err) != GPG_ERR_EINVAL) + fail ("ec_p_new: bad parameter detection failed (1)\n"); gcry_mpi_set_ui (p, 1); - ctx = gcry_mpi_ec_p_new (p, a); - if (ctx || gpg_err_code_from_syserror () != GPG_ERR_EINVAL) - fail ("gcry_mpi_ec_p_new: bad parameter detection failed (2)\n"); + err = ec_p_new (&ctx, p, a); + if (!err || gpg_err_code (err) != GPG_ERR_EINVAL) + fail ("ec_p_new: bad parameter detection failed (2)\n"); gcry_mpi_release (p); p = NULL; - ctx = gcry_mpi_ec_p_new (p, a); - if (ctx || gpg_err_code_from_syserror () != GPG_ERR_EINVAL) - fail ("gcry_mpi_ec_p_new: bad parameter detection failed (3)\n"); + err = ec_p_new (&ctx, p, a); + if (!err || gpg_err_code (err) != GPG_ERR_EINVAL) + fail ("ec_p_new: bad parameter detection failed (3)\n"); gcry_mpi_release (a); a = NULL; - ctx = gcry_mpi_ec_p_new (p, a); - if (ctx || gpg_err_code_from_syserror () != GPG_ERR_EINVAL) - fail ("gcry_mpi_ec_p_new: bad parameter detection failed (4)\n"); + err = ec_p_new (&ctx, p, a); + if (!err || gpg_err_code (err) != GPG_ERR_EINVAL) + fail ("ec_p_new: bad parameter detection failed (4)\n"); + +} + + +static int +get_and_cmp_mpi (const char *name, const char *mpistring, const char *desc, + gcry_ctx_t ctx) +{ + gcry_mpi_t mpi; + + mpi = gcry_mpi_ec_get_mpi (name, ctx, 1); + if (!mpi) + { + fail ("error getting parameter '%s' of curve '%s'\n", name, desc); + return 1; + } + if (cmp_mpihex (mpi, mpistring)) + { + fail ("parameter '%s' of curve '%s' does not match\n", name, desc); + gcry_mpi_release (mpi); + return 1; + } + gcry_mpi_release (mpi); + return 0; +} + + +static int +get_and_cmp_point (const char *name, + const char *mpi_x_string, const char *mpi_y_string, + const char *desc, gcry_ctx_t ctx) +{ + gcry_mpi_point_t point; + gcry_mpi_t x, y, z; + int result = 0; + + point = gcry_mpi_ec_get_point (name, ctx, 1); + if (!point) + { + fail ("error getting point parameter '%s' of curve '%s'\n", name, desc); + return 1; + } + + x = gcry_mpi_new (0); + y = gcry_mpi_new (0); + z = gcry_mpi_new (0); + gcry_mpi_point_snatch_get (x, y, z, point); + if (cmp_mpihex (x, mpi_x_string)) + { + fail ("x coordinate of '%s' of curve '%s' does not match\n", name, desc); + result = 1; + } + if (cmp_mpihex (y, mpi_y_string)) + { + fail ("y coordinate of '%s' of curve '%s' does not match\n", name, desc); + result = 1; + } + if (cmp_mpihex (z, "01")) + { + fail ("z coordinate of '%s' of curve '%s' is not 1\n", name, desc); + result = 1; + } + gcry_mpi_release (x); + gcry_mpi_release (y); + gcry_mpi_release (z); + return result; +} + + +static void +context_param (void) +{ + gpg_error_t err; + int idx; + gcry_ctx_t ctx = NULL; + + wherestr = "context_param"; + + for (idx=0; test_curve[idx].desc; idx++) + { + show ("checking curve '%s'\n", test_curve[idx].desc); + gcry_ctx_release (ctx); + err = gcry_mpi_ec_new (&ctx, NULL, test_curve[idx].desc); + if (err) + { + fail ("can't create context for curve '%s': %s\n", + test_curve[idx].desc, gpg_strerror (err)); + continue; + } + if (get_and_cmp_mpi ("p", test_curve[idx].p, test_curve[idx].desc, ctx)) + continue; + if (get_and_cmp_mpi ("a", test_curve[idx].a, test_curve[idx].desc, ctx)) + continue; + if (get_and_cmp_mpi ("b", test_curve[idx].b, test_curve[idx].desc, ctx)) + continue; + if (get_and_cmp_mpi ("g.x",test_curve[idx].g_x, test_curve[idx].desc,ctx)) + continue; + if (get_and_cmp_mpi ("g.y",test_curve[idx].g_y, test_curve[idx].desc,ctx)) + continue; + if (get_and_cmp_mpi ("n", test_curve[idx].n, test_curve[idx].desc, ctx)) + continue; + if (get_and_cmp_point ("g", test_curve[idx].g_x, test_curve[idx].g_y, + test_curve[idx].desc, ctx)) + continue; + + } + gcry_ctx_release (ctx); + + /* FIXME: Add tests for Q and d. */ + + /* FIXME: Add test sor the set functions. */ + } + + /* Create a new point from (X,Y,Z) given as hex strings. */ gcry_mpi_point_t make_point (const char *x, const char *y, const char *z) @@ -244,9 +460,13 @@ make_point (const char *x, const char *y, const char *z) } +/* This tests checks that the low-level EC API yields the same result + as using the high level API. The values have been taken from a + test run using the high level API. */ static void basic_ec_math (void) { + gpg_error_t err; gcry_ctx_t ctx; gcry_mpi_t P, A; gcry_mpi_point_t G, Q; @@ -264,7 +484,9 @@ basic_ec_math (void) d = hex2mpi ("D4EF27E32F8AD8E2A1C6DDEBB1D235A69E3CEF9BCE90273D"); Q = gcry_mpi_point_new (0); - ctx = gcry_mpi_ec_p_new (P, A); + err = ec_p_new (&ctx, P, A); + if (err) + die ("ec_p_new failed: %s\n", gpg_strerror (err)); gcry_mpi_ec_mul (Q, d, G, ctx); x = gcry_mpi_new (0); @@ -304,6 +526,66 @@ basic_ec_math (void) } +/* This is the same as basic_ec_math but uses more advanced + features. */ +static void +basic_ec_math_simplified (void) +{ + gpg_error_t err; + gcry_ctx_t ctx; + gcry_mpi_point_t G, Q; + gcry_mpi_t d; + gcry_mpi_t x, y, z; + + wherestr = "set_get_point"; + show ("checking basic math functions for EC (variant)\n"); + + d = hex2mpi ("D4EF27E32F8AD8E2A1C6DDEBB1D235A69E3CEF9BCE90273D"); + Q = gcry_mpi_point_new (0); + + err = gcry_mpi_ec_new (&ctx, NULL, "NIST P-192"); + if (err) + die ("gcry_mpi_ec_new failed: %s\n", gpg_strerror (err)); + G = gcry_mpi_ec_get_point ("g", ctx, 1); + if (!G) + die ("gcry_mpi_ec_get_point(G) failed\n"); + gcry_mpi_ec_mul (Q, d, G, ctx); + + x = gcry_mpi_new (0); + y = gcry_mpi_new (0); + z = gcry_mpi_new (0); + gcry_mpi_point_get (x, y, z, Q); + if (cmp_mpihex (x, "222D9EC717C89D047E0898C9185B033CD11C0A981EE6DC66") + || cmp_mpihex (y, "605DE0A82D70D3E0F84A127D0739ED33D657DF0D054BFDE8") + || cmp_mpihex (z, "00B06B519071BC536999AC8F2D3934B3C1FC9EACCD0A31F88F")) + fail ("computed public key does not match\n"); + if (debug) + { + print_mpi ("Q.x", x); + print_mpi ("Q.y", y); + print_mpi ("Q.z", z); + } + + if (gcry_mpi_ec_get_affine (x, y, Q, ctx)) + fail ("failed to get affine coordinates\n"); + if (cmp_mpihex (x, "008532093BA023F4D55C0424FA3AF9367E05F309DC34CDC3FE") + || cmp_mpihex (y, "00C13CA9E617C6C8487BFF6A726E3C4F277913D97117939966")) + fail ("computed affine coordinates of public key do not match\n"); + if (debug) + { + print_mpi ("q.x", x); + print_mpi ("q.y", y); + } + + gcry_mpi_release (z); + gcry_mpi_release (y); + gcry_mpi_release (x); + gcry_mpi_point_release (Q); + gcry_mpi_release (d); + gcry_mpi_point_release (G); +} + + int main (int argc, char **argv) { @@ -324,7 +606,9 @@ main (int argc, char **argv) set_get_point (); context_alloc (); + context_param (); basic_ec_math (); + basic_ec_math_simplified (); show ("All tests completed. Errors: %d\n", error_count); return error_count ? 1 : 0; commit e005629bd7bebb3e13945645c6e1230b44ab16a2 Author: Werner Koch Date: Wed Mar 13 15:08:33 2013 +0100 Add GCRYMPI_FLAG_CONST and make use constants. * src/gcrypt.h.in (GCRYMPI_FLAG_CONST): New. * src/mpi.h (mpi_is_const, mpi_const): New. (enum gcry_mpi_constants, MPI_NUMBER_OF_CONSTANTS): New. * mpi/mpiutil.c (_gcry_mpi_init): New. (constants): New. (_gcry_mpi_free): Do not release a constant flagged MPI. (gcry_mpi_copy): Clear the const and immutable flags. (gcry_mpi_set_flag, gcry_mpi_clear_flag, gcry_mpi_get_flag): Support GCRYMPI_FLAG_CONST. (_gcry_mpi_const): New. * src/global.c (global_init): Call _gcry_mpi_init. * mpi/ec.c (mpi_ec_ctx_s): Remove fields one, two, three, four, and eight. Change all users to call mpi_const() instead. * src/mpiutils.c (gcry_mpi_set_opaque): Check the immutable flag. -- Allocating the trivial constants newly for every EC context is a waste of memory and cpu cycles. We instead provide a simple mechanism to internally support such constants. Using a new flag in THE API also allows to mark an arbitrary MPI as constant. The drawback of the constants is the their memory will never be deallocated. However, that is what constants are about. diff --git a/NEWS b/NEWS index 3a4ca4c..c0a7e8e 100644 --- a/NEWS +++ b/NEWS @@ -51,6 +51,7 @@ Noteworthy changes in version 1.6.0 (unreleased) gcry_mpi_ec_add NEW. gcry_mpi_ec_mul NEW. GCRYMPI_FLAG_IMMUTABLE NEW. + GCRYMPI_FLAG_CONST NEW. Noteworthy changes in version 1.5.0 (2011-06-29) diff --git a/doc/gcrypt.texi b/doc/gcrypt.texi index bfc825d..a56d527 100644 --- a/doc/gcrypt.texi +++ b/doc/gcrypt.texi @@ -3571,7 +3571,8 @@ confidential data like private key parameters. @deftypefun gcry_mpi_t gcry_mpi_copy (@w{const gcry_mpi_t @var{a}}) -Create a new MPI as the exact copy of @var{a}. +Create a new MPI as the exact copy of @var{a} but with the constant +and immutable flags cleared. @end deftypefun @@ -4008,20 +4009,29 @@ cleared. If this flag is set, the MPI is marked as immutable. Setting or changing the value of that MPI is ignored and an error message is logged. The flag is sometimes useful for debugging. + at item GCRYMPI_FLAG_CONST +If this flag is set, the MPI is marked as a constant and as immutable +Setting or changing the value of that MPI is ignored and an error +message is logged. Such an MPI will never be deallocated and may thus +be used without copying. Note that using gcry_mpi_copy will return a +copy of that constant with this and the immutable flag cleared. @end table @deftypefun void gcry_mpi_set_flag (@w{gcry_mpi_t @var{a}}, @ @w{enum gcry_mpi_flag @var{flag}}) Set the @var{flag} for the MPI @var{a}. The only allowed flags are - at code{GCRYMPI_FLAG_SECURE} and @code{GCRYMPI_FLAG_IMMUTABLE}. + at code{GCRYMPI_FLAG_SECURE}, @code{GCRYMPI_FLAG_IMMUTABLE}, and + at code{GCRYMPI_FLAG_CONST}. @end deftypefun @deftypefun void gcry_mpi_clear_flag (@w{gcry_mpi_t @var{a}}, @ @w{enum gcry_mpi_flag @var{flag}}) Clear @var{flag} for the multi-precision-integers @var{a}. The only -allowed flag is @code{GCRYMPI_FLAG_IMMUTABLE}. +allowed flag is @code{GCRYMPI_FLAG_IMMUTABLE} but only if + at code{GCRYMPI_FLAG_CONST} is not set. If @code{GCRYMPI_FLAG_CONST} is +set, clearing @code{GCRYMPI_FLAG_IMMUTABLE} will simply be ignored. @end deftypefun o @deftypefun int gcry_mpi_get_flag (@w{gcry_mpi_t @var{a}}, @ diff --git a/mpi/ec.c b/mpi/ec.c index e85ec04..7f310ea 100644 --- a/mpi/ec.c +++ b/mpi/ec.c @@ -45,12 +45,6 @@ struct mpi_ec_ctx_s int a_is_pminus3; /* True if A = P - 3. */ - /* Some often used constants. */ - gcry_mpi_t one; - gcry_mpi_t two; - gcry_mpi_t three; - gcry_mpi_t four; - gcry_mpi_t eight; gcry_mpi_t two_inv_p; /* Scratch variables. */ @@ -374,15 +368,8 @@ ec_p_init (mpi_ec_t ctx, gcry_mpi_t p, gcry_mpi_t a) ctx->a_is_pminus3 = !mpi_cmp (ctx->a, tmp); mpi_free (tmp); - - /* Allocate constants. */ - ctx->one = mpi_alloc_set_ui (1); - ctx->two = mpi_alloc_set_ui (2); - ctx->three = mpi_alloc_set_ui (3); - ctx->four = mpi_alloc_set_ui (4); - ctx->eight = mpi_alloc_set_ui (8); ctx->two_inv_p = mpi_alloc (0); - ec_invm (ctx->two_inv_p, ctx->two, ctx); + ec_invm (ctx->two_inv_p, mpi_const (MPI_C_TWO), ctx); /* Allocate scratch variables. */ for (i=0; i< DIM(ctx->scratch); i++) @@ -417,12 +404,6 @@ ec_deinit (void *opaque) mpi_free (ctx->p); mpi_free (ctx->a); - mpi_free (ctx->one); - mpi_free (ctx->two); - mpi_free (ctx->three); - mpi_free (ctx->four); - mpi_free (ctx->eight); - mpi_free (ctx->two_inv_p); for (i=0; i< DIM(ctx->scratch); i++) @@ -563,9 +544,9 @@ _gcry_mpi_ec_dup_point (mpi_point_t result, mpi_point_t point, mpi_ec_t ctx) /* L1 = 3(X - Z^2)(X + Z^2) */ /* T1: used for Z^2. */ /* T2: used for the right term. */ - ec_powm (t1, point->z, ctx->two, ctx); + ec_powm (t1, point->z, mpi_const (MPI_C_TWO), ctx); ec_subm (l1, point->x, t1, ctx); - ec_mulm (l1, l1, ctx->three, ctx); + ec_mulm (l1, l1, mpi_const (MPI_C_THREE), ctx); ec_addm (t2, point->x, t1, ctx); ec_mulm (l1, l1, t2, ctx); } @@ -573,32 +554,32 @@ _gcry_mpi_ec_dup_point (mpi_point_t result, mpi_point_t point, mpi_ec_t ctx) { /* L1 = 3X^2 + aZ^4 */ /* T1: used for aZ^4. */ - ec_powm (l1, point->x, ctx->two, ctx); - ec_mulm (l1, l1, ctx->three, ctx); - ec_powm (t1, point->z, ctx->four, ctx); + ec_powm (l1, point->x, mpi_const (MPI_C_TWO), ctx); + ec_mulm (l1, l1, mpi_const (MPI_C_THREE), ctx); + ec_powm (t1, point->z, mpi_const (MPI_C_FOUR), ctx); ec_mulm (t1, t1, ctx->a, ctx); ec_addm (l1, l1, t1, ctx); } /* Z3 = 2YZ */ ec_mulm (z3, point->y, point->z, ctx); - ec_mulm (z3, z3, ctx->two, ctx); + ec_mulm (z3, z3, mpi_const (MPI_C_TWO), ctx); /* L2 = 4XY^2 */ /* T2: used for Y2; required later. */ - ec_powm (t2, point->y, ctx->two, ctx); + ec_powm (t2, point->y, mpi_const (MPI_C_TWO), ctx); ec_mulm (l2, t2, point->x, ctx); - ec_mulm (l2, l2, ctx->four, ctx); + ec_mulm (l2, l2, mpi_const (MPI_C_FOUR), ctx); /* X3 = L1^2 - 2L2 */ /* T1: used for L2^2. */ - ec_powm (x3, l1, ctx->two, ctx); - ec_mulm (t1, l2, ctx->two, ctx); + ec_powm (x3, l1, mpi_const (MPI_C_TWO), ctx); + ec_mulm (t1, l2, mpi_const (MPI_C_TWO), ctx); ec_subm (x3, x3, t1, ctx); /* L3 = 8Y^4 */ /* T2: taken from above. */ - ec_powm (t2, t2, ctx->two, ctx); - ec_mulm (l3, t2, ctx->eight, ctx); + ec_powm (t2, t2, mpi_const (MPI_C_TWO), ctx); + ec_mulm (l3, t2, mpi_const (MPI_C_EIGHT), ctx); /* Y3 = L1(L2 - X3) - L3 */ ec_subm (y3, l2, x3, ctx); @@ -676,23 +657,23 @@ _gcry_mpi_ec_add_points (mpi_point_t result, mpi_set (l1, x1); else { - ec_powm (l1, z2, ctx->two, ctx); + ec_powm (l1, z2, mpi_const (MPI_C_TWO), ctx); ec_mulm (l1, l1, x1, ctx); } if (z1_is_one) mpi_set (l2, x1); else { - ec_powm (l2, z1, ctx->two, ctx); + ec_powm (l2, z1, mpi_const (MPI_C_TWO), ctx); ec_mulm (l2, l2, x2, ctx); } /* l3 = l1 - l2 */ ec_subm (l3, l1, l2, ctx); /* l4 = y1 z2^3 */ - ec_powm (l4, z2, ctx->three, ctx); + ec_powm (l4, z2, mpi_const (MPI_C_THREE), ctx); ec_mulm (l4, l4, y1, ctx); /* l5 = y2 z1^3 */ - ec_powm (l5, z1, ctx->three, ctx); + ec_powm (l5, z1, mpi_const (MPI_C_THREE), ctx); ec_mulm (l5, l5, y2, ctx); /* l6 = l4 - l5 */ ec_subm (l6, l4, l5, ctx); @@ -722,16 +703,16 @@ _gcry_mpi_ec_add_points (mpi_point_t result, ec_mulm (z3, z1, z2, ctx); ec_mulm (z3, z3, l3, ctx); /* x3 = l6^2 - l7 l3^2 */ - ec_powm (t1, l6, ctx->two, ctx); - ec_powm (t2, l3, ctx->two, ctx); + ec_powm (t1, l6, mpi_const (MPI_C_TWO), ctx); + ec_powm (t2, l3, mpi_const (MPI_C_TWO), ctx); ec_mulm (t2, t2, l7, ctx); ec_subm (x3, t1, t2, ctx); /* l9 = l7 l3^2 - 2 x3 */ - ec_mulm (t1, x3, ctx->two, ctx); + ec_mulm (t1, x3, mpi_const (MPI_C_TWO), ctx); ec_subm (l9, t2, t1, ctx); /* y3 = (l9 l6 - l8 l3^3)/2 */ ec_mulm (l9, l9, l6, ctx); - ec_powm (t1, l3, ctx->three, ctx); /* fixme: Use saved value*/ + ec_powm (t1, l3, mpi_const (MPI_C_THREE), ctx); /* fixme: Use saved value*/ ec_mulm (t1, t1, l8, ctx); ec_subm (y3, l9, t1, ctx); ec_mulm (y3, y3, ctx->two_inv_p, ctx); @@ -824,9 +805,9 @@ _gcry_mpi_ec_mul_point (mpi_point_t result, mpi_free (z2); mpi_free (z3); } - z1 = mpi_copy (ctx->one); + z1 = mpi_copy (mpi_const (MPI_C_ONE)); - mpi_mul (h, k, ctx->three); /* h = 3k */ + mpi_mul (h, k, mpi_const (MPI_C_THREE)); /* h = 3k */ loops = mpi_get_nbits (h); mpi_set (result->x, point->x); diff --git a/mpi/mpiutil.c b/mpi/mpiutil.c index 64a2f7e..cff15b7 100644 --- a/mpi/mpiutil.c +++ b/mpi/mpiutil.c @@ -28,6 +28,10 @@ #include "mpi-internal.h" #include "mod-source-info.h" +/* Constatns allocated right away at strtartup. */ +static gcry_mpi_t constants[MPI_NUMBER_OF_CONSTANTS]; + + const char * _gcry_mpi_get_hw_config (void) @@ -36,6 +40,34 @@ _gcry_mpi_get_hw_config (void) } +/* Initialize the MPI subsystem. This is called early and allows to + do some initialization without taking care of threading issues. */ +gcry_err_code_t +_gcry_mpi_init (void) +{ + int idx; + unsigned long value; + + for (idx=0; idx < MPI_NUMBER_OF_CONSTANTS; idx++) + { + switch (idx) + { + case MPI_C_ZERO: value = 0; break; + case MPI_C_ONE: value = 1; break; + case MPI_C_TWO: value = 2; break; + case MPI_C_THREE: value = 3; break; + case MPI_C_FOUR: value = 4; break; + case MPI_C_EIGHT: value = 8; break; + default: log_bug ("invalid mpi_const selector %d\n", idx); + } + constants[idx] = mpi_alloc_set_ui (value); + constants[idx]->flags = (16|32); + } + + return 0; +} + + /**************** * Note: It was a bad idea to use the number of limbs to allocate * because on a alpha the limbs are large but we normally need @@ -178,6 +210,8 @@ _gcry_mpi_free( gcry_mpi_t a ) { if (!a ) return; + if ((a->flags & 32)) + return; /* Never release a constant. */ if ((a->flags & 4)) gcry_free( a->d ); else @@ -195,7 +229,7 @@ _gcry_mpi_free( gcry_mpi_t a ) void _gcry_mpi_immutable_failed (void) { - log_info ("Warning: trying to change immutable MPI\n"); + log_info ("Warning: trying to change an immutable MPI\n"); } @@ -226,6 +260,12 @@ gcry_mpi_set_opaque( gcry_mpi_t a, void *p, unsigned int nbits ) if (!a) a = mpi_alloc(0); + if (mpi_is_immutable (a)) + { + mpi_immutable_failed (); + return a; + } + if( a->flags & 4 ) gcry_free( a->d ); else @@ -266,6 +306,7 @@ gcry_mpi_copy( gcry_mpi_t a ) : gcry_xmalloc( (a->sign+7)/8 ); memcpy( p, a->d, (a->sign+7)/8 ); b = gcry_mpi_set_opaque( NULL, p, a->sign ); + b->flags &= ~(16|32); /* Reset the immutable and constant flags. */ } else if( a ) { b = mpi_is_secure(a)? mpi_alloc_secure( a->nlimbs ) @@ -273,6 +314,7 @@ gcry_mpi_copy( gcry_mpi_t a ) b->nlimbs = a->nlimbs; b->sign = a->sign; b->flags = a->flags; + b->flags &= ~(16|32); /* Reset the immutable and constant flags. */ for(i=0; i < b->nlimbs; i++ ) b->d[i] = a->d[i]; } @@ -478,24 +520,30 @@ gcry_mpi_randomize( gcry_mpi_t w, void -gcry_mpi_set_flag( gcry_mpi_t a, enum gcry_mpi_flag flag ) +gcry_mpi_set_flag (gcry_mpi_t a, enum gcry_mpi_flag flag) { - switch( flag ) { - case GCRYMPI_FLAG_SECURE: mpi_set_secure(a); break; - case GCRYMPI_FLAG_IMMUTABLE: a->flags |= 16; break; - case GCRYMPI_FLAG_OPAQUE: - default: log_bug("invalid flag value\n"); + switch (flag) + { + case GCRYMPI_FLAG_SECURE: mpi_set_secure(a); break; + case GCRYMPI_FLAG_CONST: a->flags |= (16|32); break; + case GCRYMPI_FLAG_IMMUTABLE: a->flags |= 16; break; + case GCRYMPI_FLAG_OPAQUE: + default: log_bug("invalid flag value\n"); } } void -gcry_mpi_clear_flag( gcry_mpi_t a, enum gcry_mpi_flag flag ) +gcry_mpi_clear_flag (gcry_mpi_t a, enum gcry_mpi_flag flag) { (void)a; /* Not yet used. */ switch (flag) { - case GCRYMPI_FLAG_IMMUTABLE: a->flags &= ~16; break; + case GCRYMPI_FLAG_IMMUTABLE: + if (!(a->flags & 32)) + a->flags &= ~16; + break; + case GCRYMPI_FLAG_CONST: case GCRYMPI_FLAG_SECURE: case GCRYMPI_FLAG_OPAQUE: default: log_bug("invalid flag value\n"); @@ -503,15 +551,30 @@ gcry_mpi_clear_flag( gcry_mpi_t a, enum gcry_mpi_flag flag ) } int -gcry_mpi_get_flag( gcry_mpi_t a, enum gcry_mpi_flag flag ) +gcry_mpi_get_flag (gcry_mpi_t a, enum gcry_mpi_flag flag) { switch (flag) { - case GCRYMPI_FLAG_SECURE: return (a->flags & 1); - case GCRYMPI_FLAG_OPAQUE: return (a->flags & 4); - case GCRYMPI_FLAG_IMMUTABLE: return (a->flags & 16); + case GCRYMPI_FLAG_SECURE: return !!(a->flags & 1); + case GCRYMPI_FLAG_OPAQUE: return !!(a->flags & 4); + case GCRYMPI_FLAG_IMMUTABLE: return !!(a->flags & 16); + case GCRYMPI_FLAG_CONST: return !!(a->flags & 32); default: log_bug("invalid flag value\n"); } /*NOTREACHED*/ return 0; } + + +/* Return a constant MPI descripbed by NO which is one of the + MPI_C_xxx macros. There is no need to copy this returned value; it + may be used directly. */ +gcry_mpi_t +_gcry_mpi_const (enum gcry_mpi_constants no) +{ + if ((int)no < 0 || no > MPI_NUMBER_OF_CONSTANTS) + log_bug("invalid mpi_const selector %d\n", no); + if (!constants[no]) + log_bug("MPI subsystem not initialized\n"); + return constants[no]; +} diff --git a/src/g10lib.h b/src/g10lib.h index da76c7b..3caa2be 100644 --- a/src/g10lib.h +++ b/src/g10lib.h @@ -348,6 +348,7 @@ gcry_err_code_t _gcry_cipher_init (void); gcry_err_code_t _gcry_md_init (void); gcry_err_code_t _gcry_pk_init (void); gcry_err_code_t _gcry_secmem_module_init (void); +gcry_err_code_t _gcry_mpi_init (void); gcry_err_code_t _gcry_pk_module_lookup (int id, gcry_module_t *module); void _gcry_pk_module_release (gcry_module_t module); diff --git a/src/gcrypt.h.in b/src/gcrypt.h.in index 9f6438c..eb9a11d 100644 --- a/src/gcrypt.h.in +++ b/src/gcrypt.h.in @@ -457,7 +457,8 @@ enum gcry_mpi_flag GCRYMPI_FLAG_OPAQUE = 2, /* The number is not a real one but just a way to store some bytes. This is useful for encrypted big integers. */ - GCRYMPI_FLAG_IMMUTABLE = 4 /* Mark the MPI as immutable. */ + GCRYMPI_FLAG_IMMUTABLE = 4, /* Mark the MPI as immutable. */ + GCRYMPI_FLAG_CONST = 8 /* Mark the MPI as a constant. */ }; diff --git a/src/global.c b/src/global.c index a1a83e9..0c6fbbd 100644 --- a/src/global.c +++ b/src/global.c @@ -140,6 +140,9 @@ global_init (void) err = _gcry_secmem_module_init (); if (err) goto fail; + err = _gcry_mpi_init (); + if (err) + goto fail; return; diff --git a/src/mpi.h b/src/mpi.h index 93ad889..9c22141 100644 --- a/src/mpi.h +++ b/src/mpi.h @@ -70,7 +70,8 @@ struct gcry_mpi for opaque MPIs to store the length. */ unsigned int flags; /* Bit 0: Array to be allocated in secure memory space.*/ /* Bit 2: The limb is a pointer to some m_alloced data.*/ - /* Bit 4: Const MPI - the MPI may not be modified. */ + /* Bit 4: Immutable MPI - the MPI may not be modified. */ + /* Bit 5: Constant MPI - the MPI will not be freed. */ mpi_limb_t *d; /* Array with the limbs */ }; @@ -108,6 +109,7 @@ struct gcry_mpi void _gcry_mpi_immutable_failed (void); #define mpi_immutable_failed() _gcry_mpi_immutable_failed () +#define mpi_is_const(a) ((a) && ((a)->flags&32)) #define mpi_is_immutable(a) ((a) && ((a)->flags&16)) #define mpi_is_opaque(a) ((a) && ((a)->flags&4)) #define mpi_is_secure(a) ((a) && ((a)->flags&1)) @@ -122,6 +124,7 @@ void _gcry_mpi_immutable_failed (void); #define mpi_swap(a,b) _gcry_mpi_swap ((a),(b)) #define mpi_new(n) _gcry_mpi_new ((n)) #define mpi_snew(n) _gcry_mpi_snew ((n)) +#define mpi_const(n) _gcry_mpi_const ((n)) void _gcry_mpi_clear( gcry_mpi_t a ); gcry_mpi_t _gcry_mpi_alloc_like( gcry_mpi_t a ); @@ -132,6 +135,23 @@ void _gcry_mpi_swap( gcry_mpi_t a, gcry_mpi_t b); gcry_mpi_t _gcry_mpi_new (unsigned int nbits); gcry_mpi_t _gcry_mpi_snew (unsigned int nbits); +/* Constants used to return constant MPIs. See _gcry_mpi_init if you + want to add more constants. */ +#define MPI_NUMBER_OF_CONSTANTS 6 +enum gcry_mpi_constants + { + MPI_C_ZERO, + MPI_C_ONE, + MPI_C_TWO, + MPI_C_THREE, + MPI_C_FOUR, + MPI_C_EIGHT + }; + + +gcry_mpi_t _gcry_mpi_const (enum gcry_mpi_constants no); + + /*-- mpicoder.c --*/ void _gcry_log_mpidump( const char *text, gcry_mpi_t a ); u32 _gcry_mpi_get_keyid( gcry_mpi_t a, u32 *keyid ); diff --git a/tests/mpitests.c b/tests/mpitests.c index cf82842..3b75ea7 100644 --- a/tests/mpitests.c +++ b/tests/mpitests.c @@ -88,6 +88,67 @@ unsigned char manyff[] = { }; +static int +test_const_and_immutable (void) +{ + gcry_mpi_t one, second_one; + + one = gcry_mpi_set_ui (NULL, 1); + if (gcry_mpi_get_flag (one, GCRYMPI_FLAG_IMMUTABLE) + || gcry_mpi_get_flag (one, GCRYMPI_FLAG_CONST)) + die ("immutable or const flag initially set\n"); + + second_one = gcry_mpi_copy (one); + if (gcry_mpi_get_flag (second_one, GCRYMPI_FLAG_IMMUTABLE)) + die ("immutable flag set after copy\n"); + if (gcry_mpi_get_flag (second_one, GCRYMPI_FLAG_CONST)) + die ("const flag set after copy\n"); + gcry_mpi_release (second_one); + + gcry_mpi_set_flag (one, GCRYMPI_FLAG_IMMUTABLE); + if (!gcry_mpi_get_flag (one, GCRYMPI_FLAG_IMMUTABLE)) + die ("failed to set immutable flag\n"); + if (gcry_mpi_get_flag (one, GCRYMPI_FLAG_CONST)) + die ("const flag unexpectly set\n"); + + second_one = gcry_mpi_copy (one); + if (gcry_mpi_get_flag (second_one, GCRYMPI_FLAG_IMMUTABLE)) + die ("immutable flag not cleared after copy\n"); + if (gcry_mpi_get_flag (second_one, GCRYMPI_FLAG_CONST)) + die ("const flag unexpectly set after copy\n"); + gcry_mpi_release (second_one); + + gcry_mpi_clear_flag (one, GCRYMPI_FLAG_IMMUTABLE); + if (gcry_mpi_get_flag (one, GCRYMPI_FLAG_IMMUTABLE)) + die ("failed to clear immutable flag\n"); + if (gcry_mpi_get_flag (one, GCRYMPI_FLAG_CONST)) + die ("const flag unexpectly set\n"); + + gcry_mpi_set_flag (one, GCRYMPI_FLAG_CONST); + if (!gcry_mpi_get_flag (one, GCRYMPI_FLAG_CONST)) + die ("failed to set const flag\n"); + if (!gcry_mpi_get_flag (one, GCRYMPI_FLAG_IMMUTABLE)) + die ("failed to set immutable flag with const flag\n"); + + second_one = gcry_mpi_copy (one); + if (gcry_mpi_get_flag (second_one, GCRYMPI_FLAG_IMMUTABLE)) + die ("immutable flag not cleared after copy\n"); + if (gcry_mpi_get_flag (second_one, GCRYMPI_FLAG_CONST)) + die ("const flag not cleared after copy\n"); + gcry_mpi_release (second_one); + + gcry_mpi_clear_flag (one, GCRYMPI_FLAG_IMMUTABLE); + if (!gcry_mpi_get_flag (one, GCRYMPI_FLAG_IMMUTABLE)) + die ("clearing immutable flag not ignored for a constant MPI\n"); + if (!gcry_mpi_get_flag (one, GCRYMPI_FLAG_CONST)) + die ("const flag unexpectly cleared\n"); + + /* Due to the the constant flag the release below should be a NOP + and will leak memory. */ + gcry_mpi_release (one); + return 1; +} + static int test_add (void) @@ -292,6 +353,7 @@ main (int argc, char* argv[]) } gcry_control(GCRYCTL_DISABLE_SECMEM); + test_const_and_immutable (); test_add (); test_sub (); test_mul (); commit 1fecae98ee7e0fa49b29f98efa6817ca121ed98a Author: Werner Koch Date: Tue Mar 12 20:20:42 2013 +0100 Add GCRYMPI_FLAG_IMMUTABLE to help debugging. * src/gcrypt.h.in (GCRYMPI_FLAG_IMMUTABLE): New. * src/mpi.h (mpi_is_immutable): New macro. * mpi/mpiutil.c (gcry_mpi_set_flag, gcry_mpi_clear_flag) (gcry_mpi_get_flag): Implement new flag (_gcry_mpi_immutable_failed): New. * mpi/mpiutil.c (_gcry_mpi_clear, _gcry_mpi_free, gcry_mpi_snatch) (gcry_mpi_set, gcry_mpi_randomize): Act upon the immutable flag. * mpi/mpi-bit.c (gcry_mpi_set_bit, gcry_mpi_set_highbit) (gcry_mpi_clear_highbit, gcry_mpi_clear_bit) (_gcry_mpi_rshift_limbs, gcry_mpi_lshift): Ditto. * mpi/mpicoder.c (_gcry_mpi_set_buffer): Ditto. -- Note that this flag is currently only checked by a few MPI functions. The reason why we eventually need such a flag is to help implementing a generic way to retrieve and set ECC parameters without accidentally changing a curve parameter taken from a list of predefined curves. diff --git a/NEWS b/NEWS index 733dd88..3a4ca4c 100644 --- a/NEWS +++ b/NEWS @@ -50,6 +50,7 @@ Noteworthy changes in version 1.6.0 (unreleased) gcry_mpi_ec_dup NEW. gcry_mpi_ec_add NEW. gcry_mpi_ec_mul NEW. + GCRYMPI_FLAG_IMMUTABLE NEW. Noteworthy changes in version 1.5.0 (2011-06-29) diff --git a/doc/gcrypt.texi b/doc/gcrypt.texi index c986ec7..bfc825d 100644 --- a/doc/gcrypt.texi +++ b/doc/gcrypt.texi @@ -3970,6 +3970,9 @@ Multiply the point @var{u} of the elliptic curve described by @node Miscellaneous @section Miscellaneous +An MPI data type is allowed to be ``misused'' to store an arbitrary +value. Two functions implement this kludge: + @deftypefun gcry_mpi_t gcry_mpi_set_opaque (@w{gcry_mpi_t @var{a}}, @w{void *@var{p}}, @w{unsigned int @var{nbits}}) Store @var{nbits} of the value @var{p} points to in @var{a} and mark @@ -3980,7 +3983,6 @@ math calculation and is only used to store an arbitrary bit pattern in WARNING: Never use an opaque MPI for actual math operations. The only valid functions are gcry_mpi_get_opaque and gcry_mpi_release. Use gcry_mpi_scan to convert a string of arbitrary bytes into an MPI. - @end deftypefun @deftypefun {void *} gcry_mpi_get_opaque (@w{gcry_mpi_t @var{a}}, @w{unsigned int *@var{nbits}}) @@ -3991,23 +3993,46 @@ size in @var{nbits}. Note that the returned pointer is still owned by MPI. @end deftypefun - at deftypefun void gcry_mpi_set_flag (@w{gcry_mpi_t @var{a}}, @w{enum gcry_mpi_flag @var{flag}}) +Each MPI has an associated set of flags for special purposes. The +currently defined flags are: -Set the @var{flag} for the MPI @var{a}. Currently only the flag - at code{GCRYMPI_FLAG_SECURE} is allowed to convert @var{a} into an MPI -stored in "secure memory". - at end deftypefun + at table @code + at item GCRYMPI_FLAG_SECURE +Setting this flag converts @var{a} into an MPI stored in "secure +memory". Clearing this flag is not allowed. + at item GCRYMPI_FLAG_OPAQUE +This is an interanl flag, indicating the an opaque valuue and not an +integer is stored. This is an read-only flag; it may not be set or +cleared. + at item GCRYMPI_FLAG_IMMUTABLE +If this flag is set, the MPI is marked as immutable. Setting or +changing the value of that MPI is ignored and an error message is +logged. The flag is sometimes useful for debugging. + at end table - at deftypefun void gcry_mpi_clear_flag (@w{gcry_mpi_t @var{a}}, @w{enum gcry_mpi_flag @var{flag}}) + at deftypefun void gcry_mpi_set_flag (@w{gcry_mpi_t @var{a}}, @ + @w{enum gcry_mpi_flag @var{flag}}) -Clear @var{flag} for the multi-precision-integers @var{a}. Note that -this function is currently useless as no flags are allowed. +Set the @var{flag} for the MPI @var{a}. The only allowed flags are + at code{GCRYMPI_FLAG_SECURE} and @code{GCRYMPI_FLAG_IMMUTABLE}. @end deftypefun - at deftypefun int gcry_mpi_get_flag (@w{gcry_mpi_t @var{a}}, @w{enum gcry_mpi_flag @var{flag}}) + at deftypefun void gcry_mpi_clear_flag (@w{gcry_mpi_t @var{a}}, @ + @w{enum gcry_mpi_flag @var{flag}}) -Return true when the @var{flag} is set for @var{a}. +Clear @var{flag} for the multi-precision-integers @var{a}. The only +allowed flag is @code{GCRYMPI_FLAG_IMMUTABLE}. @end deftypefun +o + at deftypefun int gcry_mpi_get_flag (@w{gcry_mpi_t @var{a}}, @ + @w{enum gcry_mpi_flag @var{flag}}) + +Return true if @var{flag} is set for @var{a}. + at end deftypefun + + +To put a random value into an MPI, the following convenience function +may be used: @deftypefun void gcry_mpi_randomize (@w{gcry_mpi_t @var{w}}, @w{unsigned int @var{nbits}}, @w{enum gcry_random_level @var{level}}) diff --git a/mpi/mpi-bit.c b/mpi/mpi-bit.c index cdc6b0b..74042e8 100644 --- a/mpi/mpi-bit.c +++ b/mpi/mpi-bit.c @@ -1,5 +1,6 @@ /* mpi-bit.c - MPI bit level functions * Copyright (C) 1998, 1999, 2001, 2002, 2006 Free Software Foundation, Inc. + * Copyright (C) 2013 g10 Code GmbH * * This file is part of Libgcrypt. * @@ -117,6 +118,12 @@ gcry_mpi_set_bit( gcry_mpi_t a, unsigned int n ) { unsigned int limbno, bitno; + if (mpi_is_immutable (a)) + { + mpi_immutable_failed (); + return; + } + limbno = n / BITS_PER_MPI_LIMB; bitno = n % BITS_PER_MPI_LIMB; @@ -136,6 +143,12 @@ gcry_mpi_set_highbit( gcry_mpi_t a, unsigned int n ) { unsigned int limbno, bitno; + if (mpi_is_immutable (a)) + { + mpi_immutable_failed (); + return; + } + limbno = n / BITS_PER_MPI_LIMB; bitno = n % BITS_PER_MPI_LIMB; @@ -156,18 +169,23 @@ gcry_mpi_set_highbit( gcry_mpi_t a, unsigned int n ) void gcry_mpi_clear_highbit( gcry_mpi_t a, unsigned int n ) { - unsigned int limbno, bitno; + unsigned int limbno, bitno; - limbno = n / BITS_PER_MPI_LIMB; - bitno = n % BITS_PER_MPI_LIMB; + if (mpi_is_immutable (a)) + { + mpi_immutable_failed (); + return; + } - if( limbno >= a->nlimbs ) - return; /* not allocated, therefore no need to clear bits - :-) */ + limbno = n / BITS_PER_MPI_LIMB; + bitno = n % BITS_PER_MPI_LIMB; + + if( limbno >= a->nlimbs ) + return; /* not allocated, therefore no need to clear bits :-) */ - for( ; bitno < BITS_PER_MPI_LIMB; bitno++ ) - a->d[limbno] &= ~(A_LIMB_1 << bitno); - a->nlimbs = limbno+1; + for( ; bitno < BITS_PER_MPI_LIMB; bitno++ ) + a->d[limbno] &= ~(A_LIMB_1 << bitno); + a->nlimbs = limbno+1; } /**************** @@ -176,14 +194,20 @@ gcry_mpi_clear_highbit( gcry_mpi_t a, unsigned int n ) void gcry_mpi_clear_bit( gcry_mpi_t a, unsigned int n ) { - unsigned int limbno, bitno; + unsigned int limbno, bitno; - limbno = n / BITS_PER_MPI_LIMB; - bitno = n % BITS_PER_MPI_LIMB; + if (mpi_is_immutable (a)) + { + mpi_immutable_failed (); + return; + } - if( limbno >= a->nlimbs ) - return; /* don't need to clear this bit, it's to far to left */ - a->d[limbno] &= ~(A_LIMB_1 << bitno); + limbno = n / BITS_PER_MPI_LIMB; + bitno = n % BITS_PER_MPI_LIMB; + + if (limbno >= a->nlimbs) + return; /* Don't need to clear this bit, it's far too left. */ + a->d[limbno] &= ~(A_LIMB_1 << bitno); } @@ -194,19 +218,26 @@ gcry_mpi_clear_bit( gcry_mpi_t a, unsigned int n ) void _gcry_mpi_rshift_limbs( gcry_mpi_t a, unsigned int count ) { - mpi_ptr_t ap = a->d; - mpi_size_t n = a->nlimbs; - unsigned int i; + mpi_ptr_t ap = a->d; + mpi_size_t n = a->nlimbs; + unsigned int i; - if( count >= n ) { - a->nlimbs = 0; - return; + if (mpi_is_immutable (a)) + { + mpi_immutable_failed (); + return; } - for( i = 0; i < n - count; i++ ) - ap[i] = ap[i+count]; - ap[i] = 0; - a->nlimbs -= count; + if (count >= n) + { + a->nlimbs = 0; + return; + } + + for( i = 0; i < n - count; i++ ) + ap[i] = ap[i+count]; + ap[i] = 0; + a->nlimbs -= count; } @@ -221,6 +252,12 @@ gcry_mpi_rshift ( gcry_mpi_t x, gcry_mpi_t a, unsigned int n ) unsigned int nlimbs = (n/BITS_PER_MPI_LIMB); unsigned int nbits = (n%BITS_PER_MPI_LIMB); + if (mpi_is_immutable (x)) + { + mpi_immutable_failed (); + return; + } + if ( x == a ) { /* In-place operation. */ @@ -328,6 +365,12 @@ gcry_mpi_lshift ( gcry_mpi_t x, gcry_mpi_t a, unsigned int n ) unsigned int nlimbs = (n/BITS_PER_MPI_LIMB); unsigned int nbits = (n%BITS_PER_MPI_LIMB); + if (mpi_is_immutable (x)) + { + mpi_immutable_failed (); + return; + } + if (x == a && !n) return; /* In-place shift with an amount of zero. */ diff --git a/mpi/mpicoder.c b/mpi/mpicoder.c index a3435ed..06d5553 100644 --- a/mpi/mpicoder.c +++ b/mpi/mpicoder.c @@ -305,6 +305,12 @@ _gcry_mpi_set_buffer (gcry_mpi_t a, const void *buffer_arg, int nlimbs; int i; + if (mpi_is_immutable (a)) + { + mpi_immutable_failed (); + return; + } + nlimbs = (nbytes + BYTES_PER_MPI_LIMB - 1) / BYTES_PER_MPI_LIMB; RESIZE_IF_NEEDED(a, nlimbs); a->sign = sign; diff --git a/mpi/mpiutil.c b/mpi/mpiutil.c index d410d90..64a2f7e 100644 --- a/mpi/mpiutil.c +++ b/mpi/mpiutil.c @@ -163,8 +163,13 @@ _gcry_mpi_resize (gcry_mpi_t a, unsigned nlimbs) void _gcry_mpi_clear( gcry_mpi_t a ) { - a->nlimbs = 0; - a->flags = 0; + if (mpi_is_immutable (a)) + { + mpi_immutable_failed (); + return; + } + a->nlimbs = 0; + a->flags = 0; } @@ -179,11 +184,21 @@ _gcry_mpi_free( gcry_mpi_t a ) { _gcry_mpi_free_limb_space(a->d, a->alloced); } - if ((a->flags & ~7)) - log_bug("invalid flag value in mpi\n"); + /* Check that the flags makes sense. We better allow for bit 1 + (value 2) for backward ABI compatibility. */ + if ((a->flags & ~(1|2|4|16))) + log_bug("invalid flag value in mpi_free\n"); gcry_free(a); } + +void +_gcry_mpi_immutable_failed (void) +{ + log_info ("Warning: trying to change immutable MPI\n"); +} + + static void mpi_set_secure( gcry_mpi_t a ) { @@ -303,6 +318,11 @@ gcry_mpi_snatch (gcry_mpi_t w, gcry_mpi_t u) { if (w) { + if (mpi_is_immutable (w)) + { + mpi_immutable_failed (); + return; + } _gcry_mpi_assign_limb_space (w, u->d, u->alloced); w->nlimbs = u->nlimbs; w->sign = u->sign; @@ -324,6 +344,11 @@ gcry_mpi_set( gcry_mpi_t w, gcry_mpi_t u) if (!w) w = _gcry_mpi_alloc( mpi_get_nlimbs(u) ); + if (mpi_is_immutable (w)) + { + mpi_immutable_failed (); + return w; + } RESIZE_IF_NEEDED(w, usize); wp = w->d; up = u->d; @@ -342,6 +367,11 @@ gcry_mpi_set_ui( gcry_mpi_t w, unsigned long u) w = _gcry_mpi_alloc (1); /* FIXME: If U is 0 we have no need to resize and thus possible allocating the the limbs. */ + if (mpi_is_immutable (w)) + { + mpi_immutable_failed (); + return w; + } RESIZE_IF_NEEDED(w, 1); w->d[0] = u; w->nlimbs = u? 1:0; @@ -426,6 +456,11 @@ gcry_mpi_randomize( gcry_mpi_t w, unsigned char *p; size_t nbytes = (nbits+7)/8; + if (mpi_is_immutable (w)) + { + mpi_immutable_failed (); + return; + } if (level == GCRY_WEAK_RANDOM) { p = mpi_is_secure(w) ? gcry_xmalloc_secure (nbytes) @@ -446,7 +481,8 @@ void gcry_mpi_set_flag( gcry_mpi_t a, enum gcry_mpi_flag flag ) { switch( flag ) { - case GCRYMPI_FLAG_SECURE: mpi_set_secure(a); break; + case GCRYMPI_FLAG_SECURE: mpi_set_secure(a); break; + case GCRYMPI_FLAG_IMMUTABLE: a->flags |= 16; break; case GCRYMPI_FLAG_OPAQUE: default: log_bug("invalid flag value\n"); } @@ -459,6 +495,7 @@ gcry_mpi_clear_flag( gcry_mpi_t a, enum gcry_mpi_flag flag ) switch (flag) { + case GCRYMPI_FLAG_IMMUTABLE: a->flags &= ~16; break; case GCRYMPI_FLAG_SECURE: case GCRYMPI_FLAG_OPAQUE: default: log_bug("invalid flag value\n"); @@ -472,6 +509,7 @@ gcry_mpi_get_flag( gcry_mpi_t a, enum gcry_mpi_flag flag ) { case GCRYMPI_FLAG_SECURE: return (a->flags & 1); case GCRYMPI_FLAG_OPAQUE: return (a->flags & 4); + case GCRYMPI_FLAG_IMMUTABLE: return (a->flags & 16); default: log_bug("invalid flag value\n"); } /*NOTREACHED*/ diff --git a/src/gcrypt.h.in b/src/gcrypt.h.in index 57b841e..9f6438c 100644 --- a/src/gcrypt.h.in +++ b/src/gcrypt.h.in @@ -454,9 +454,10 @@ enum gcry_mpi_format enum gcry_mpi_flag { GCRYMPI_FLAG_SECURE = 1, /* Allocate the number in "secure" memory. */ - GCRYMPI_FLAG_OPAQUE = 2 /* The number is not a real one but just + GCRYMPI_FLAG_OPAQUE = 2, /* The number is not a real one but just a way to store some bytes. This is useful for encrypted big integers. */ + GCRYMPI_FLAG_IMMUTABLE = 4 /* Mark the MPI as immutable. */ }; diff --git a/src/mpi.h b/src/mpi.h index 23afa68..93ad889 100644 --- a/src/mpi.h +++ b/src/mpi.h @@ -69,7 +69,8 @@ struct gcry_mpi int sign; /* Indicates a negative number and is also used for opaque MPIs to store the length. */ unsigned int flags; /* Bit 0: Array to be allocated in secure memory space.*/ - /* Bit 2: the limb is a pointer to some m_alloced data.*/ + /* Bit 2: The limb is a pointer to some m_alloced data.*/ + /* Bit 4: Const MPI - the MPI may not be modified. */ mpi_limb_t *d; /* Array with the limbs */ }; @@ -104,8 +105,12 @@ struct gcry_mpi gcry_mpi_t _gcry_mpi_copy( gcry_mpi_t a ); #endif -#define mpi_is_opaque(a) ((a) && ((a)->flags&4)) -#define mpi_is_secure(a) ((a) && ((a)->flags&1)) +void _gcry_mpi_immutable_failed (void); +#define mpi_immutable_failed() _gcry_mpi_immutable_failed () + +#define mpi_is_immutable(a) ((a) && ((a)->flags&16)) +#define mpi_is_opaque(a) ((a) && ((a)->flags&4)) +#define mpi_is_secure(a) ((a) && ((a)->flags&1)) #define mpi_clear(a) _gcry_mpi_clear ((a)) #define mpi_alloc_like(a) _gcry_mpi_alloc_like((a)) #define mpi_snatch(a,b) _gcry_mpi_snatch ((a),(b)) ----------------------------------------------------------------------- Summary of changes: NEWS | 9 ++- cipher/ecc.c | 287 +++++++++++++++++++++++++++++++++++++++++++++- doc/gcrypt.texi | 141 +++++++++++++++++++---- mpi/ec.c | 297 ++++++++++++++++++++++++++++++------------------ mpi/mpi-bit.c | 93 +++++++++++---- mpi/mpicoder.c | 6 + mpi/mpiutil.c | 127 ++++++++++++++++++-- src/Makefile.am | 1 + src/context.c | 2 +- src/ec-context.h | 57 +++++++++ src/g10lib.h | 1 + src/gcrypt.h.in | 25 ++++- src/global.c | 3 + src/libgcrypt.def | 14 ++- src/libgcrypt.vers | 4 +- src/mpi.h | 44 +++++++- src/visibility.c | 32 +++++- src/visibility.h | 8 +- tests/mpitests.c | 62 ++++++++++ tests/t-mpi-point.c | 318 ++++++++++++++++++++++++++++++++++++++++++++++++--- 20 files changed, 1318 insertions(+), 213 deletions(-) create mode 100644 src/ec-context.h hooks/post-receive -- The GNU crypto library http://git.gnupg.org From cvs at cvs.gnupg.org Mon Mar 18 09:17:20 2013 From: cvs at cvs.gnupg.org (by Werner Koch) Date: Mon, 18 Mar 2013 09:17:20 +0100 Subject: [git] GCRYPT - branch, LIBGCRYPT-1-5-BRANCH, updated. libgcrypt-1.5.0-18-gd313255 Message-ID: This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "The GNU crypto library". The branch, LIBGCRYPT-1-5-BRANCH has been updated via d313255350e6f397500ce23714ddec8780f32449 (commit) from e0139f73600ed584f23d57a2baf768e32ea900ec (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit d313255350e6f397500ce23714ddec8780f32449 Author: Werner Koch Date: Mon Mar 18 09:02:35 2013 +0100 mpi: Make using gcc's -Ofast easier. * cipher/Makefile.am (o_flag_munging): Take -Ofast in account. -- GnuPG-bug-id: 1468 diff --git a/cipher/Makefile.am b/cipher/Makefile.am index cbeace8..f8c39fb 100644 --- a/cipher/Makefile.am +++ b/cipher/Makefile.am @@ -68,7 +68,7 @@ rfc2268.c \ camellia.c camellia.h camellia-glue.c if ENABLE_O_FLAG_MUNGING -o_flag_munging = sed -e 's/-O[2-9s]*/-O1/g' +o_flag_munging = sed -e 's/-O([2-9s]|fast)*/-O1/g' else o_flag_munging = cat endif ----------------------------------------------------------------------- Summary of changes: cipher/Makefile.am | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) hooks/post-receive -- The GNU crypto library http://git.gnupg.org From cvs at cvs.gnupg.org Mon Mar 18 18:30:32 2013 From: cvs at cvs.gnupg.org (by Werner Koch) Date: Mon, 18 Mar 2013 18:30:32 +0100 Subject: [git] GCRYPT - branch, LIBGCRYPT-1-5-BRANCH, updated. libgcrypt-1.5.1-2-g8160f3b Message-ID: This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "The GNU crypto library". The branch, LIBGCRYPT-1-5-BRANCH has been updated via 8160f3b81e976d0568cc65260c29cc3d0f76fcc9 (commit) from 462dcda91ea20e5cc08ad644d49045f2944ae7fa (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 8160f3b81e976d0568cc65260c29cc3d0f76fcc9 Author: Werner Koch Date: Mon Mar 18 18:15:49 2013 +0100 Get rid of the deprecated AM_CONFIG_HEADER. * configure.ac: Use AC_CONFIG_HEADERS. -- GnuPG-bug-id: 1459 diff --git a/configure.ac b/configure.ac index 34c3beb..8c419aa 100644 --- a/configure.ac +++ b/configure.ac @@ -72,7 +72,7 @@ VERSION=$PACKAGE_VERSION AC_CONFIG_SRCDIR([src/libgcrypt.vers]) AM_INIT_AUTOMAKE -AM_CONFIG_HEADER(config.h) +AC_CONFIG_HEADERS([config.h]) AC_CONFIG_MACRO_DIR([m4]) AC_CONFIG_LIBOBJ_DIR([compat]) AC_CANONICAL_HOST ----------------------------------------------------------------------- Summary of changes: configure.ac | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) hooks/post-receive -- The GNU crypto library http://git.gnupg.org From cvs at cvs.gnupg.org Tue Mar 19 15:27:35 2013 From: cvs at cvs.gnupg.org (by Werner Koch) Date: Tue, 19 Mar 2013 15:27:35 +0100 Subject: [git] GCRYPT - branch, master, updated. libgcrypt-1.5.0-97-g931e409 Message-ID: This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "The GNU crypto library". The branch, master has been updated via 931e409e877d1e444edd53dead327ec8e64daf9a (commit) from 229f3219f80c9369ed9624242c0436ae6d293201 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 931e409e877d1e444edd53dead327ec8e64daf9a Author: Werner Koch Date: Tue Mar 19 15:12:07 2013 +0100 Extend the new EC interface and fix two bugs. * src/ec-context.h (mpi_ec_ctx_s): Add field NEED_SYNC. * mpi/ec.c (ec_p_sync): New. (ec_p_init): Only set NEED_SYNC. (_gcry_mpi_ec_set_mpi): Set NEED_SYNC for 'p' and 'a'. (_gcry_mpi_ec_dup_point, _gcry_mpi_ec_add_points) (_gcry_mpi_ec_mul_point): Call ec_p_sync. (_gcry_mpi_ec_get_point): Recompute 'q' is needed. (_gcry_mpi_ec_get_mpi): Ditto. Also allow for names 'q', 'q.x', 'q.y', and 'g'. * cipher/ecc.c (_gcry_mpi_ec_ec2os): New. * cipher/ecc.c (_gcry_mpi_ec_new): Fix init from parameters 'Q'->'q', 'G'->'q'. -- Note that the parameter names are all lowercase. This patch fixes an inconsistency. The other bug was that changing the parameters D or A may have resulted in wrong computations because helper variables were not updated. Now we delay the computation of those helper variables until we need them. diff --git a/cipher/ecc.c b/cipher/ecc.c index c95a57a..c23ba08 100644 --- a/cipher/ecc.c +++ b/cipher/ecc.c @@ -930,6 +930,27 @@ ec2os (gcry_mpi_t x, gcry_mpi_t y, gcry_mpi_t p) } +/* Convert POINT into affine coordinates using the context CTX and + return a newly allocated MPI. If the conversion is not possible + NULL is returned. This function won't print an error message. */ +gcry_mpi_t +_gcry_mpi_ec_ec2os (gcry_mpi_point_t point, mpi_ec_t ectx) +{ + gcry_mpi_t g_x, g_y, result; + + g_x = mpi_new (0); + g_y = mpi_new (0); + if (_gcry_mpi_ec_get_affine (g_x, g_y, point, ectx)) + result = NULL; + else + result = ec2os (g_x, g_y, ectx->p); + mpi_free (g_x); + mpi_free (g_y); + + return result; +} + + /* RESULT must have been initialized and is set on success to the point given by VALUE. */ static gcry_error_t @@ -1838,13 +1859,13 @@ _gcry_mpi_ec_new (gcry_ctx_t *r_ctx, errc = mpi_from_keyparam (&b, keyparam, "b"); if (errc) goto leave; - errc = point_from_keyparam (&G, keyparam, "G"); + errc = point_from_keyparam (&G, keyparam, "g"); if (errc) goto leave; errc = mpi_from_keyparam (&n, keyparam, "n"); if (errc) goto leave; - errc = point_from_keyparam (&Q, keyparam, "Q"); + errc = point_from_keyparam (&Q, keyparam, "q"); if (errc) goto leave; errc = mpi_from_keyparam (&d, keyparam, "d"); diff --git a/doc/gcrypt.texi b/doc/gcrypt.texi index 4d48eb4..a6b585d 100644 --- a/doc/gcrypt.texi +++ b/doc/gcrypt.texi @@ -3953,7 +3953,10 @@ modified, it is suggested to pass @code{1} to @var{copy}, so that the function guarantees that a modifiable copy of the MPI is returned. If @code{0} is used for @var{copy}, this function may return a constant flagged MPI. In any case @code{gcry_mpi_release} needs to be called -to release the result. For valid names @ref{ecc_keyparam}. +to release the result. For valid names @ref{ecc_keyparam}. If a +point parameter is requested it is returned as an uncompressed encoded +point. If the public key @code{q} is requested but only the private +key @code{d} is available, @code{q} will be recomputed on the fly. @end deftypefun @deftypefun gcry_mpi_point_t gcry_mpi_ec_get_point ( @ @@ -3965,7 +3968,9 @@ modified, it is suggested to pass @code{1} to @var{copy}, so that the function guarantees that a modifiable copy of the MPI is returned. If @code{0} is used for @var{copy}, this function may return a constant flagged point. In any case @code{gcry_mpi_point_release} needs to be -called to release the result. +called to release the result. If the public key @code{q} is requested +but only the private key @code{d} is available, @code{q} will be +recomputed on the fly. @end deftypefun @deftypefun gpg_error_t gcry_mpi_ec_set_mpi ( @ diff --git a/mpi/ec.c b/mpi/ec.c index 9a6868b..0a348d2 100644 --- a/mpi/ec.c +++ b/mpi/ec.c @@ -337,6 +337,25 @@ ec_invm (gcry_mpi_t x, gcry_mpi_t a, mpi_ec_t ctx) } +/* Sync changed data in the context. */ +static void +ec_p_sync (mpi_ec_t ec) +{ + gcry_mpi_t tmp; + + if (!ec->t.need_sync) + return; + + tmp = mpi_alloc_like (ec->p); + mpi_sub_ui (tmp, ec->p, 3); + ec->t.a_is_pminus3 = !mpi_cmp (ec->a, tmp); + mpi_free (tmp); + + ec_invm (ec->t.two_inv_p, mpi_const (MPI_C_TWO), ec); + ec->t.need_sync = 0; +} + + /* This function initialized a context for elliptic curve based on the field GF(p). P is the prime specifying this field, A is the first @@ -345,20 +364,14 @@ static void ec_p_init (mpi_ec_t ctx, gcry_mpi_t p, gcry_mpi_t a) { int i; - gcry_mpi_t tmp; /* Fixme: Do we want to check some constraints? e.g. a < p */ ctx->p = mpi_copy (p); ctx->a = mpi_copy (a); - tmp = mpi_alloc_like (ctx->p); - mpi_sub_ui (tmp, ctx->p, 3); - ctx->t.a_is_pminus3 = !mpi_cmp (ctx->a, tmp); - mpi_free (tmp); - + ctx->t.need_sync = 1; ctx->t.two_inv_p = mpi_alloc (0); - ec_invm (ctx->t.two_inv_p, mpi_const (MPI_C_TWO), ctx); /* Allocate scratch variables. */ for (i=0; i< DIM(ctx->t.scratch); i++) @@ -492,10 +505,29 @@ _gcry_mpi_ec_get_mpi (const char *name, gcry_ctx_t ctx, int copy) return mpi_is_const (ec->n) && !copy? ec->n : mpi_copy (ec->n); if (!strcmp (name, "d") && ec->d) return mpi_is_const (ec->d) && !copy? ec->d : mpi_copy (ec->d); + + /* Return a requested point coordinate. */ if (!strcmp (name, "g.x") && ec->G && ec->G->x) return mpi_is_const (ec->G->x) && !copy? ec->G->x : mpi_copy (ec->G->x); if (!strcmp (name, "g.y") && ec->G && ec->G->y) return mpi_is_const (ec->G->y) && !copy? ec->G->y : mpi_copy (ec->G->y); + if (!strcmp (name, "q.x") && ec->Q && ec->Q->x) + return mpi_is_const (ec->Q->x) && !copy? ec->Q->x : mpi_copy (ec->Q->x); + if (!strcmp (name, "q.y") && ec->Q && ec->Q->y) + return mpi_is_const (ec->G->y) && !copy? ec->Q->y : mpi_copy (ec->Q->y); + + /* If a point has been requested, return it in standard encoding. */ + if (!strcmp (name, "g") && ec->G) + return _gcry_mpi_ec_ec2os (ec->G, ec); + if (!strcmp (name, "q")) + { + /* If only the private key is given, compute the public key. */ + if (!ec->Q && ec->d && ec->G && ec->p && ec->a) + _gcry_mpi_ec_mul_point (ec->Q, ec->d, ec->G, ec); + + if (ec->Q) + return _gcry_mpi_ec_ec2os (ec->Q, ec); + } return NULL; } @@ -510,8 +542,15 @@ _gcry_mpi_ec_get_point (const char *name, gcry_ctx_t ctx, int copy) if (!strcmp (name, "g") && ec->G) return point_copy (ec->G); - if (!strcmp (name, "q") && ec->Q) - return point_copy (ec->Q); + if (!strcmp (name, "q")) + { + /* If only the private key is given, compute the public key. */ + if (!ec->Q && ec->d && ec->G && ec->p && ec->a) + _gcry_mpi_ec_mul_point (ec->Q, ec->d, ec->G, ec); + + if (ec->Q) + return point_copy (ec->Q); + } return NULL; } @@ -527,11 +566,13 @@ _gcry_mpi_ec_set_mpi (const char *name, gcry_mpi_t newvalue, { mpi_free (ec->p); ec->p = mpi_copy (newvalue); + ec->t.need_sync = 1; } else if (!strcmp (name, "a")) { mpi_free (ec->a); ec->a = mpi_copy (newvalue); + ec->t.need_sync = 1; } else if (!strcmp (name, "b")) { @@ -628,6 +669,8 @@ _gcry_mpi_ec_dup_point (mpi_point_t result, mpi_point_t point, mpi_ec_t ctx) #define l2 (ctx->t.scratch[4]) #define l3 (ctx->t.scratch[5]) + ec_p_sync (ctx); + if (!mpi_cmp_ui (point->y, 0) || !mpi_cmp_ui (point->z, 0)) { /* P_y == 0 || P_z == 0 => [1:1:0] */ @@ -725,6 +768,8 @@ _gcry_mpi_ec_add_points (mpi_point_t result, #define t1 (ctx->t.scratch[9]) #define t2 (ctx->t.scratch[10]) + ec_p_sync (ctx); + if ( (!mpi_cmp (x1, x2)) && (!mpi_cmp (y1, y2)) && (!mpi_cmp (z1, z2)) ) { /* Same point; need to call the duplicate function. */ @@ -854,6 +899,8 @@ _gcry_mpi_ec_mul_point (mpi_point_t result, unsigned int nbits; int i; + ec_p_sync (ctx); + nbits = mpi_get_nbits (scalar); mpi_set_ui (result->x, 1); mpi_set_ui (result->y, 1); @@ -871,6 +918,8 @@ _gcry_mpi_ec_mul_point (mpi_point_t result, unsigned int i, loops; mpi_point_struct p1, p2, p1inv; + ec_p_sync (ctx); + x1 = mpi_alloc_like (ctx->p); y1 = mpi_alloc_like (ctx->p); h = mpi_alloc_like (ctx->p); diff --git a/src/ec-context.h b/src/ec-context.h index 88742bf..6827e18 100644 --- a/src/ec-context.h +++ b/src/ec-context.h @@ -38,6 +38,8 @@ struct mpi_ec_ctx_s /* This structure is private to mpi/ec.c! */ struct { + int need_sync; /* Helper for ec_p_sync. */ + int a_is_pminus3; /* True if A = P - 3. */ gcry_mpi_t two_inv_p; diff --git a/src/mpi.h b/src/mpi.h index b727d5f..fd265bf 100644 --- a/src/mpi.h +++ b/src/mpi.h @@ -289,6 +289,8 @@ void _gcry_mpi_ec_mul_point (mpi_point_t result, gcry_mpi_t scalar, mpi_point_t point, mpi_ec_t ctx); +gcry_mpi_t _gcry_mpi_ec_ec2os (gcry_mpi_point_t point, mpi_ec_t ectx); + gpg_err_code_t _gcry_mpi_ec_p_new (gcry_ctx_t *r_ctx, gcry_mpi_t p, gcry_mpi_t a); gpg_err_code_t _gcry_mpi_ec_new (gcry_ctx_t *r_ctx, diff --git a/tests/t-mpi-point.c b/tests/t-mpi-point.c index 31df12b..a3b6c56 100644 --- a/tests/t-mpi-point.c +++ b/tests/t-mpi-point.c @@ -116,6 +116,15 @@ static struct { NULL, NULL, NULL, NULL, NULL } }; +/* A sample public key for NIST P-256. */ +static const char sample_p256_q[] = + "04" + "42B927242237639A36CE9221B340DB1A9AB76DF2FE3E171277F6A4023DED146E" + "E86525E38CCECFF3FB8D152CC6334F70D23A525175C1BCBDDE6E023B2228770E"; +static const char sample_p256_q_x[] = + "42B927242237639A36CE9221B340DB1A9AB76DF2FE3E171277F6A4023DED146E"; +static const char sample_p256_q_y[] = + "00E86525E38CCECFF3FB8D152CC6334F70D23A525175C1BCBDDE6E023B2228770E"; @@ -164,7 +173,7 @@ die (const char *format, ...) static void -print_mpi (const char *text, gcry_mpi_t a) +print_mpi_2 (const char *text, const char *text2, gcry_mpi_t a) { gcry_error_t err; char *buf; @@ -172,16 +181,41 @@ print_mpi (const char *text, gcry_mpi_t a) err = gcry_mpi_aprint (GCRYMPI_FMT_HEX, bufaddr, NULL, a); if (err) - fprintf (stderr, "%s: [error printing number: %s]\n", - text, gpg_strerror (err)); + fprintf (stderr, "%s%s: [error printing number: %s]\n", + text, text2? text2:"", gpg_strerror (err)); else { - fprintf (stderr, "%s: %s\n", text, buf); + fprintf (stderr, "%s%s: %s\n", text, text2? text2:"", buf); gcry_free (buf); } } +static void +print_mpi (const char *text, gcry_mpi_t a) +{ + print_mpi_2 (text, NULL, a); +} + + +static void +print_point (const char *text, gcry_mpi_point_t a) +{ + gcry_mpi_t x, y, z; + + x = gcry_mpi_new (0); + y = gcry_mpi_new (0); + z = gcry_mpi_new (0); + gcry_mpi_point_get (x, y, z, a); + print_mpi_2 (text, ".x", x); + print_mpi_2 (text, ".y", y); + print_mpi_2 (text, ".z", z); + gcry_mpi_release (x); + gcry_mpi_release (y); + gcry_mpi_release (z); +} + + static gcry_mpi_t hex2mpi (const char *string) { @@ -345,6 +379,8 @@ get_and_cmp_mpi (const char *name, const char *mpistring, const char *desc, fail ("error getting parameter '%s' of curve '%s'\n", name, desc); return 1; } + if (debug) + print_mpi (name, mpi); if (cmp_mpihex (mpi, mpistring)) { fail ("parameter '%s' of curve '%s' does not match\n", name, desc); @@ -371,6 +407,8 @@ get_and_cmp_point (const char *name, fail ("error getting point parameter '%s' of curve '%s'\n", name, desc); return 1; } + if (debug) + print_point (name, point); x = gcry_mpi_new (0); y = gcry_mpi_new (0); @@ -404,12 +442,14 @@ context_param (void) gpg_error_t err; int idx; gcry_ctx_t ctx = NULL; + gcry_mpi_t q; + gcry_sexp_t keyparam; wherestr = "context_param"; + show ("checking standard curves\n"); for (idx=0; test_curve[idx].desc; idx++) { - show ("checking curve '%s'\n", test_curve[idx].desc); gcry_ctx_release (ctx); err = gcry_mpi_ec_new (&ctx, NULL, test_curve[idx].desc); if (err) @@ -437,11 +477,35 @@ context_param (void) } gcry_ctx_release (ctx); - /* FIXME: Add tests for Q and d. */ - /* FIXME: Add test sor the set functions. */ + show ("checking sample public key\n"); + q = hex2mpi (sample_p256_q); + err = gcry_sexp_build (&keyparam, NULL, + "(public-key(ecdsa(curve %s)(q %m)))", + "NIST P-256", q); + if (err) + die ("gcry_sexp_build failed: %s\n", gpg_strerror (err)); + gcry_mpi_release (q); + + /* We can't call gcry_pk_testkey because it is only implemented for + private keys. */ + /* err = gcry_pk_testkey (keyparam); */ + /* if (err) */ + /* fail ("gcry_pk_testkey failed for sample public key: %s\n", */ + /* gpg_strerror (err)); */ + err = gcry_mpi_ec_new (&ctx, keyparam, NULL); + if (err) + fail ("gcry_mpi_ec_new failed for sample public key: %s\n", + gpg_strerror (err)); + else + { + get_and_cmp_mpi ("q", sample_p256_q, "NIST P-256", ctx); + get_and_cmp_point ("q", sample_p256_q_x, sample_p256_q_y, "NIST P-256", + ctx); + } + gcry_sexp_release (keyparam); } ----------------------------------------------------------------------- Summary of changes: cipher/ecc.c | 25 +++++++++++++++- doc/gcrypt.texi | 9 ++++- mpi/ec.c | 67 ++++++++++++++++++++++++++++++++++++++------ src/ec-context.h | 2 + src/mpi.h | 2 + tests/t-mpi-point.c | 78 ++++++++++++++++++++++++++++++++++++++++++++++---- 6 files changed, 163 insertions(+), 20 deletions(-) hooks/post-receive -- The GNU crypto library http://git.gnupg.org From cvs at cvs.gnupg.org Tue Mar 19 17:43:18 2013 From: cvs at cvs.gnupg.org (by Werner Koch) Date: Tue, 19 Mar 2013 17:43:18 +0100 Subject: [git] GnuPG - branch, master, updated. gnupg-2.1.0beta3-172-gc4dbd1b Message-ID: This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "The GNU Privacy Guard". The branch, master has been updated via c4dbd1b2de8ae3847a040444e86500848868bcf4 (commit) via b693ec02c467696bf9d7324dd081e279f9965151 (commit) via 4bde12206c5bf199dc6e12a74af8da4558ba41bf (commit) from 76dc5c08dc2686eef32e1bd221c60fe91201246f (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit c4dbd1b2de8ae3847a040444e86500848868bcf4 Author: Werner Koch Date: Tue Mar 19 17:23:56 2013 +0100 gpg: Print indicator for unknown key capability. * g10/keylist.c (print_capabilities): Print '?' for unknown usage. diff --git a/doc/DETAILS b/doc/DETAILS index a52979f..d5c5cea 100644 --- a/doc/DETAILS +++ b/doc/DETAILS @@ -161,6 +161,7 @@ described here. - s :: Sign - c :: Certify - a :: Authentication + - ? :: Unknown capability A key may have any combination of them in any order. In addition to these letters, the primary key has uppercase versions of the diff --git a/g10/keylist.c b/g10/keylist.c index 87f3a4b..d45aed6 100644 --- a/g10/keylist.c +++ b/g10/keylist.c @@ -627,6 +627,9 @@ print_capabilities (PKT_public_key *pk, KBNODE keyblock) if ((use & PUBKEY_USAGE_AUTH)) es_putc ('a', es_stdout); + if ((use & PUBKEY_USAGE_UNKNOWN)) + es_putc ('?', es_stdout); + if (keyblock) { /* Figure out the usable capabilities. */ commit b693ec02c467696bf9d7324dd081e279f9965151 Author: Daniel Kahn Gillmor Date: Tue Mar 19 11:25:25 2013 -0400 gpg: Allow setting of all zero key flags * g10/keygen.c (do_add_key_flags): Do not check for empty key flags. diff --git a/g10/keygen.c b/g10/keygen.c index fc985ee..2017662 100644 --- a/g10/keygen.c +++ b/g10/keygen.c @@ -216,9 +216,6 @@ do_add_key_flags (PKT_signature *sig, unsigned int use) if (use & PUBKEY_USAGE_AUTH) buf[0] |= 0x20; - if (!buf[0]) - return; - build_sig_subpkt (sig, SIGSUBPKT_KEY_FLAGS, buf, 1); } commit 4bde12206c5bf199dc6e12a74af8da4558ba41bf Author: Werner Koch Date: Fri Mar 15 15:46:03 2013 +0100 gpg: Distinguish between missing and cleared key flags. * include/cipher.h (PUBKEY_USAGE_NONE): New. * g10/getkey.c (parse_key_usage): Set new flag. -- We do not want to use the default capabilities (derived from the algorithm) if any key flags are given in a signature. Thus if key flags are used in any way, the default key capabilities are never used. This allows to create a key with key flags set to all zero so it can't be used. This better reflects common sense. diff --git a/g10/getkey.c b/g10/getkey.c index 9294273..8cc5601 100644 --- a/g10/getkey.c +++ b/g10/getkey.c @@ -1276,13 +1276,19 @@ parse_key_usage (PKT_signature * sig) if (flags) key_usage |= PUBKEY_USAGE_UNKNOWN; + + if (!key_usage) + key_usage |= PUBKEY_USAGE_NONE; } + else if (p) /* Key flags of length zero. */ + key_usage |= PUBKEY_USAGE_NONE; /* We set PUBKEY_USAGE_UNKNOWN to indicate that this key has a capability that we do not handle. This serves to distinguish between a zero key usage which we handle as the default capabilities for that algorithm, and a usage that we do not - handle. */ + handle. Likewise we use PUBKEY_USAGE_NONE to indicate that + key_flags have been given but they do not specify any usage. */ return key_usage; } diff --git a/include/cipher.h b/include/cipher.h index 191e197..557ab70 100644 --- a/include/cipher.h +++ b/include/cipher.h @@ -54,9 +54,14 @@ #define PUBKEY_USAGE_SIG GCRY_PK_USAGE_SIGN /* Good for signatures. */ #define PUBKEY_USAGE_ENC GCRY_PK_USAGE_ENCR /* Good for encryption. */ -#define PUBKEY_USAGE_CERT GCRY_PK_USAGE_CERT /* Also good to certify keys. */ +#define PUBKEY_USAGE_CERT GCRY_PK_USAGE_CERT /* Also good to certify keys.*/ #define PUBKEY_USAGE_AUTH GCRY_PK_USAGE_AUTH /* Good for authentication. */ #define PUBKEY_USAGE_UNKNOWN GCRY_PK_USAGE_UNKN /* Unknown usage flag. */ +#define PUBKEY_USAGE_NONE 256 /* No usage given. */ +#if (GCRY_PK_USAGE_SIGN | GCRY_PK_USAGE_ENCR | GCRY_PK_USAGE_CERT \ + | GCRY_PK_USAGE_AUTH | GCRY_PK_USAGE_UNKN) >= 256 +# error Please choose another value for PUBKEY_USAGE_NONE +#endif #define DIGEST_ALGO_MD5 /* 1 */ GCRY_MD_MD5 #define DIGEST_ALGO_SHA1 /* 2 */ GCRY_MD_SHA1 ----------------------------------------------------------------------- Summary of changes: doc/DETAILS | 1 + g10/getkey.c | 8 +++++++- g10/keygen.c | 3 --- g10/keylist.c | 3 +++ include/cipher.h | 7 ++++++- 5 files changed, 17 insertions(+), 5 deletions(-) hooks/post-receive -- The GNU Privacy Guard http://git.gnupg.org From cvs at cvs.gnupg.org Wed Mar 20 10:02:32 2013 From: cvs at cvs.gnupg.org (by Werner Koch) Date: Wed, 20 Mar 2013 10:02:32 +0100 Subject: [git] GnuPG - branch, key-storage-work, updated. gnupg-2.1.0beta3-174-gc664dd2 Message-ID: This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "The GNU Privacy Guard". The branch, key-storage-work has been updated via c664dd2c9eb2a93f13ba9534117fb28d90715f78 (commit) from 273bb38cd7b517460cb3de67662e96e910104675 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit c664dd2c9eb2a93f13ba9534117fb28d90715f78 Author: Werner Koch Date: Wed Mar 20 09:50:03 2013 +0100 po: Autoupdates for de and fr. Update gitignore. -- diff --git a/.gitignore b/.gitignore index b75b404..d3a576a 100644 --- a/.gitignore +++ b/.gitignore @@ -157,3 +157,4 @@ tools/gpgtar x.parm +private-keys-v1.d/ \ No newline at end of file diff --git a/po/de.po b/po/de.po index 190120f..4a92b96 100644 --- a/po/de.po +++ b/po/de.po @@ -12,6 +12,7 @@ msgstr "" "PO-Revision-Date: 2012-08-24 10:19+0200\n" "Last-Translator: Werner Koch \n" "Language-Team: German \n" +"Language: de\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" @@ -98,12 +99,14 @@ msgstr "Passphrase" msgid "ssh keys greater than %d bits are not supported\n" msgstr "SSH Schl?ssel von mehr als %d Bits werden nicht unterst?tzt\n" -#, c-format -msgid "can't create '%s': %s\n" +#, fuzzy, c-format +#| msgid "can't create '%s': %s\n" +msgid "can't create `%s': %s\n" msgstr "'%s' kann nicht erzeugt werden: %s\n" -#, c-format -msgid "can't open '%s': %s\n" +#, fuzzy, c-format +#| msgid "can't open '%s': %s\n" +msgid "can't open `%s': %s\n" msgstr "'%s' kann nicht ge?ffnet werden: %s\n" #, c-format @@ -135,8 +138,8 @@ msgid "" "An ssh process requested the use of key%%0A %s%%0A (%s)%%0ADo you want to " "allow this?" msgstr "" -"Ein SSH Processs m?chte folgenden Schl?ssel verwenden:%%0A %s%%0A (%s)%%" -"0AErlauben Sie dies?" +"Ein SSH Processs m?chte folgenden Schl?ssel verwenden:%%0A %s%%0A " +"(%s)%%0AErlauben Sie dies?" msgid "Allow" msgstr "Erlauben" @@ -147,16 +150,16 @@ msgstr "Verweigern" #, c-format msgid "Please enter the passphrase for the ssh key%%0A %F%%0A (%c)" msgstr "" -"Bitte geben Sie die Passphrase f?r den SSH-Schl?ssel%%0A %F%%0A (%c)%%" -"0Aein." +"Bitte geben Sie die Passphrase f?r den SSH-Schl?ssel%%0A %F%%0A " +"(%c)%%0Aein." msgid "Please re-enter this passphrase" msgstr "Bitte geben Sie die Passphrase noch einmal ein:" #, c-format msgid "" -"Please enter a passphrase to protect the received secret key%%0A %s%%0A %" -"s%%0Awithin gpg-agent's key storage" +"Please enter a passphrase to protect the received secret key%%0A %s%%0A " +"%s%%0Awithin gpg-agent's key storage" msgstr "" "Bitte geben Sie eine Passphrase ein, um den empfangenen geheimen\n" "Schl?ssel%%0A %s%%0A %s%%0Aim Schl?sselspeicher des Gpg-Agenten zu " @@ -188,8 +191,9 @@ msgstr "PUK" msgid "Reset Code" msgstr "R?ckstellcode" -#, c-format -msgid "%s%%0A%%0AUse the reader's keypad for input." +#, fuzzy, c-format +#| msgid "%s%%0A%%0AUse the reader's keypad for input." +msgid "%s%%0A%%0AUse the reader's pinpad for input." msgstr "%s%%0A%%0AZur Eingabe die Tastatur des Kartenlesers verwenden." msgid "Repeat this Reset Code" @@ -608,8 +612,9 @@ msgid "" "Do you ultimately trust%%0A \"%s\"%%0Ato correctly certify user " "certificates?" msgstr "" -"Wenn Sie vollst?ndiges Vertrauen haben, da?%%0A \"%s\"%%" -"0ABenutzerzertifikate verl??lich zertifiziert, so antworten Sie mit \"Ja\"." +"Wenn Sie vollst?ndiges Vertrauen haben, da?%%0A \"%s" +"\"%%0ABenutzerzertifikate verl??lich zertifiziert, so antworten Sie mit \"Ja" +"\"." msgid "Yes" msgstr "Ja" @@ -965,6 +970,10 @@ msgstr "Dirmngr benutzbar" msgid "No help available for '%s'." msgstr "Keine Hilfe f?r '%s' vorhanden." +#, c-format +msgid "can't open '%s': %s\n" +msgstr "'%s' kann nicht ge?ffnet werden: %s\n" + msgid "ignoring garbage line" msgstr "Zeile mit nicht identifizierten Zeichen wird ignoriert" @@ -1055,6 +1064,10 @@ msgid "error writing to '%s': %s\n" msgstr "Fehler beim Schreiben von %s: %s\n" #, c-format +msgid "can't create '%s': %s\n" +msgstr "'%s' kann nicht erzeugt werden: %s\n" + +#, c-format msgid "removing stale lockfile (created by %d)\n" msgstr "eine ?briggebliebene Sperrdatei wird entfernt (erzeugt von %d)\n" @@ -1157,6 +1170,15 @@ msgid "not human readable" msgstr "nicht als Klartext darstellbar" #, c-format +msgid "failed to proxy %s inquiry to client\n" +msgstr "Die %s \"inquiry\" konnte nicht an den Client weitergeleitet werden\n" + +#, fuzzy +#| msgid "Enter passphrase\n" +msgid "Enter passphrase: " +msgstr "Geben Sie die Passphrase ein\n" + +#, c-format msgid "OpenPGP card not available: %s\n" msgstr "OpenPGP Karte ist nicht vorhanden: %s\n" @@ -1359,6 +1381,14 @@ msgstr " (3) Authentisierungs-Schl?ssel\n" msgid "Invalid selection.\n" msgstr "Ung?ltige Auswahl.\n" +msgid "Please select where to store the key:\n" +msgstr "W?hlen Sie den Speicherort f?r den Schl?ssel:\n" + +#, fuzzy, c-format +#| msgid "read failed: %s\n" +msgid "KEYTOCARD failed: %s\n" +msgstr "Lesen schlug fehl: %s\n" + msgid "quit this menu" msgstr "Men? verlassen" @@ -1509,8 +1539,8 @@ msgstr "" msgid "" "WARNING: forcing symmetric cipher %s (%d) violates recipient preferences\n" msgstr "" -"WARNUNG: Erzwungene Verwendung des symmetrischen Verschl?sselungsverfahren %" -"s (%d) verletzt die Empf?ngervoreinstellungen\n" +"WARNUNG: Erzwungene Verwendung des symmetrischen Verschl?sselungsverfahren " +"%s (%d) verletzt die Empf?ngervoreinstellungen\n" #, c-format msgid "" @@ -1630,9 +1660,6 @@ msgstr " - ?bersprungen" msgid "WARNING: nothing exported\n" msgstr "WARNUNG: Nichts exportiert\n" -msgid "too many entries in pk cache - disabled\n" -msgstr "zu viele Eintr?ge im pk-Cache - abgeschaltet\n" - msgid "[User ID not found]" msgstr "[User-ID nicht gefunden]" @@ -1957,8 +1984,8 @@ msgstr "Hinweis: Alte voreingestellte Optionendatei '%s' wurde ignoriert\n" #, c-format msgid "libgcrypt is too old (need %s, have %s)\n" msgstr "" -"Die Bibliothek \"libgcrypt\" ist zu alt (ben?tigt wird %s, vorhanden ist %" -"s)\n" +"Die Bibliothek \"libgcrypt\" ist zu alt (ben?tigt wird %s, vorhanden ist " +"%s)\n" #, c-format msgid "NOTE: %s is not for normal use!\n" @@ -1968,6 +1995,11 @@ msgstr "Hinweis: %s ist nicht f?r den ?blichen Gebrauch gedacht!\n" msgid "'%s' is not a valid signature expiration\n" msgstr "`%s' ist kein g?ltiges Signaturablaufdatum\n" +#, fuzzy, c-format +#| msgid "Invalid subject name '%s'\n" +msgid "invalid pinentry mode '%s'\n" +msgstr "Ung?ltiger Subjekt-Name `%s'\n" + #, c-format msgid "'%s' is not a valid character set\n" msgstr "`%s' ist kein g?ltiger Zeichensatz\n" @@ -2658,10 +2690,18 @@ msgid "key %s: direct key signature added\n" msgstr "Schl?ssel %s: \"direct-key\"-Signaturen hinzugef?gt\n" #, c-format +msgid "error creating keybox '%s': %s\n" +msgstr "Die \"Keybox\" `%s' konnte nicht erstellt werden: %s\n" + +#, c-format msgid "error creating keyring '%s': %s\n" msgstr "Fehler beim Erzeugen des Schl?sselbundes `%s': %s\n" #, c-format +msgid "keybox '%s' created\n" +msgstr "Die \"Keybox\" `%s' wurde erstellt\n" + +#, c-format msgid "keyring '%s' created\n" msgstr "Schl?sselbund `%s' erstellt\n" @@ -5272,8 +5312,8 @@ msgstr "%d marginal-needed, %d complete-needed, %s Vertrauensmodell\n" msgid "" "depth: %d valid: %3d signed: %3d trust: %d-, %dq, %dn, %dm, %df, %du\n" msgstr "" -"Tiefe: %d g?ltig: %3d signiert: %3d Vertrauen: %d-, %dq, %dn, %dm, %df, %" -"du\n" +"Tiefe: %d g?ltig: %3d signiert: %3d Vertrauen: %d-, %dq, %dn, %dm, %df, " +"%du\n" #, c-format msgid "unable to update trustdb version record: write failed: %s\n" @@ -5528,7 +5568,9 @@ msgstr "" msgid "can't access %s - invalid OpenPGP card?\n" msgstr "Kann auf %s nicht zugreifen - ung?ltige OpenPGP-Karte?\n" -msgid "||Please enter your PIN at the reader's keypad" +#, fuzzy +#| msgid "||Please enter your PIN at the reader's keypad" +msgid "||Please enter your PIN at the reader's pinpad" msgstr "||Bitte die PIN auf der Tastatur des Kartenlesers eingeben" #. TRANSLATORS: Do not translate the "|*|" prefixes but @@ -5561,12 +5603,17 @@ msgstr "Den internen CCID Treiber nicht benutzen" msgid "|N|disconnect the card after N seconds of inactivity" msgstr "|N|Schalte die Karte nach N Sekunden Inaktivit?t ab" -msgid "do not use a reader's keypad" +#, fuzzy +#| msgid "do not use a reader's keypad" +msgid "do not use a reader's pinpad" msgstr "Die Tastatur des Kartenlesers nicht benutzen" msgid "deny the use of admin card commands" msgstr "Verweigere die Benutzung von \"Admin\"-Befehlen" +msgid "use variable length input for pinpad" +msgstr "" + msgid "Usage: scdaemon [options] (-h for help)" msgstr "Aufruf: scdaemon [Optionen] (-h f?r Hilfe)" @@ -5595,10 +5642,6 @@ msgid "invalid radix64 character %02x skipped\n" msgstr "Ung?ltiges Basis-64 Zeichen %02X wurde ?bersprungen\n" #, c-format -msgid "failed to proxy %s inquiry to client\n" -msgstr "Die %s \"inquiry\" konnte nicht an den Client weitergeleitet werden\n" - -#, c-format msgid "validation model requested by certificate: %s" msgstr "Durch Zertifikat angefordertes G?ltigkeitsmodell: %s" @@ -6213,17 +6256,9 @@ msgstr "Fehler beim Importieren des Zertifikats: %s\n" msgid "error reading input: %s\n" msgstr "Fehler beim Lesen der Eingabe: %s\n" -#, c-format -msgid "error creating keybox '%s': %s\n" -msgstr "Die \"Keybox\" `%s' konnte nicht erstellt werden: %s\n" - msgid "you may want to start the gpg-agent first\n" msgstr "Sie sollten zuerst den gpg-agent starten\n" -#, c-format -msgid "keybox '%s' created\n" -msgstr "Die \"Keybox\" `%s' wurde erstellt\n" - msgid "failed to get the fingerprint\n" msgstr "Kann den Fingerprint nicht ermitteln\n" @@ -6339,8 +6374,8 @@ msgstr "Dies ist eine qualifizierte Signatur.\n" #, c-format msgid "can't initialize certificate cache lock: %s\n" msgstr "" -"Sperre f?r den Zertifikatzwischenspeicher kann nicht initialisiert werden: %" -"s\n" +"Sperre f?r den Zertifikatzwischenspeicher kann nicht initialisiert werden: " +"%s\n" #, c-format msgid "can't acquire read lock on the certificate cache: %s\n" @@ -6350,8 +6385,8 @@ msgstr "" #, c-format msgid "can't acquire write lock on the certificate cache: %s\n" msgstr "" -"Schreibsperre f?r den Zertifikatzwischenspeicher kann nicht gesetzt werden: %" -"s\n" +"Schreibsperre f?r den Zertifikatzwischenspeicher kann nicht gesetzt werden: " +"%s\n" #, c-format msgid "can't release lock on the certificate cache: %s\n" @@ -7949,6 +7984,9 @@ msgstr "" "Syntax: gpg-check-pattern [optionen] Musterdatei\n" "Die von stdin gelesene Passphrase gegen die Musterdatei pr?fen\n" +#~ msgid "too many entries in pk cache - disabled\n" +#~ msgstr "zu viele Eintr?ge im pk-Cache - abgeschaltet\n" + #~ msgid "failed to allocated keyDB handle\n" #~ msgstr "Ein keyDB Handle konnte nicht bereitgestellt werden\n" @@ -8095,9 +8133,6 @@ msgstr "" #~ msgid "can't fdopen pipe for reading: %s\n" #~ msgstr "Pipe kann nicht zum Lesen \"fdopen\"t werden: %s\n" -#~ msgid "Please select where to store the key:\n" -#~ msgstr "W?hlen Sie den Speicherort f?r den Schl?ssel:\n" - #~ msgid "secret key already stored on a card\n" #~ msgstr "Geheimer Schl?ssel ist bereits auf einer Karte gespeichert\n" diff --git a/po/fr.po b/po/fr.po index 5d8f13c..9e58e19 100644 --- a/po/fr.po +++ b/po/fr.po @@ -10,10 +10,10 @@ msgstr "" "PO-Revision-Date: 2012-08-21 15:44-0400\n" "Last-Translator: David Pr?vot \n" "Language-Team: French \n" +"Language: fr\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8-bit\n" -"Language: fr\n" "Plural-Forms: nplurals=2; plural=(n > 1);\n" "X-Generator: Lokalize 1.4\n" @@ -97,12 +97,14 @@ msgstr "Phrase de passe" msgid "ssh keys greater than %d bits are not supported\n" msgstr "les clefs SSH plus grandes que %d?bits ne sont pas prises en charge\n" -#, c-format -msgid "can't create '%s': %s\n" +#, fuzzy, c-format +#| msgid "can't create '%s': %s\n" +msgid "can't create `%s': %s\n" msgstr "impossible de cr?er ??%s???: %s\n" -#, c-format -msgid "can't open '%s': %s\n" +#, fuzzy, c-format +#| msgid "can't open '%s': %s\n" +msgid "can't open `%s': %s\n" msgstr "impossible d'ouvrir ??%s???: %s\n" #, c-format @@ -152,11 +154,11 @@ msgstr "Veuillez r?p?ter cette phrase de passe" #, c-format msgid "" -"Please enter a passphrase to protect the received secret key%%0A %s%%0A %" -"s%%0Awithin gpg-agent's key storage" +"Please enter a passphrase to protect the received secret key%%0A %s%%0A " +"%s%%0Awithin gpg-agent's key storage" msgstr "" -"Veuillez entrer une phrase de passe pour prot?ger la clef secr?te%%0A %s%%" -"0A %s%%0Are?ue dans l'espace de stockage de clefs de gpg-agent" +"Veuillez entrer une phrase de passe pour prot?ger la clef secr?te%%0A %s" +"%%0A %s%%0Are?ue dans l'espace de stockage de clefs de gpg-agent" msgid "does not match - try again" msgstr "ne correspond pas ? veuillez r?essayer" @@ -182,8 +184,9 @@ msgstr "CDP" msgid "Reset Code" msgstr "Code de r?initialisation" -#, c-format -msgid "%s%%0A%%0AUse the reader's keypad for input." +#, fuzzy, c-format +#| msgid "%s%%0A%%0AUse the reader's keypad for input." +msgid "%s%%0A%%0AUse the reader's pinpad for input." msgstr "%s%%0A%%0AUtilisez le pav? num?rique du lecteur en entr?e." msgid "Repeat this Reset Code" @@ -274,8 +277,8 @@ msgid "" "You have not entered a passphrase - this is in general a bad idea!%0APlease " "confirm that you do not want to have any protection on your key." msgstr "" -"Aucune phrase de passe n'a ?t? entr?e ? c'est souvent une mauvaise id?e.%" -"0AVeuillez confirmer que vous ne voulez aucune protection pour la clef." +"Aucune phrase de passe n'a ?t? entr?e ? c'est souvent une mauvaise id?e." +"%0AVeuillez confirmer que vous ne voulez aucune protection pour la clef." msgid "Yes, protection is not needed" msgstr "Oui, aucune protection n'est n?cessaire" @@ -965,6 +968,10 @@ msgstr "Dirmngr utilisable" msgid "No help available for '%s'." msgstr "Pas d'aide disponible pour ??%s??." +#, c-format +msgid "can't open '%s': %s\n" +msgstr "impossible d'ouvrir ??%s???: %s\n" + msgid "ignoring garbage line" msgstr "ligne inutile ignor?e" @@ -1055,6 +1062,10 @@ msgid "error writing to '%s': %s\n" msgstr "erreur d'?criture sur ??%s???: %s\n" #, c-format +msgid "can't create '%s': %s\n" +msgstr "impossible de cr?er ??%s???: %s\n" + +#, c-format msgid "removing stale lockfile (created by %d)\n" msgstr "suppression du vieux fichier verrou (cr?? par %d)\n" @@ -1157,6 +1168,13 @@ msgid "not human readable" msgstr "non lisible par l'utilisateur" #, c-format +msgid "failed to proxy %s inquiry to client\n" +msgstr "?chec de transfert de la demande %s au client\n" + +msgid "Enter passphrase: " +msgstr "Entrez la phrase de passe?: " + +#, c-format msgid "OpenPGP card not available: %s\n" msgstr "la carte OpenPGP n'est pas disponible?: %s\n" @@ -1359,6 +1377,14 @@ msgstr " (3) Clef d'authentification\n" msgid "Invalid selection.\n" msgstr "Choix incorrect.\n" +msgid "Please select where to store the key:\n" +msgstr "Veuillez s?lectionner l'endroit o? stocker la clef?:\n" + +#, fuzzy, c-format +#| msgid "read failed: %s\n" +msgid "KEYTOCARD failed: %s\n" +msgstr "?chec de read?: %s\n" + msgid "quit this menu" msgstr "quitter ce menu" @@ -1466,7 +1492,8 @@ msgid "there is a secret key for public key \"%s\"!\n" msgstr "il y a une clef secr?te pour la clef publique ??%s??.\n" msgid "use option \"--delete-secret-keys\" to delete it first.\n" -msgstr "utiliser d'abord l'option ??--delete-secret-keys?? pour la supprimer.\n" +msgstr "" +"utiliser d'abord l'option ??--delete-secret-keys?? pour la supprimer.\n" #, c-format msgid "error creating passphrase: %s\n" @@ -1631,9 +1658,6 @@ msgstr " ? ignor?" msgid "WARNING: nothing exported\n" msgstr "Attention?: rien n'a ?t? export?\n" -msgid "too many entries in pk cache - disabled\n" -msgstr "trop d'entr?es dans le cache de clefs publiques ? d?sactiv?\n" - msgid "[User ID not found]" msgstr "[identit? introuvable]" @@ -1989,6 +2013,11 @@ msgstr "Remarque?: %s n'est pas pour une utilisation normale.\n" msgid "'%s' is not a valid signature expiration\n" msgstr "??%s?? n'est pas une date d'expiration de signature valable\n" +#, fuzzy, c-format +#| msgid "Invalid subject name '%s'\n" +msgid "invalid pinentry mode '%s'\n" +msgstr "Nom de sujet ??%s?? incorrect\n" + #, c-format msgid "'%s' is not a valid character set\n" msgstr "??%s?? n'est pas un jeu de caract?res valable\n" @@ -2667,10 +2696,18 @@ msgid "key %s: direct key signature added\n" msgstr "clef %s?: ajout de la signature directe de clef\n" #, c-format +msgid "error creating keybox '%s': %s\n" +msgstr "erreur de cr?ation du trousseau local ??%s???: %s\n" + +#, c-format msgid "error creating keyring '%s': %s\n" msgstr "erreur de cr?ation du porte-clefs ??%s???: %s\n" #, c-format +msgid "keybox '%s' created\n" +msgstr "le trousseau local ??%s?? a ?t? cr??\n" + +#, c-format msgid "keyring '%s' created\n" msgstr "le porte-clefs ??%s?? a ?t? cr??\n" @@ -5578,7 +5615,9 @@ msgid "can't access %s - invalid OpenPGP card?\n" msgstr "" "impossible d'acc?der ? %s ? la carte OpenPGP n'est peut-?tre pas valable\n" -msgid "||Please enter your PIN at the reader's keypad" +#, fuzzy +#| msgid "||Please enter your PIN at the reader's keypad" +msgid "||Please enter your PIN at the reader's pinpad" msgstr "" "||Veuillez entrer votre code personnel sur le pav? num?rique du lecteur" @@ -5612,12 +5651,17 @@ msgstr "ne pas utiliser le pilote CCID interne" msgid "|N|disconnect the card after N seconds of inactivity" msgstr "|N|d?connecter la carte apr?s N?secondes d'inactivit? " -msgid "do not use a reader's keypad" +#, fuzzy +#| msgid "do not use a reader's keypad" +msgid "do not use a reader's pinpad" msgstr "ne pas utiliser de pav? num?rique du lecteur" msgid "deny the use of admin card commands" msgstr "refus d'utiliser les commandes d'administration de la carte" +msgid "use variable length input for pinpad" +msgstr "" + msgid "Usage: scdaemon [options] (-h for help)" msgstr "Utilisation?: scdaemon [options] (-h pour l'aide)" @@ -5646,10 +5690,6 @@ msgid "invalid radix64 character %02x skipped\n" msgstr "caract?re %02x incorrect en radix64, ignor?\n" #, c-format -msgid "failed to proxy %s inquiry to client\n" -msgstr "?chec de transfert de la demande %s au client\n" - -#, c-format msgid "validation model requested by certificate: %s" msgstr "mod?le de validation demand? par le certificat?: %s" @@ -6278,17 +6318,9 @@ msgstr "erreur d'importation du certificat?: %s\n" msgid "error reading input: %s\n" msgstr "erreur de lecture de l'entr?e?: %s\n" -#, c-format -msgid "error creating keybox '%s': %s\n" -msgstr "erreur de cr?ation du trousseau local ??%s???: %s\n" - msgid "you may want to start the gpg-agent first\n" msgstr "vous pourriez d'abord d?marrer l'agent GPG\n" -#, c-format -msgid "keybox '%s' created\n" -msgstr "le trousseau local ??%s?? a ?t? cr??\n" - msgid "failed to get the fingerprint\n" msgstr "impossible d'obtenir l'empreinte\n" @@ -6696,8 +6728,8 @@ msgstr "" #, c-format msgid "problem reading cache record for S/N %s: %s\n" msgstr "" -"probl?me de lecture d'enregistrement de cache pour le num?ro de s?rie %s?: %" -"s\n" +"probl?me de lecture d'enregistrement de cache pour le num?ro de s?rie %s?: " +"%s\n" #, c-format msgid "S/N %s is not valid; reason=%02X date=%.15s\n" @@ -6745,8 +6777,8 @@ msgstr "" #, c-format msgid "update times of this CRL: this=%s next=%s\n" msgstr "" -"dates de mises ? jour de la liste de r?vocations de certificats?: celle-ci=%" -"s prochaine=%s\n" +"dates de mises ? jour de la liste de r?vocations de certificats?: celle-ci=" +"%s prochaine=%s\n" msgid "nextUpdate not given; assuming a validity period of one day\n" msgstr "nextUpdate non donn??; p?riode de validit? suppos?e d'un jour\n" @@ -6774,8 +6806,8 @@ msgstr "" #, c-format msgid "CRL signature verification failed: %s\n" msgstr "" -"?chec de v?rification de signature de liste de r?vocations de certificats?: %" -"s\n" +"?chec de v?rification de signature de liste de r?vocations de certificats?: " +"%s\n" #, c-format msgid "error checking validity of CRL issuer certificate: %s\n" @@ -6836,8 +6868,8 @@ msgstr "" #, c-format msgid "error reading CRL extensions: %s\n" msgstr "" -"erreur de lecture des extensions de liste de r?vocations de certificats?: %" -"s\n" +"erreur de lecture des extensions de liste de r?vocations de certificats?: " +"%s\n" #, c-format msgid "creating cache file '%s'\n" @@ -6857,8 +6889,8 @@ msgstr "" #, c-format msgid "Begin CRL dump (retrieved via %s)\n" msgstr "" -"D?marrage du vidage de liste de r?vocations de certificats (r?cup?r?e par %" -"s)\n" +"D?marrage du vidage de liste de r?vocations de certificats (r?cup?r?e par " +"%s)\n" msgid "" " ERROR: The CRL will not be used because it was still too old after an " @@ -7196,7 +7228,8 @@ msgstr "les deux-points ne sont pas permis avec dans le nom de socket\n" #, c-format msgid "fetching CRL from '%s' failed: %s\n" msgstr "" -"?chec de r?cup?ration de liste de r?vocations de certificats sur ??%s???: %s\n" +"?chec de r?cup?ration de liste de r?vocations de certificats sur ??%s???: " +"%s\n" #, c-format msgid "processing CRL from '%s' failed: %s\n" @@ -8060,15 +8093,15 @@ msgstr "" "V?rifier une phrase de passe donn?e sur l'entr?e standard par rapport ? " "ficmotif\n" +#~ msgid "too many entries in pk cache - disabled\n" +#~ msgstr "trop d'entr?es dans le cache de clefs publiques ? d?sactiv?\n" + #~ msgid "failed to allocated keyDB handle\n" #~ msgstr "impossible d'allouer la gestion de base de clefs\n" #~ msgid "can't fdopen pipe for reading: %s\n" #~ msgstr "impossible d'ouvrir un tube en lecture avec fdopen?: %s\n" -#~ msgid "Please select where to store the key:\n" -#~ msgstr "Veuillez s?lectionner l'endroit o? stocker la clef?:\n" - #~ msgid "unknown key protection algorithm\n" #~ msgstr "algorithme de protection de clef inconnu\n" @@ -8704,9 +8737,6 @@ msgstr "" #~ msgid "can't query passphrase in batch mode\n" #~ msgstr "impossible de demander la phrase de passe en mode automatique\n" -#~ msgid "Enter passphrase: " -#~ msgstr "Entrez la phrase de passe?: " - #~ msgid "Repeat passphrase: " #~ msgstr "R?p?tez la phrase de passe?: " ----------------------------------------------------------------------- Summary of changes: .gitignore | 1 + po/de.po | 123 +++++++++++++++++++++++++++++++++++++--------------------- po/fr.po | 126 +++++++++++++++++++++++++++++++++++++----------------------- 3 files changed, 158 insertions(+), 92 deletions(-) hooks/post-receive -- The GNU Privacy Guard http://git.gnupg.org From cvs at cvs.gnupg.org Wed Mar 20 10:10:43 2013 From: cvs at cvs.gnupg.org (by Werner Koch) Date: Wed, 20 Mar 2013 10:10:43 +0100 Subject: [git] GnuPG - branch, key-storage-work, updated. gnupg-2.1.0beta3-176-g2739834 Message-ID: This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "The GNU Privacy Guard". The branch, key-storage-work has been updated via 2739834206f23833161898a73427b8a9c6d5d26d (commit) via 44159b681f8f09000fabfc3ee294d5821578d3a6 (commit) from c664dd2c9eb2a93f13ba9534117fb28d90715f78 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 2739834206f23833161898a73427b8a9c6d5d26d Author: Werner Koch Date: Fri Dec 28 19:26:59 2012 +0100 Add code to allow for late memory cleanup. * common/init.c (mem_cleanup_item_t): New. (run_mem_cleanup): New. (_init_common_subsystems): Add an atexit for it. (register_mem_cleanup_func): New. * g10/kbnode.c (cleanup_registered): New. (release_unused_nodes): New. (alloc_node): Call register_mem_cleanup_func. -- It is often time consuming to figure out whether still allocated memory at process termination is fine (e.g. a cache) or a problem. To help for that register_mem_cleanup_func may now be used to cleanup such memory. The run time of the program will be longer; if that turns out to be a problem we can change the code to only run in debugging mode. diff --git a/common/init.c b/common/init.c index e00b9b3..8a0b6a8 100644 --- a/common/init.c +++ b/common/init.c @@ -46,6 +46,21 @@ #include "util.h" +/* This object is used to register memory cleanup functions. + Technically they are not needed but they can avoid frequent + questions about un-released memory. Note that we use the system + malloc and not any wrappers. */ +struct mem_cleanup_item_s; +typedef struct mem_cleanup_item_s *mem_cleanup_item_t; + +struct mem_cleanup_item_s +{ + mem_cleanup_item_t next; + void (*func) (void); +}; + +static mem_cleanup_item_t mem_cleanup_list; + /* The default error source of the application. This is different from GPG_ERR_SOURCE_DEFAULT in that it does not depend on the @@ -65,6 +80,36 @@ sleep_on_exit (void) #endif /*HAVE_W32CE_SYSTEM*/ +static void +run_mem_cleanup (void) +{ + mem_cleanup_item_t next; + + while (mem_cleanup_list) + { + next = mem_cleanup_list->next; + mem_cleanup_list->func (); + free (mem_cleanup_list); + mem_cleanup_list = next; + } +} + + +void +register_mem_cleanup_func (void (*func)(void)) +{ + mem_cleanup_item_t item; + + item = malloc (sizeof *item); + if (item) + { + item->func = func; + item->next = mem_cleanup_list; + mem_cleanup_list = item; + } +} + + /* If STRING is not NULL write string to es_stdout or es_stderr. MODE must be 1 or 2. If STRING is NULL flush the respective stream. */ static int @@ -100,6 +145,8 @@ _init_common_subsystems (gpg_err_source_t errsource, int *argcp, char ***argvp) /* Store the error source in a gloabl variable. */ default_errsource = errsource; + atexit (run_mem_cleanup); + /* Try to auto set the character set. */ set_native_charset (NULL); diff --git a/common/init.h b/common/init.h index 633ffac..eea2eb1 100644 --- a/common/init.h +++ b/common/init.h @@ -36,6 +36,8 @@ # error GPG_ERR_SOURCE_DEFAULT has default value #endif +void register_mem_cleanup_func (void (*func)(void)); + void _init_common_subsystems (gpg_err_source_t errsource, int *argcp, char ***argvp); #define init_common_subsystems(a,b) \ diff --git a/g10/kbnode.c b/g10/kbnode.c index 1a8b91e..d490740 100644 --- a/g10/kbnode.c +++ b/g10/kbnode.c @@ -31,35 +31,58 @@ #define USE_UNUSED_NODES 1 +static int cleanup_registered; static KBNODE unused_nodes; -static KBNODE -alloc_node(void) +#if USE_UNUSED_NODES +static void +release_unused_nodes (void) { - KBNODE n; + while (unused_nodes) + { + kbnode_t next = unused_nodes->next; + xfree (unused_nodes); + unused_nodes = next; + } +} +#endif /*USE_UNUSED_NODES*/ - n = unused_nodes; - if( n ) - unused_nodes = n->next; - else - n = xmalloc( sizeof *n ); - n->next = NULL; - n->pkt = NULL; - n->flag = 0; - n->private_flag=0; - n->recno = 0; - return n; + +static kbnode_t +alloc_node (void) +{ + kbnode_t n; + + n = unused_nodes; + if (n) + unused_nodes = n->next; + else + { + if (!cleanup_registered) + { + cleanup_registered = 1; + register_mem_cleanup_func (release_unused_nodes); + } + n = xmalloc (sizeof *n); + } + n->next = NULL; + n->pkt = NULL; + n->flag = 0; + n->private_flag=0; + n->recno = 0; + return n; } static void free_node( KBNODE n ) { - if( n ) { + if (n) + { #if USE_UNUSED_NODES - n->next = unused_nodes; - unused_nodes = n; + n->next = unused_nodes; + unused_nodes = n; #else - xfree( n ); + xfree (n); #endif } } commit 44159b681f8f09000fabfc3ee294d5821578d3a6 Author: Werner Koch Date: Fri Dec 28 17:28:43 2012 +0100 kbx: Remove unused macro. * kbx/keybox.h (KEYBOX_WITH_OPENPGP): Remove unused macro. diff --git a/kbx/keybox.h b/kbx/keybox.h index 4f7e23d..5b29437 100644 --- a/kbx/keybox.h +++ b/kbx/keybox.h @@ -29,15 +29,9 @@ extern "C" { #include "../common/iobuf.h" #include "keybox-search-desc.h" -#define KEYBOX_WITH_OPENPGP 1 #define KEYBOX_WITH_X509 1 -#ifdef KEYBOX_WITH_OPENPGP -# undef KEYBOX_WITH_OPENPGP -/*#include */ -#endif - #ifdef KEYBOX_WITH_X509 # include #endif ----------------------------------------------------------------------- Summary of changes: common/init.c | 47 +++++++++++++++++++++++++++++++++++++++++++ common/init.h | 2 + g10/kbnode.c | 61 +++++++++++++++++++++++++++++++++++++++----------------- kbx/keybox.h | 6 ----- 4 files changed, 91 insertions(+), 25 deletions(-) hooks/post-receive -- The GNU Privacy Guard http://git.gnupg.org From cvs at cvs.gnupg.org Wed Mar 20 10:27:25 2013 From: cvs at cvs.gnupg.org (by Werner Koch) Date: Wed, 20 Mar 2013 10:27:25 +0100 Subject: [git] GnuPG - branch, key-storage-work, updated. gnupg-2.1.0beta3-196-geaa6dc3 Message-ID: This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "The GNU Privacy Guard". The branch, key-storage-work has been updated via eaa6dc3a8b4f31525650cd4785d6bafab86d68b7 (commit) via c4dbd1b2de8ae3847a040444e86500848868bcf4 (commit) via b693ec02c467696bf9d7324dd081e279f9965151 (commit) via 4bde12206c5bf199dc6e12a74af8da4558ba41bf (commit) via 76dc5c08dc2686eef32e1bd221c60fe91201246f (commit) via 006782068e4d2a9413770400494421a2e9726ee7 (commit) via 73ad742deacfe2bf7d6efc7cc30f9ced2d83521a (commit) via 010bc7f4f06d8affb98950e1adc76c68bfcc9abb (commit) via 5132ea8a0d8517dd43cb5b4a4b0921c3b1ca291c (commit) via 5bac5040dc93343e1e89916b263390b0e52040bf (commit) via ef1983d58b913306e9bf02a7189e530123839c59 (commit) via 585d5c62eece23911a768d97d11f159be138b13d (commit) via c6b8f05517228c6aeab28d2bf5da7724c059bb1a (commit) via 161674118d568025896026ede5e03d26bdfdfa68 (commit) via baee681d2406530c45fd6d4bde77193ba23ac263 (commit) via 2838385e76c8c7108bc949d5a1d1c947051bd5be (commit) via 21f5a9ec27c0794141a835a5bb3c69495ee554a6 (commit) via 3c3648e720b8014828573bd708c88ba4775014e3 (commit) via 7d376ffa321d4af6e62a2bc64ef2b8574b122b1a (commit) via c36089daf76d53a1d1912f58f284b78bafe14508 (commit) from 2739834206f23833161898a73427b8a9c6d5d26d (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit eaa6dc3a8b4f31525650cd4785d6bafab86d68b7 Merge: 2739834 c4dbd1b Author: Werner Koch Date: Wed Mar 20 10:00:12 2013 +0100 Merge branch 'master' into key-storage-work -- diff --cc .gitignore index d3a576a,b75b404..6502072 --- a/.gitignore +++ b/.gitignore @@@ -154,7 -154,6 +154,5 @@@ tools/mk-tdat tools/symcryptrun tools/watchgnupg tools/gpgtar -- -- ++private-keys-v1.d/ x.parm - private-keys-v1.d/ ----------------------------------------------------------------------- Summary of changes: .gitignore | 4 +- agent/agent.h | 3 +- agent/call-pinentry.c | 9 +- agent/call-scd.c | 53 ++------ agent/command-ssh.c | 2 + agent/command.c | 1 + agent/divert-scd.c | 8 +- agent/findkey.c | 2 +- agent/pksign.c | 92 +++++++++++- common/util.h | 10 -- configure.ac | 2 +- doc/DETAILS | 1 + doc/gpg.texi | 4 +- g10/call-agent.c | 22 ++-- g10/call-dirmngr.c | 4 +- g10/card-util.c | 6 +- g10/getkey.c | 8 +- g10/keygen.c | 3 - g10/keylist.c | 3 + g13/g13.c | 18 ++-- include/cipher.h | 7 +- scd/app-openpgp.c | 379 ++++++++++++++++++++++++++++++++++++------------- scd/ccid-driver.c | 2 +- sm/call-agent.c | 28 ++-- sm/call-dirmngr.c | 64 ++++----- tools/gpgconf-comp.c | 6 - 26 files changed, 482 insertions(+), 259 deletions(-) hooks/post-receive -- The GNU Privacy Guard http://git.gnupg.org From cvs at cvs.gnupg.org Wed Mar 20 10:33:43 2013 From: cvs at cvs.gnupg.org (by Werner Koch) Date: Wed, 20 Mar 2013 10:33:43 +0100 Subject: [git] GnuPG - branch, master, updated. gnupg-2.1.0beta3-196-geaa6dc3 Message-ID: This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "The GNU Privacy Guard". The branch, master has been updated via eaa6dc3a8b4f31525650cd4785d6bafab86d68b7 (commit) via 2739834206f23833161898a73427b8a9c6d5d26d (commit) via 44159b681f8f09000fabfc3ee294d5821578d3a6 (commit) via c664dd2c9eb2a93f13ba9534117fb28d90715f78 (commit) via 273bb38cd7b517460cb3de67662e96e910104675 (commit) via 18a261b65fd77a9e434b13483ceaaaf2176f1197 (commit) via 4af0c62b15c51056dc293c8e3b907e7c41fbf08c (commit) via 8e5766c38f3ac376fb8e7c7f2b0f65de23d84cbe (commit) via 7ab61423f0066c89130d1d1e6a5b429cff188b97 (commit) via caddeef4a7ffe5f2eb6453d364b6ae152e0f6625 (commit) via b11f84b858bad867f1062977a7aba30299157e90 (commit) via bbcdb3d3cefa06b2bff367054c6518f611d7abb7 (commit) via 492792378dc7a79316ef742b2ffaa46c6cda282a (commit) via 5c565512b8af73bee2a176530663154b9277ef1c (commit) via f3f5721e6843a08d1011875400f385b8cd5fe226 (commit) via f6d7b3f1ee5eed32bc3257c99cb878091d26c482 (commit) via 0baedfd25a4bdc6c8e7aefbd67006b063e2dc33f (commit) via fb31462e7e92d4b19256e6fd40b1b6ffcef2676c (commit) via 7d00e52bd58d9e40c18dcc0122b2c236ef3318f5 (commit) via 79f08fb0699f4a065e3a29bc7676a90534d7ba60 (commit) via 564d10ea5cd29685a00a4096d69ae2476b60506f (commit) via a9863834244fc2a58d8950977243702d12e420a1 (commit) via f7495f1004071a0ceac394007bb37f88d7a3467f (commit) via 91e61d52539b1808e209c43e51465c76cebb06f9 (commit) from c4dbd1b2de8ae3847a040444e86500848868bcf4 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- ----------------------------------------------------------------------- Summary of changes: .gitignore | 3 +- common/init.c | 47 ++++ common/init.h | 2 + common/iobuf.c | 5 +- common/logging.c | 27 ++ common/logging.h | 2 + g10/Makefile.am | 11 +- g10/delkey.c | 2 +- g10/export.c | 2 +- g10/getkey.c | 35 ++- g10/gpg.c | 22 +- g10/gpgv.c | 7 +- g10/kbnode.c | 61 +++-- g10/keydb.c | 705 ++++++++++++++++++++++++++++++++++++++++++++------ g10/keydb.h | 16 +- g10/keyserver.c | 2 +- g10/options.h | 2 + g10/pubkey-enc.c | 10 + g10/revoke.c | 4 +- g10/trustdb.c | 5 +- kbx/kbxutil.c | 42 +++- kbx/keybox-blob.c | 481 +++++++++++++++++----------------- kbx/keybox-defs.h | 11 +- kbx/keybox-dump.c | 136 ++++++++-- kbx/keybox-file.c | 2 +- kbx/keybox-init.c | 17 ++ kbx/keybox-openpgp.c | 2 + kbx/keybox-search.c | 171 ++++++++++--- kbx/keybox-update.c | 62 +++++- kbx/keybox.h | 28 ++- po/de.po | 123 ++++++--- po/fr.po | 126 ++++++---- 32 files changed, 1614 insertions(+), 557 deletions(-) hooks/post-receive -- The GNU Privacy Guard http://git.gnupg.org From cvs at cvs.gnupg.org Wed Mar 20 13:25:13 2013 From: cvs at cvs.gnupg.org (by Ulrich Müller) Date: Wed, 20 Mar 2013 13:25:13 +0100 Subject: [git] GCRYPT - branch, LIBGCRYPT-1-5-BRANCH, updated. libgcrypt-1.5.1-5-g4f57ad0 Message-ID: This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "The GNU crypto library". The branch, LIBGCRYPT-1-5-BRANCH has been updated via 4f57ad0f8744263c917b3f16d84c2e5204893422 (commit) via 0fb5e52d417d5430ce8abf9af2ce1cd6b2bfa8b8 (commit) via 8ff4025e3698822c47199d9172153bc378f7bd32 (commit) from 8160f3b81e976d0568cc65260c29cc3d0f76fcc9 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 4f57ad0f8744263c917b3f16d84c2e5204893422 Author: Ulrich M?ller Date: Thu Feb 16 21:58:52 2012 +0100 Rework selftest in idea.c. * cipher/idea.c (do_setkey): Execute selftest when first called. (decrypt_block): Remove commented-out code. (selftest): Execute all selftests. Return NULL on success, or string in case of error. diff --git a/cipher/idea.c b/cipher/idea.c index fe14b21..39c9720 100644 --- a/cipher/idea.c +++ b/cipher/idea.c @@ -63,6 +63,8 @@ typedef struct { int have_dk; } IDEA_context; +static const char *selftest(void); + static u16 mul_inv( u16 x ) @@ -236,14 +238,18 @@ cipher( byte *outbuf, const byte *inbuf, u16 *key ) static int do_setkey( IDEA_context *c, const byte *key, unsigned int keylen ) { -#if 0 static int initialized = 0; + static const char *selftest_failed = 0; if( !initialized ) { initialized = 1; - selftest(0); + selftest_failed = selftest(); + if( selftest_failed ) + log_error( "%s\n", selftest_failed ); } -#endif + if( selftest_failed ) + return GPG_ERR_SELFTEST_FAILED; + assert(keylen == 16); c->have_dk = 0; expand_key( key, c->ek ); @@ -277,14 +283,6 @@ idea_encrypt (void *context, byte *out, const byte *in) static void decrypt_block( IDEA_context *c, byte *outbuf, const byte *inbuf ) { -#if 0 - static int initialized; - - if( !initialized ) { - initialized = 1; - selftest(1); - } -#endif if( !c->have_dk ) { c->have_dk = 1; invert_key( c->ek, c->dk ); @@ -301,9 +299,8 @@ idea_decrypt (void *context, byte *out, const byte *in) } -#if 0 -static void -selftest( int check_decrypt ) +static const char * +selftest( void ) { static struct { byte key[16]; @@ -361,19 +358,16 @@ static struct { for(i=0; i < DIM(test_vectors); i++ ) { do_setkey( &c, test_vectors[i].key, 16 ); - if( !check_decrypt ) { - encrypt_block( &c, buffer, test_vectors[i].plain ); - if( memcmp( buffer, test_vectors[i].cipher, 8 ) ) - g10_log_fatal("idea encryption (%d) failed\n", i); - } - else { - decrypt_block( &c, buffer, test_vectors[i].cipher ); - if( memcmp( buffer, test_vectors[i].plain, 8 ) ) - g10_log_fatal("idea decryption (%d) failed\n", i); - } + encrypt_block( &c, buffer, test_vectors[i].plain ); + if( memcmp( buffer, test_vectors[i].cipher, 8 ) ) + return "IDEA test encryption failed."; + decrypt_block( &c, buffer, test_vectors[i].cipher ); + if( memcmp( buffer, test_vectors[i].plain, 8 ) ) + return "IDEA test decryption failed."; } + + return NULL; } -#endif gcry_cipher_spec_t _gcry_cipher_spec_idea = commit 0fb5e52d417d5430ce8abf9af2ce1cd6b2bfa8b8 Author: Ulrich M?ller Date: Wed Jan 11 13:20:48 2012 +0100 Add support for the IDEA cipher. Adapt idea.c to the Libgcrypt framework. Add IDEA to cipher_table and to the build system. Patents on IDEA have expired: Europe: EP0482154 on 2011-05-16, Japan: JP3225440 on 2011-05-16, U.S.: 5,214,703 on 2012-01-07. * configure.ac: Add idea to the list of available ciphers. Define USE_IDEA if idea is enabled. * cipher/cipher.c (cipher_table): Add entry for IDEA. * cipher/idea.c: Update comment about patents. Include proper header files and remove redundant declarations. (expand_key, cipher, do_setkey, encrypt_block, decrypt_block): Define function arguments as const where appropriate. (cipher): Test for !WORDS_BIGENDIAN instead of LITTLE_ENDIAN_HOST. (do_setkey, decrypt_block): Don't call selftest. (idea_setkey): New function, wrapper for do_setkey. (idea_encrypt): New function, wrapper for encrypt_block. (_gcry_cipher_spec_idea): Define. * cipher/Makefile.am (EXTRA_libcipher_la_SOURCES): Add idea.c. * src/cipher.h (_gcry_cipher_spec_idea): Declare. * tests/basic.c (check_ciphers): Add GCRY_CIPHER_IDEA. diff --git a/cipher/Makefile.am b/cipher/Makefile.am index f8c39fb..1109c9d 100644 --- a/cipher/Makefile.am +++ b/cipher/Makefile.am @@ -51,6 +51,7 @@ des.c \ dsa.c \ elgamal.c \ ecc.c \ +idea.c \ md4.c \ md5.c \ rijndael.c rijndael-tables.h \ diff --git a/cipher/cipher.c b/cipher/cipher.c index b99ab41..9852d6a 100644 --- a/cipher/cipher.c +++ b/cipher/cipher.c @@ -112,6 +112,10 @@ static struct cipher_table_entry { &_gcry_cipher_spec_camellia256, &dummy_extra_spec, GCRY_CIPHER_CAMELLIA256 }, #endif +#ifdef USE_IDEA + { &_gcry_cipher_spec_idea, + &dummy_extra_spec, GCRY_CIPHER_IDEA }, +#endif { NULL } }; diff --git a/cipher/idea.c b/cipher/idea.c index 65a8ec3..fe14b21 100644 --- a/cipher/idea.c +++ b/cipher/idea.c @@ -22,10 +22,10 @@ * used in advertising or otherwise to promote the sale, use or other dealings * in this Software without prior written authorization from Werner Koch. * - * DUE TO PATENT CLAIMS THE DISTRIBUTION OF THE SOFTWARE IS NOT ALLOWED IN - * THESE COUNTRIES: - * AUSTRIA, FRANCE, GERMANY, ITALY, JAPAN, THE NETHERLANDS, - * SPAIN, SWEDEN, SWITZERLAND, THE UK AND THE US. + * Patents on IDEA have expired: + * Europe: EP0482154 on 2011-05-16, + * Japan: JP3225440 on 2011-05-16, + * U.S.: 5,214,703 on 2012-01-07. */ /* @@ -34,60 +34,22 @@ * * The code herein is based on the one from: * Bruce Schneier: Applied Cryptography. John Wiley & Sons, 1996. - * ISBN 0-471-11709-9. . - * - * How to compile: - gcc -Wall -O2 -shared -fPIC -o idea idea.c - * - * 2001-06-08 wk Changed distribution conditions - * 2001-06-11 wk Fixed invert_key (which is not used in CFB mode) - * Thanks to Mark A. Borgerding. Added defintion for - * the PowerPC. + * ISBN 0-471-11709-9. */ +#include #include #include #include #include -/* configuration stuff */ -#ifdef __alpha__ - #define SIZEOF_UNSIGNED_LONG 8 -#else - #define SIZEOF_UNSIGNED_LONG 4 -#endif - -#if defined(__mc68000__) || defined (__sparc__) || defined (__PPC__) \ - || (defined(__mips__) && (defined(MIPSEB) || defined (__MIPSEB__)) ) \ - || defined(__powerpc__) \ - || defined(__hpux__) /* should be replaced by the Macro for the PA */ - #define BIG_ENDIAN_HOST 1 -#else - #define LITTLE_ENDIAN_HOST 1 -#endif - -typedef unsigned long ulong; -typedef unsigned short ushort; -typedef unsigned char byte; - -typedef unsigned short u16; -typedef unsigned long u32; - -/* end configurable stuff */ - -#ifndef DIM - #define DIM(v) (sizeof(v)/sizeof((v)[0])) - #define DIMof(type,member) DIM(((type *)0)->member) -#endif - -/* imports */ -void g10_log_fatal( const char *fmt, ... ); - +#include "types.h" /* for byte and u32 typedefs */ +#include "g10lib.h" +#include "cipher.h" -/* local stuff */ -#define FNCCAST_SETKEY(f) ((int(*)(void*, byte*, unsigned))(f)) +#define FNCCAST_SETKEY(f) ((int(*)(void*, byte*, unsigned int))(f)) #define FNCCAST_CRYPT(f) ((void(*)(void*, byte*, byte*))(f)) #define IDEA_KEYSIZE 16 @@ -102,13 +64,6 @@ typedef struct { } IDEA_context; -static int do_setkey( IDEA_context *c, byte *key, unsigned keylen ); -static void encrypt_block( IDEA_context *bc, byte *outbuf, byte *inbuf ); -static void decrypt_block( IDEA_context *bc, byte *outbuf, byte *inbuf ); -static void selftest(int); - - - static u16 mul_inv( u16 x ) { @@ -139,7 +94,7 @@ mul_inv( u16 x ) static void -expand_key( byte *userkey, u16 *ek ) +expand_key( const byte *userkey, u16 *ek ) { int i,j; @@ -202,7 +157,7 @@ invert_key( u16 *ek, u16 dk[IDEA_KEYLEN] ) static void -cipher( byte *outbuf, byte *inbuf, u16 *key ) +cipher( byte *outbuf, const byte *inbuf, u16 *key ) { u16 x1, x2, x3,x4, s2, s3; u16 *in, *out; @@ -230,7 +185,7 @@ cipher( byte *outbuf, byte *inbuf, u16 *key ) x2 = *in++; x3 = *in++; x4 = *in; - #ifdef LITTLE_ENDIAN_HOST + #ifndef WORDS_BIGENDIAN x1 = (x1>>8) | (x1<<8); x2 = (x2>>8) | (x2<<8); x3 = (x3>>8) | (x3<<8); @@ -263,7 +218,7 @@ cipher( byte *outbuf, byte *inbuf, u16 *key ) MUL(x4, *key); out = (u16*)outbuf; - #ifdef LITTLE_ENDIAN_HOST + #ifndef WORDS_BIGENDIAN *out++ = (x1>>8) | (x1<<8); *out++ = (x3>>8) | (x3<<8); *out++ = (x2>>8) | (x2<<8); @@ -279,14 +234,16 @@ cipher( byte *outbuf, byte *inbuf, u16 *key ) static int -do_setkey( IDEA_context *c, byte *key, unsigned keylen ) +do_setkey( IDEA_context *c, const byte *key, unsigned int keylen ) { +#if 0 static int initialized = 0; if( !initialized ) { initialized = 1; selftest(0); } +#endif assert(keylen == 16); c->have_dk = 0; expand_key( key, c->ek ); @@ -294,21 +251,40 @@ do_setkey( IDEA_context *c, byte *key, unsigned keylen ) return 0; } +static gcry_err_code_t +idea_setkey (void *context, const byte *key, unsigned int keylen) +{ + IDEA_context *ctx = context; + int rc = do_setkey (ctx, key, keylen); + _gcry_burn_stack (23+6*sizeof(void*)); + return rc; +} + static void -encrypt_block( IDEA_context *c, byte *outbuf, byte *inbuf ) +encrypt_block( IDEA_context *c, byte *outbuf, const byte *inbuf ) { cipher( outbuf, inbuf, c->ek ); } static void -decrypt_block( IDEA_context *c, byte *outbuf, byte *inbuf ) +idea_encrypt (void *context, byte *out, const byte *in) +{ + IDEA_context *ctx = context; + encrypt_block (ctx, out, in); + _gcry_burn_stack (24+3*sizeof (void*)); +} + +static void +decrypt_block( IDEA_context *c, byte *outbuf, const byte *inbuf ) { +#if 0 static int initialized; if( !initialized ) { initialized = 1; selftest(1); } +#endif if( !c->have_dk ) { c->have_dk = 1; invert_key( c->ek, c->dk ); @@ -316,7 +292,16 @@ decrypt_block( IDEA_context *c, byte *outbuf, byte *inbuf ) cipher( outbuf, inbuf, c->dk ); } +static void +idea_decrypt (void *context, byte *out, const byte *in) +{ + IDEA_context *ctx = context; + decrypt_block (ctx, out, in); + _gcry_burn_stack (24+3*sizeof (void*)); +} + +#if 0 static void selftest( int check_decrypt ) { @@ -388,89 +373,12 @@ static struct { } } } +#endif -/**************** - * Return some information about the algorithm. We need algo here to - * distinguish different flavors of the algorithm. - * Returns: A pointer to string describing the algorithm or NULL if - * the ALGO is invalid. - */ -const char * -idea_get_info( int algo, size_t *keylen, - size_t *blocksize, size_t *contextsize, - int (**r_setkey)( void *c, byte *key, unsigned keylen ), - void (**r_encrypt)( void *c, byte *outbuf, byte *inbuf ), - void (**r_decrypt)( void *c, byte *outbuf, byte *inbuf ) - ) +gcry_cipher_spec_t _gcry_cipher_spec_idea = { - *keylen = 128; - *blocksize = 8; - *contextsize = sizeof(IDEA_context); - *r_setkey = FNCCAST_SETKEY(do_setkey); - *r_encrypt= FNCCAST_CRYPT(encrypt_block); - *r_decrypt= FNCCAST_CRYPT(decrypt_block); - if( algo == 1 ) - return "IDEA"; - return NULL; -} - - - -const char * const gnupgext_version = "IDEA ($Revision: 1.11 $)"; - -static struct { - int class; - int version; - int value; - void (*func)(void); -} func_table[] = { - { 20, 1, 0, (void(*)(void))idea_get_info }, - { 21, 1, 1 }, + "IDEA", NULL, NULL, IDEA_BLOCKSIZE, 128, + sizeof (IDEA_context), + idea_setkey, idea_encrypt, idea_decrypt }; - - - -/**************** - * Enumerate the names of the functions together with informations about - * this function. Set sequence to an integer with a initial value of 0 and - * do not change it. - * If what is 0 all kind of functions are returned. - * Return values: class := class of function: - * 10 = message digest algorithm info function - * 11 = integer with available md algorithms - * 20 = cipher algorithm info function - * 21 = integer with available cipher algorithms - * 30 = public key algorithm info function - * 31 = integer with available pubkey algorithms - * version = interface version of the function/pointer - * (currently this is 1 for all functions) - */ -void * -gnupgext_enum_func( int what, int *sequence, int *class, int *vers ) -{ - void *ret; - int i = *sequence; - - do { - if( i >= DIM(func_table) || i < 0 ) { - return NULL; - } - *class = func_table[i].class; - *vers = func_table[i].version; - switch( *class ) { - case 11: - case 21: - case 31: - ret = &func_table[i].value; - break; - default: - ret = func_table[i].func; - break; - } - i++; - } while( what && what != *class ); - - *sequence = i; - return ret; -} diff --git a/configure.ac b/configure.ac index 8c419aa..0bcc8ae 100644 --- a/configure.ac +++ b/configure.ac @@ -172,7 +172,7 @@ LIBGCRYPT_CONFIG_HOST="$host" # Definitions for symmetric ciphers. available_ciphers="arcfour blowfish cast5 des aes twofish serpent rfc2268 seed" -available_ciphers="$available_ciphers camellia" +available_ciphers="$available_ciphers camellia idea" enabled_ciphers="" # Definitions for public-key ciphers. @@ -1057,6 +1057,12 @@ if test "$found" = "1" ; then AC_DEFINE(USE_CAMELLIA, 1, [Defined if this module should be included]) fi +LIST_MEMBER(idea, $enabled_ciphers) +if test "$found" = "1" ; then + GCRYPT_CIPHERS="$GCRYPT_CIPHERS idea.lo" + AC_DEFINE(USE_IDEA, 1, [Defined if this module should be included]) +fi + LIST_MEMBER(dsa, $enabled_pubkey_ciphers) if test "$found" = "1" ; then GCRYPT_PUBKEY_CIPHERS="$GCRYPT_PUBKEY_CIPHERS dsa.lo" diff --git a/src/cipher.h b/src/cipher.h index 0f923d7..48eeeda 100644 --- a/src/cipher.h +++ b/src/cipher.h @@ -135,6 +135,7 @@ extern gcry_cipher_spec_t _gcry_cipher_spec_seed; extern gcry_cipher_spec_t _gcry_cipher_spec_camellia128; extern gcry_cipher_spec_t _gcry_cipher_spec_camellia192; extern gcry_cipher_spec_t _gcry_cipher_spec_camellia256; +extern gcry_cipher_spec_t _gcry_cipher_spec_idea; extern cipher_extra_spec_t _gcry_cipher_extraspec_tripledes; extern cipher_extra_spec_t _gcry_cipher_extraspec_aes; diff --git a/tests/basic.c b/tests/basic.c index b29668b..da5dfa8 100644 --- a/tests/basic.c +++ b/tests/basic.c @@ -1568,6 +1568,9 @@ check_ciphers (void) GCRY_CIPHER_CAMELLIA192, GCRY_CIPHER_CAMELLIA256, #endif +#if USE_IDEA + GCRY_CIPHER_IDEA, +#endif 0 }; static int algos2[] = { commit 8ff4025e3698822c47199d9172153bc378f7bd32 Author: Werner Koch Date: Mon Jan 9 14:11:41 2012 +0100 Include an IDEA implementation. The code is the old IDEA test code, written by me back in 1997 and distributed on a Danish FTP server. This commit is only for reference. To use the code it has to be adjusted to the Libgcrypt framework. diff --git a/cipher/idea.c b/cipher/idea.c new file mode 100644 index 0000000..65a8ec3 --- /dev/null +++ b/cipher/idea.c @@ -0,0 +1,476 @@ +/* idea.c - IDEA function + * Copyright (c) 1997, 1998, 1999, 2001 by Werner Koch (dd9jn) + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * WERNER KOCH BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Werner Koch shall not be + * used in advertising or otherwise to promote the sale, use or other dealings + * in this Software without prior written authorization from Werner Koch. + * + * DUE TO PATENT CLAIMS THE DISTRIBUTION OF THE SOFTWARE IS NOT ALLOWED IN + * THESE COUNTRIES: + * AUSTRIA, FRANCE, GERMANY, ITALY, JAPAN, THE NETHERLANDS, + * SPAIN, SWEDEN, SWITZERLAND, THE UK AND THE US. + */ + +/* + * Please see http://www.noepatents.org/ to learn why software patents + * are bad for society and what you can do to fight them. + * + * The code herein is based on the one from: + * Bruce Schneier: Applied Cryptography. John Wiley & Sons, 1996. + * ISBN 0-471-11709-9. . + * + * How to compile: + gcc -Wall -O2 -shared -fPIC -o idea idea.c + * + * 2001-06-08 wk Changed distribution conditions + * 2001-06-11 wk Fixed invert_key (which is not used in CFB mode) + * Thanks to Mark A. Borgerding. Added defintion for + * the PowerPC. + */ + + +#include +#include +#include +#include + +/* configuration stuff */ +#ifdef __alpha__ + #define SIZEOF_UNSIGNED_LONG 8 +#else + #define SIZEOF_UNSIGNED_LONG 4 +#endif + +#if defined(__mc68000__) || defined (__sparc__) || defined (__PPC__) \ + || (defined(__mips__) && (defined(MIPSEB) || defined (__MIPSEB__)) ) \ + || defined(__powerpc__) \ + || defined(__hpux__) /* should be replaced by the Macro for the PA */ + #define BIG_ENDIAN_HOST 1 +#else + #define LITTLE_ENDIAN_HOST 1 +#endif + +typedef unsigned long ulong; +typedef unsigned short ushort; +typedef unsigned char byte; + +typedef unsigned short u16; +typedef unsigned long u32; + +/* end configurable stuff */ + +#ifndef DIM + #define DIM(v) (sizeof(v)/sizeof((v)[0])) + #define DIMof(type,member) DIM(((type *)0)->member) +#endif + +/* imports */ +void g10_log_fatal( const char *fmt, ... ); + + +/* local stuff */ + +#define FNCCAST_SETKEY(f) ((int(*)(void*, byte*, unsigned))(f)) +#define FNCCAST_CRYPT(f) ((void(*)(void*, byte*, byte*))(f)) + +#define IDEA_KEYSIZE 16 +#define IDEA_BLOCKSIZE 8 +#define IDEA_ROUNDS 8 +#define IDEA_KEYLEN (6*IDEA_ROUNDS+4) + +typedef struct { + u16 ek[IDEA_KEYLEN]; + u16 dk[IDEA_KEYLEN]; + int have_dk; +} IDEA_context; + + +static int do_setkey( IDEA_context *c, byte *key, unsigned keylen ); +static void encrypt_block( IDEA_context *bc, byte *outbuf, byte *inbuf ); +static void decrypt_block( IDEA_context *bc, byte *outbuf, byte *inbuf ); +static void selftest(int); + + + +static u16 +mul_inv( u16 x ) +{ + u16 t0, t1; + u16 q, y; + + if( x < 2 ) + return x; + t1 = 0x10001L / x; + y = 0x10001L % x; + if( y == 1 ) + return (1-t1) & 0xffff; + + t0 = 1; + do { + q = x / y; + x = x % y; + t0 += q * t1; + if( x == 1 ) + return t0; + q = y / x; + y = y % x; + t1 += q * t0; + } while( y != 1 ); + return (1-t1) & 0xffff; +} + + + +static void +expand_key( byte *userkey, u16 *ek ) +{ + int i,j; + + for(j=0; j < 8; j++ ) { + ek[j] = (*userkey << 8) + userkey[1]; + userkey += 2; + } + for(i=0; j < IDEA_KEYLEN; j++ ) { + i++; + ek[i+7] = ek[i&7] << 9 | ek[(i+1)&7] >> 7; + ek += i & 8; + i &= 7; + } +} + + +static void +invert_key( u16 *ek, u16 dk[IDEA_KEYLEN] ) +{ + int i; + u16 t1, t2, t3; + u16 temp[IDEA_KEYLEN]; + u16 *p = temp + IDEA_KEYLEN; + + t1 = mul_inv( *ek++ ); + t2 = -*ek++; + t3 = -*ek++; + *--p = mul_inv( *ek++ ); + *--p = t3; + *--p = t2; + *--p = t1; + + for(i=0; i < IDEA_ROUNDS-1; i++ ) { + t1 = *ek++; + *--p = *ek++; + *--p = t1; + + t1 = mul_inv( *ek++ ); + t2 = -*ek++; + t3 = -*ek++; + *--p = mul_inv( *ek++ ); + *--p = t2; + *--p = t3; + *--p = t1; + } + t1 = *ek++; + *--p = *ek++; + *--p = t1; + + t1 = mul_inv( *ek++ ); + t2 = -*ek++; + t3 = -*ek++; + *--p = mul_inv( *ek++ ); + *--p = t3; + *--p = t2; + *--p = t1; + memcpy(dk, temp, sizeof(temp) ); + memset(temp, 0, sizeof(temp) ); /* burn temp */ +} + + +static void +cipher( byte *outbuf, byte *inbuf, u16 *key ) +{ + u16 x1, x2, x3,x4, s2, s3; + u16 *in, *out; + int r = IDEA_ROUNDS; + #define MUL(x,y) \ + do {u16 _t16; u32 _t32; \ + if( (_t16 = (y)) ) { \ + if( (x = (x)&0xffff) ) { \ + _t32 = (u32)x * _t16; \ + x = _t32 & 0xffff; \ + _t16 = _t32 >> 16; \ + x = ((x)-_t16) + (x<_t16?1:0); \ + } \ + else { \ + x = 1 - _t16; \ + } \ + } \ + else { \ + x = 1 - x; \ + } \ + } while(0) + + in = (u16*)inbuf; + x1 = *in++; + x2 = *in++; + x3 = *in++; + x4 = *in; + #ifdef LITTLE_ENDIAN_HOST + x1 = (x1>>8) | (x1<<8); + x2 = (x2>>8) | (x2<<8); + x3 = (x3>>8) | (x3<<8); + x4 = (x4>>8) | (x4<<8); + #endif + do { + MUL(x1, *key++); + x2 += *key++; + x3 += *key++; + MUL(x4, *key++ ); + + s3 = x3; + x3 ^= x1; + MUL(x3, *key++); + s2 = x2; + x2 ^=x4; + x2 += x3; + MUL(x2, *key++); + x3 += x2; + + x1 ^= x2; + x4 ^= x3; + + x2 ^= s3; + x3 ^= s2; + } while( --r ); + MUL(x1, *key++); + x3 += *key++; + x2 += *key++; + MUL(x4, *key); + + out = (u16*)outbuf; + #ifdef LITTLE_ENDIAN_HOST + *out++ = (x1>>8) | (x1<<8); + *out++ = (x3>>8) | (x3<<8); + *out++ = (x2>>8) | (x2<<8); + *out = (x4>>8) | (x4<<8); + #else + *out++ = x1; + *out++ = x3; + *out++ = x2; + *out = x4; + #endif + #undef MUL +} + + +static int +do_setkey( IDEA_context *c, byte *key, unsigned keylen ) +{ + static int initialized = 0; + + if( !initialized ) { + initialized = 1; + selftest(0); + } + assert(keylen == 16); + c->have_dk = 0; + expand_key( key, c->ek ); + invert_key( c->ek, c->dk ); + return 0; +} + +static void +encrypt_block( IDEA_context *c, byte *outbuf, byte *inbuf ) +{ + cipher( outbuf, inbuf, c->ek ); +} + +static void +decrypt_block( IDEA_context *c, byte *outbuf, byte *inbuf ) +{ + static int initialized; + + if( !initialized ) { + initialized = 1; + selftest(1); + } + if( !c->have_dk ) { + c->have_dk = 1; + invert_key( c->ek, c->dk ); + } + cipher( outbuf, inbuf, c->dk ); +} + + +static void +selftest( int check_decrypt ) +{ +static struct { + byte key[16]; + byte plain[8]; + byte cipher[8]; +} test_vectors[] = { + { { 0x00, 0x01, 0x00, 0x02, 0x00, 0x03, 0x00, 0x04, + 0x00, 0x05, 0x00, 0x06, 0x00, 0x07, 0x00, 0x08 }, + { 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x03 }, + { 0x11, 0xFB, 0xED, 0x2B, 0x01, 0x98, 0x6D, 0xE5 } }, + { { 0x00, 0x01, 0x00, 0x02, 0x00, 0x03, 0x00, 0x04, + 0x00, 0x05, 0x00, 0x06, 0x00, 0x07, 0x00, 0x08 }, + { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }, + { 0x54, 0x0E, 0x5F, 0xEA, 0x18, 0xC2, 0xF8, 0xB1 } }, + { { 0x00, 0x01, 0x00, 0x02, 0x00, 0x03, 0x00, 0x04, + 0x00, 0x05, 0x00, 0x06, 0x00, 0x07, 0x00, 0x08 }, + { 0x00, 0x19, 0x32, 0x4B, 0x64, 0x7D, 0x96, 0xAF }, + { 0x9F, 0x0A, 0x0A, 0xB6, 0xE1, 0x0C, 0xED, 0x78 } }, + { { 0x00, 0x01, 0x00, 0x02, 0x00, 0x03, 0x00, 0x04, + 0x00, 0x05, 0x00, 0x06, 0x00, 0x07, 0x00, 0x08 }, + { 0xF5, 0x20, 0x2D, 0x5B, 0x9C, 0x67, 0x1B, 0x08 }, + { 0xCF, 0x18, 0xFD, 0x73, 0x55, 0xE2, 0xC5, 0xC5 } }, + { { 0x00, 0x01, 0x00, 0x02, 0x00, 0x03, 0x00, 0x04, + 0x00, 0x05, 0x00, 0x06, 0x00, 0x07, 0x00, 0x08 }, + { 0xFA, 0xE6, 0xD2, 0xBE, 0xAA, 0x96, 0x82, 0x6E }, + { 0x85, 0xDF, 0x52, 0x00, 0x56, 0x08, 0x19, 0x3D } }, + { { 0x00, 0x01, 0x00, 0x02, 0x00, 0x03, 0x00, 0x04, + 0x00, 0x05, 0x00, 0x06, 0x00, 0x07, 0x00, 0x08 }, + { 0x0A, 0x14, 0x1E, 0x28, 0x32, 0x3C, 0x46, 0x50 }, + { 0x2F, 0x7D, 0xE7, 0x50, 0x21, 0x2F, 0xB7, 0x34 } }, + { { 0x00, 0x01, 0x00, 0x02, 0x00, 0x03, 0x00, 0x04, + 0x00, 0x05, 0x00, 0x06, 0x00, 0x07, 0x00, 0x08 }, + { 0x05, 0x0A, 0x0F, 0x14, 0x19, 0x1E, 0x23, 0x28 }, + { 0x7B, 0x73, 0x14, 0x92, 0x5D, 0xE5, 0x9C, 0x09 } }, + { { 0x00, 0x05, 0x00, 0x0A, 0x00, 0x0F, 0x00, 0x14, + 0x00, 0x19, 0x00, 0x1E, 0x00, 0x23, 0x00, 0x28 }, + { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }, + { 0x3E, 0xC0, 0x47, 0x80, 0xBE, 0xFF, 0x6E, 0x20 } }, + { { 0x3A, 0x98, 0x4E, 0x20, 0x00, 0x19, 0x5D, 0xB3, + 0x2E, 0xE5, 0x01, 0xC8, 0xC4, 0x7C, 0xEA, 0x60 }, + { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }, + { 0x97, 0xBC, 0xD8, 0x20, 0x07, 0x80, 0xDA, 0x86 } }, + { { 0x00, 0x64, 0x00, 0xC8, 0x01, 0x2C, 0x01, 0x90, + 0x01, 0xF4, 0x02, 0x58, 0x02, 0xBC, 0x03, 0x20 }, + { 0x05, 0x32, 0x0A, 0x64, 0x14, 0xC8, 0x19, 0xFA }, + { 0x65, 0xBE, 0x87, 0xE7, 0xA2, 0x53, 0x8A, 0xED } }, + { { 0x9D, 0x40, 0x75, 0xC1, 0x03, 0xBC, 0x32, 0x2A, + 0xFB, 0x03, 0xE7, 0xBE, 0x6A, 0xB3, 0x00, 0x06 }, + { 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08 }, + { 0xF5, 0xDB, 0x1A, 0xC4, 0x5E, 0x5E, 0xF9, 0xF9 } } +}; + IDEA_context c; + byte buffer[8]; + int i; + + for(i=0; i < DIM(test_vectors); i++ ) { + do_setkey( &c, test_vectors[i].key, 16 ); + if( !check_decrypt ) { + encrypt_block( &c, buffer, test_vectors[i].plain ); + if( memcmp( buffer, test_vectors[i].cipher, 8 ) ) + g10_log_fatal("idea encryption (%d) failed\n", i); + } + else { + decrypt_block( &c, buffer, test_vectors[i].cipher ); + if( memcmp( buffer, test_vectors[i].plain, 8 ) ) + g10_log_fatal("idea decryption (%d) failed\n", i); + } + } +} + + +/**************** + * Return some information about the algorithm. We need algo here to + * distinguish different flavors of the algorithm. + * Returns: A pointer to string describing the algorithm or NULL if + * the ALGO is invalid. + */ +const char * +idea_get_info( int algo, size_t *keylen, + size_t *blocksize, size_t *contextsize, + int (**r_setkey)( void *c, byte *key, unsigned keylen ), + void (**r_encrypt)( void *c, byte *outbuf, byte *inbuf ), + void (**r_decrypt)( void *c, byte *outbuf, byte *inbuf ) + ) +{ + *keylen = 128; + *blocksize = 8; + *contextsize = sizeof(IDEA_context); + *r_setkey = FNCCAST_SETKEY(do_setkey); + *r_encrypt= FNCCAST_CRYPT(encrypt_block); + *r_decrypt= FNCCAST_CRYPT(decrypt_block); + if( algo == 1 ) + return "IDEA"; + return NULL; +} + + + +const char * const gnupgext_version = "IDEA ($Revision: 1.11 $)"; + +static struct { + int class; + int version; + int value; + void (*func)(void); +} func_table[] = { + { 20, 1, 0, (void(*)(void))idea_get_info }, + { 21, 1, 1 }, +}; + + + +/**************** + * Enumerate the names of the functions together with informations about + * this function. Set sequence to an integer with a initial value of 0 and + * do not change it. + * If what is 0 all kind of functions are returned. + * Return values: class := class of function: + * 10 = message digest algorithm info function + * 11 = integer with available md algorithms + * 20 = cipher algorithm info function + * 21 = integer with available cipher algorithms + * 30 = public key algorithm info function + * 31 = integer with available pubkey algorithms + * version = interface version of the function/pointer + * (currently this is 1 for all functions) + */ +void * +gnupgext_enum_func( int what, int *sequence, int *class, int *vers ) +{ + void *ret; + int i = *sequence; + + do { + if( i >= DIM(func_table) || i < 0 ) { + return NULL; + } + *class = func_table[i].class; + *vers = func_table[i].version; + switch( *class ) { + case 11: + case 21: + case 31: + ret = &func_table[i].value; + break; + default: + ret = func_table[i].func; + break; + } + i++; + } while( what && what != *class ); + + *sequence = i; + return ret; +} ----------------------------------------------------------------------- Summary of changes: cipher/Makefile.am | 1 + cipher/cipher.c | 4 + cipher/idea.c | 378 ++++++++++++++++++++++++++++++++++++++++++++++++++++ configure.ac | 8 +- src/cipher.h | 1 + tests/basic.c | 3 + 6 files changed, 394 insertions(+), 1 deletions(-) create mode 100644 cipher/idea.c hooks/post-receive -- The GNU crypto library http://git.gnupg.org From cvs at cvs.gnupg.org Wed Mar 20 17:53:12 2013 From: cvs at cvs.gnupg.org (by Werner Koch) Date: Wed, 20 Mar 2013 17:53:12 +0100 Subject: [git] GCRYPT - branch, master, updated. libgcrypt-1.5.0-101-g5fb3501 Message-ID: This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "The GNU crypto library". The branch, master has been updated via 5fb3501aa0cf5f2b2a9012706bb9ad2b1c4bfd7d (commit) via b402e550041782b770a6ae267c7c28ca8324a12e (commit) via 1eaad0a8c4cab227685a6a8768e539df2f1f4dac (commit) via de07974d807b703a2554d6ba885ea249e648bd44 (commit) from 931e409e877d1e444edd53dead327ec8e64daf9a (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 5fb3501aa0cf5f2b2a9012706bb9ad2b1c4bfd7d Author: Werner Koch Date: Wed Mar 20 17:23:54 2013 +0100 Use finer grained on-the-fly helper computations for EC. * src/ec-context.h (mpi_ec_ctx_s): Replace NEED_SYNC by a bitfield. * mpi/ec.c (ec_p_sync): Remove. (ec_get_reset, ec_get_a_is_pminus3, ec_get_two_inv_p): New. (ec_p_init): Use ec_get_reset. (_gcry_mpi_ec_set_mpi, _gcry_mpi_ec_dup_point) (_gcry_mpi_ec_add_points): Replace ec_p_sync by the ec_get_ accessors. diff --git a/mpi/ec.c b/mpi/ec.c index 0a348d2..cd19c81 100644 --- a/mpi/ec.c +++ b/mpi/ec.c @@ -337,22 +337,46 @@ ec_invm (gcry_mpi_t x, gcry_mpi_t a, mpi_ec_t ctx) } -/* Sync changed data in the context. */ +/* Force recomputation of all helper variables. */ static void -ec_p_sync (mpi_ec_t ec) +ec_get_reset (mpi_ec_t ec) +{ + ec->t.valid.a_is_pminus3 = 0; + ec->t.valid.two_inv_p = 0; +} + + +/* Accessor for helper variable. */ +static int +ec_get_a_is_pminus3 (mpi_ec_t ec) { gcry_mpi_t tmp; - if (!ec->t.need_sync) - return; + if (!ec->t.valid.a_is_pminus3) + { + ec->t.valid.a_is_pminus3 = 1; + tmp = mpi_alloc_like (ec->p); + mpi_sub_ui (tmp, ec->p, 3); + ec->t.a_is_pminus3 = !mpi_cmp (ec->a, tmp); + mpi_free (tmp); + } + + return ec->t.a_is_pminus3; +} - tmp = mpi_alloc_like (ec->p); - mpi_sub_ui (tmp, ec->p, 3); - ec->t.a_is_pminus3 = !mpi_cmp (ec->a, tmp); - mpi_free (tmp); - ec_invm (ec->t.two_inv_p, mpi_const (MPI_C_TWO), ec); - ec->t.need_sync = 0; +/* Accessor for helper variable. */ +static gcry_mpi_t +ec_get_two_inv_p (mpi_ec_t ec) +{ + if (!ec->t.valid.two_inv_p) + { + ec->t.valid.two_inv_p = 1; + if (!ec->t.two_inv_p) + ec->t.two_inv_p = mpi_alloc (0); + ec_invm (ec->t.two_inv_p, mpi_const (MPI_C_TWO), ec); + } + return ec->t.two_inv_p; } @@ -370,8 +394,7 @@ ec_p_init (mpi_ec_t ctx, gcry_mpi_t p, gcry_mpi_t a) ctx->p = mpi_copy (p); ctx->a = mpi_copy (a); - ctx->t.need_sync = 1; - ctx->t.two_inv_p = mpi_alloc (0); + ec_get_reset (ctx); /* Allocate scratch variables. */ for (i=0; i< DIM(ctx->t.scratch); i++) @@ -566,13 +589,13 @@ _gcry_mpi_ec_set_mpi (const char *name, gcry_mpi_t newvalue, { mpi_free (ec->p); ec->p = mpi_copy (newvalue); - ec->t.need_sync = 1; + ec_get_reset (ec); } else if (!strcmp (name, "a")) { mpi_free (ec->a); ec->a = mpi_copy (newvalue); - ec->t.need_sync = 1; + ec_get_reset (ec); } else if (!strcmp (name, "b")) { @@ -669,8 +692,6 @@ _gcry_mpi_ec_dup_point (mpi_point_t result, mpi_point_t point, mpi_ec_t ctx) #define l2 (ctx->t.scratch[4]) #define l3 (ctx->t.scratch[5]) - ec_p_sync (ctx); - if (!mpi_cmp_ui (point->y, 0) || !mpi_cmp_ui (point->z, 0)) { /* P_y == 0 || P_z == 0 => [1:1:0] */ @@ -680,7 +701,7 @@ _gcry_mpi_ec_dup_point (mpi_point_t result, mpi_point_t point, mpi_ec_t ctx) } else { - if (ctx->t.a_is_pminus3) /* Use the faster case. */ + if (ec_get_a_is_pminus3 (ctx)) /* Use the faster case. */ { /* L1 = 3(X - Z^2)(X + Z^2) */ /* T1: used for Z^2. */ @@ -768,8 +789,6 @@ _gcry_mpi_ec_add_points (mpi_point_t result, #define t1 (ctx->t.scratch[9]) #define t2 (ctx->t.scratch[10]) - ec_p_sync (ctx); - if ( (!mpi_cmp (x1, x2)) && (!mpi_cmp (y1, y2)) && (!mpi_cmp (z1, z2)) ) { /* Same point; need to call the duplicate function. */ @@ -858,7 +877,7 @@ _gcry_mpi_ec_add_points (mpi_point_t result, ec_powm (t1, l3, mpi_const (MPI_C_THREE), ctx); /* fixme: Use saved value*/ ec_mulm (t1, t1, l8, ctx); ec_subm (y3, l9, t1, ctx); - ec_mulm (y3, y3, ctx->t.two_inv_p, ctx); + ec_mulm (y3, y3, ec_get_two_inv_p (ctx), ctx); } } @@ -899,8 +918,6 @@ _gcry_mpi_ec_mul_point (mpi_point_t result, unsigned int nbits; int i; - ec_p_sync (ctx); - nbits = mpi_get_nbits (scalar); mpi_set_ui (result->x, 1); mpi_set_ui (result->y, 1); @@ -918,8 +935,6 @@ _gcry_mpi_ec_mul_point (mpi_point_t result, unsigned int i, loops; mpi_point_struct p1, p2, p1inv; - ec_p_sync (ctx); - x1 = mpi_alloc_like (ctx->p); y1 = mpi_alloc_like (ctx->p); h = mpi_alloc_like (ctx->p); diff --git a/src/ec-context.h b/src/ec-context.h index 6827e18..7002d47 100644 --- a/src/ec-context.h +++ b/src/ec-context.h @@ -38,7 +38,10 @@ struct mpi_ec_ctx_s /* This structure is private to mpi/ec.c! */ struct { - int need_sync; /* Helper for ec_p_sync. */ + struct { + unsigned int a_is_pminus3:1; + unsigned int two_inv_p:1; + } valid; /* Flags to help setting the helper vars below. */ int a_is_pminus3; /* True if A = P - 3. */ commit b402e550041782b770a6ae267c7c28ca8324a12e Author: Werner Koch Date: Mon Nov 5 19:21:51 2012 +0100 Allow building with w64-mingw32 * autogen.sh <--build-w32>: Support the w64-mingw32 toolchain. Also prepare for 64 bit building. -- NB: Despite of this change in autogen.sh, there is no support for 64 bit Windows yet. The change has only be done to eventually allow to work on a W64 version. diff --git a/autogen.sh b/autogen.sh index a0bbd6b..841c2c2 100755 --- a/autogen.sh +++ b/autogen.sh @@ -102,12 +102,12 @@ if [ "$myhost" = "w32" ]; then 64) w32root="$w64root" [ -z "$w32root" ] && w32root="$HOME/w64root" - toolprefixes="amd64-mingw32msvc" + toolprefixes="$amd64_toolprefixes amd64-mingw32msvc" ;; *) [ -z "$w32root" ] && w32root="$HOME/w32root" - toolprefixes="i586-mingw32msvc i386-mingw32msvc" - toolprefixes="i586-mingw32msvc i386-mingw32msvc i686-w64-mingw32" + toolprefixes="$w32_toolprefixes i686-w64-mingw32 i586-mingw32msvc" + toolprefixes="$toolprefixes i386-mingw32msvc mingw32" ;; esac echo "Using $w32root as standard install directory" >&2 commit 1eaad0a8c4cab227685a6a8768e539df2f1f4dac Author: Werner Koch Date: Mon Mar 18 15:31:34 2013 +0100 Provide GCRYPT_VERSION_NUMBER macro, add build info to the binary. * src/gcrypt.h.in (GCRYPT_VERSION_NUMBER): New. * configure.ac (VERSION_NUMBER): New ac_subst. * src/global.c (_gcry_vcontrol): Move call to above function ... (gcry_check_version): .. here. * configure.ac (BUILD_REVISION, BUILD_FILEVERSION) (BUILD_TIMESTAMP): Define on all platforms. * compat/compat.c (_gcry_compat_identification): Include revision and timestamp. diff --git a/NEWS b/NEWS index 429f666..0d75680 100644 --- a/NEWS +++ b/NEWS @@ -57,6 +57,7 @@ Noteworthy changes in version 1.6.0 (unreleased) gcry_mpi_ec_mul NEW. GCRYMPI_FLAG_IMMUTABLE NEW. GCRYMPI_FLAG_CONST NEW. + GCRYPT_VERSION_NUMBER NEW. Noteworthy changes in version 1.5.0 (2011-06-29) diff --git a/compat/compat.c b/compat/compat.c index 96889d3..d259130 100644 --- a/compat/compat.c +++ b/compat/compat.c @@ -30,6 +30,9 @@ _gcry_compat_identification (void) "This is Libgcrypt " PACKAGE_VERSION " - The GNU Crypto Library\n" "Copyright 2000, 2002, 2003, 2004, 2007, 2008, 2009,\n" " 2010, 2011, 2012 Free Software Foundation, Inc.\n" + "Copyright 2012, 2013 g10 Code GmbH\n" + "\n" + "(" BUILD_REVISION " " BUILD_TIMESTAMP ")\n" "\n\n"; return blurb; } diff --git a/configure.ac b/configure.ac index 7afd83d..7504d76 100644 --- a/configure.ac +++ b/configure.ac @@ -28,12 +28,16 @@ min_automake_version="1.10" # bump the version number immediately after the release and do another # commit and push so that the git magic is able to work. See below # for the LT versions. -m4_define(mym4_version, [1.6.0]) +m4_define(mym4_version_major, [1]) +m4_define(mym4_version_minor, [6]) +m4_define(mym4_version_micro, [0]) # Below is m4 magic to extract and compute the revision number, the # decimalized short revision number, a beta version string, and a flag # indicating a development version (mym4_isgit). Note that the m4 # processing is done by autoconf and not during the configure run. +m4_define(mym4_version, + [mym4_version_major.mym4_version_minor.mym4_version_micro]) m4_define([mym4_revision], m4_esyscmd([git rev-parse --short HEAD | tr -d '\n\r'])) m4_define([mym4_revision_dec], @@ -125,6 +129,9 @@ AC_SUBST(PACKAGE) AC_SUBST(VERSION) AC_DEFINE_UNQUOTED(PACKAGE, "$PACKAGE", [Name of this package]) AC_DEFINE_UNQUOTED(VERSION, "$VERSION", [Version of this package]) +VERSION_NUMBER=m4_esyscmd(printf "0x%02x%02x%02x" mym4_version_major \ + mym4_version_minor mym4_version_micro) +AC_SUBST(VERSION_NUMBER) ###################### @@ -1341,21 +1348,24 @@ esac AC_SUBST([GCRYPT_HWF_MODULES]) -# Generate extended version information for W32. -if test "$have_w32_system" = yes; then - BUILD_TIMESTAMP=`date --iso-8601=minutes` - changequote(,)dnl - BUILD_FILEVERSION=`echo "$VERSION" | sed 's/\([0-9.]*\).*/\1./;s/\./,/g'` - changequote([,])dnl - BUILD_FILEVERSION="${BUILD_FILEVERSION}mym4_revision_dec" -fi +# +# Provide information about the build. +# BUILD_REVISION="mym4_revision" AC_SUBST(BUILD_REVISION) -AC_SUBST(BUILD_TIMESTAMP) -AC_SUBST(BUILD_FILEVERSION) AC_DEFINE_UNQUOTED(BUILD_REVISION, "$BUILD_REVISION", [GIT commit id revision used to build this package]) +changequote(,)dnl +BUILD_FILEVERSION=`echo "$VERSION" | sed 's/\([0-9.]*\).*/\1./;s/\./,/g'` +changequote([,])dnl +BUILD_FILEVERSION="${BUILD_FILEVERSION}mym4_revision_dec" +AC_SUBST(BUILD_FILEVERSION) + +BUILD_TIMESTAMP=`date -u +%Y-%m-%dT%H:%M+0000 2>/dev/null || date` +AC_SUBST(BUILD_TIMESTAMP) +AC_DEFINE_UNQUOTED(BUILD_TIMESTAMP, "$BUILD_TIMESTAMP", + [The time this package was configured for a build]) # And create the files. diff --git a/src/gcrypt.h.in b/src/gcrypt.h.in index ad4da04..8343799 100644 --- a/src/gcrypt.h.in +++ b/src/gcrypt.h.in @@ -66,6 +66,11 @@ extern "C" { matches the installed library. */ #define GCRYPT_VERSION "@VERSION@" +/* The version number of this header. It may be used to handle minor + API incompatibilities. */ +#define GCRYPT_VERSION_NUMBER @VERSION_NUMBER@ + + /* Internal: We can't use the convenience macros for the multi precision integer functions when building this library. */ #ifdef _GCRYPT_IN_LIBGCRYPT diff --git a/src/global.c b/src/global.c index 0c6fbbd..f873897 100644 --- a/src/global.c +++ b/src/global.c @@ -247,6 +247,9 @@ gcry_check_version( const char *req_version ) int rq_major, rq_minor, rq_micro; const char *my_plvl; + if (req_version && req_version[0] == 1 && req_version[1] == 1) + return _gcry_compat_identification (); + /* Initialize library. */ global_init (); @@ -686,8 +689,6 @@ _gcry_vcontrol (enum gcry_ctl_cmds cmd, va_list arg_ptr) default: _gcry_set_preferred_rng_type (0); - /* A call to make sure that the dummy code is linked in. */ - _gcry_compat_identification (); err = GPG_ERR_INV_OP; } commit de07974d807b703a2554d6ba885ea249e648bd44 Author: Werner Koch Date: Wed Mar 20 15:18:08 2013 +0100 Fix a memory leak in the new EC code. * cipher/ecc.c (point_from_keyparam): Always call mpi_free on A. diff --git a/cipher/ecc.c b/cipher/ecc.c index c23ba08..8fcd57d 100644 --- a/cipher/ecc.c +++ b/cipher/ecc.c @@ -1763,10 +1763,10 @@ point_from_keyparam (gcry_mpi_point_t *r_a, { point = gcry_mpi_point_new (0); ec = os2ec (point, a); + mpi_free (a); if (ec) { gcry_mpi_point_release (point); - mpi_free (a); return ec; } } ----------------------------------------------------------------------- Summary of changes: NEWS | 1 + autogen.sh | 6 ++-- cipher/ecc.c | 2 +- compat/compat.c | 3 ++ configure.ac | 32 ++++++++++++++++++--------- mpi/ec.c | 63 +++++++++++++++++++++++++++++++++-------------------- src/ec-context.h | 5 +++- src/gcrypt.h.in | 5 ++++ src/global.c | 5 ++- 9 files changed, 80 insertions(+), 42 deletions(-) hooks/post-receive -- The GNU crypto library http://git.gnupg.org From cvs at cvs.gnupg.org Thu Mar 21 01:17:05 2013 From: cvs at cvs.gnupg.org (by NIIBE Yutaka) Date: Thu, 21 Mar 2013 01:17:05 +0100 Subject: [git] GnuPG - branch, STABLE-BRANCH-2-0, updated. gnupg-2.0.19-92-g33d2767 Message-ID: This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "The GNU Privacy Guard". The branch, STABLE-BRANCH-2-0 has been updated via 33d276791c8169063b22fde96a1760f9f5ef1e63 (commit) from 91423a826e3cefd78fc0006e65b56559dd578784 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 33d276791c8169063b22fde96a1760f9f5ef1e63 Author: NIIBE Yutaka Date: Thu Mar 21 09:04:13 2013 +0900 scd: change default value of pinpad maxlen. * scd/apdu.c (pcsc_pinpad_verify, pcsc_pinpad_modify): Default value of maxlen for pinpad input is now 15 (was: 25). * scd/ccid-driver.c (ccid_transceive_secure): Likewise. -- For newer PC/SC, it is better to use FEATURE_GET_TLV_PROPERTIES to get bMaxPINSize. diff --git a/scd/apdu.c b/scd/apdu.c index 196d58b..268c2fa 100644 --- a/scd/apdu.c +++ b/scd/apdu.c @@ -2086,7 +2086,7 @@ pcsc_pinpad_verify (int slot, int class, int ins, int p0, int p1, if (!pininfo->minlen) pininfo->minlen = 1; if (!pininfo->maxlen) - pininfo->maxlen = 25; + pininfo->maxlen = 15; /* Note that the 25 is the maximum value the SPR532 allows. */ if (pininfo->minlen < 1 || pininfo->minlen > 25 @@ -2167,7 +2167,7 @@ pcsc_pinpad_modify (int slot, int class, int ins, int p0, int p1, if (!pininfo->minlen) pininfo->minlen = 1; if (!pininfo->maxlen) - pininfo->maxlen = 25; + pininfo->maxlen = 15; /* Note that the 25 is the maximum value the SPR532 allows. */ if (pininfo->minlen < 1 || pininfo->minlen > 25 diff --git a/scd/ccid-driver.c b/scd/ccid-driver.c index dd9fabe..c3a66fa 100644 --- a/scd/ccid-driver.c +++ b/scd/ccid-driver.c @@ -3358,7 +3358,7 @@ ccid_transceive_secure (ccid_driver_t handle, if (!pininfo->minlen) pininfo->minlen = 1; if (!pininfo->maxlen) - pininfo->maxlen = 25; + pininfo->maxlen = 15; /* Note that the 25 is the maximum value the SPR532 allows. */ if (pininfo->minlen < 1 || pininfo->minlen > 25 @@ -3373,13 +3373,14 @@ ccid_transceive_secure (ccid_driver_t handle, case VENDOR_SCM: /* Tested with SPR 532. */ case VENDOR_KAAN: /* Tested with KAAN Advanced (1.02). */ case VENDOR_FSIJ: /* Tested with Gnuk (0.21). */ + pininfo->maxlen = 25; enable_varlen = 1; break; case VENDOR_VASCO: /* Tested with DIGIPASS 920 */ enable_varlen = 1; - pininfo->maxlen = 15; break; case VENDOR_CHERRY: + pininfo->maxlen = 25; enable_varlen = 1; /* The CHERRY XX44 keyboard echos an asterisk for each entered character on the keyboard channel. We use a special variant ----------------------------------------------------------------------- Summary of changes: scd/apdu.c | 4 ++-- scd/ccid-driver.c | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) hooks/post-receive -- The GNU Privacy Guard http://git.gnupg.org From cvs at cvs.gnupg.org Thu Mar 21 01:26:37 2013 From: cvs at cvs.gnupg.org (by NIIBE Yutaka) Date: Thu, 21 Mar 2013 01:26:37 +0100 Subject: [git] GnuPG - branch, master, updated. gnupg-2.1.0beta3-198-ga75a08d Message-ID: This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "The GNU Privacy Guard". The branch, master has been updated via a75a08d6e30e93e1793aa78a15d473a3ea7623cb (commit) via ca66f5c779af74d0eb7221afd7a9707201931e50 (commit) from eaa6dc3a8b4f31525650cd4785d6bafab86d68b7 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit a75a08d6e30e93e1793aa78a15d473a3ea7623cb Author: NIIBE Yutaka Date: Thu Mar 21 09:11:15 2013 +0900 po: Enable ja.po. * po/LINGUAS: Enable ja.po. diff --git a/po/LINGUAS b/po/LINGUAS index 1fc9664..76ab343 100644 --- a/po/LINGUAS +++ b/po/LINGUAS @@ -15,7 +15,7 @@ fr #hu #id #it -#ja +ja #nb #pl #pt_BR commit ca66f5c779af74d0eb7221afd7a9707201931e50 Author: NIIBE Yutaka Date: Thu Mar 21 09:04:13 2013 +0900 scd: change default value of pinpad maxlen. * scd/apdu.c (pcsc_pinpad_verify, pcsc_pinpad_modify): Default value of maxlen for pinpad input is now 15 (was: 25). * scd/ccid-driver.c (ccid_transceive_secure): Likewise. -- For newer PC/SC, it is better to use FEATURE_GET_TLV_PROPERTIES to get bMaxPINSize. diff --git a/scd/apdu.c b/scd/apdu.c index 6824ded..e920678 100644 --- a/scd/apdu.c +++ b/scd/apdu.c @@ -2056,7 +2056,7 @@ pcsc_pinpad_verify (int slot, int class, int ins, int p0, int p1, if (!pininfo->minlen) pininfo->minlen = 1; if (!pininfo->maxlen) - pininfo->maxlen = 25; + pininfo->maxlen = 15; /* Note that the 25 is the maximum value the SPR532 allows. */ if (pininfo->minlen < 1 || pininfo->minlen > 25 @@ -2139,7 +2139,7 @@ pcsc_pinpad_modify (int slot, int class, int ins, int p0, int p1, if (!pininfo->minlen) pininfo->minlen = 1; if (!pininfo->maxlen) - pininfo->maxlen = 25; + pininfo->maxlen = 15; /* Note that the 25 is the maximum value the SPR532 allows. */ if (pininfo->minlen < 1 || pininfo->minlen > 25 diff --git a/scd/ccid-driver.c b/scd/ccid-driver.c index da5fac9..8c91767 100644 --- a/scd/ccid-driver.c +++ b/scd/ccid-driver.c @@ -3357,7 +3357,7 @@ ccid_transceive_secure (ccid_driver_t handle, if (!pininfo->minlen) pininfo->minlen = 1; if (!pininfo->maxlen) - pininfo->maxlen = 25; + pininfo->maxlen = 15; /* Note that the 25 is the maximum value the SPR532 allows. */ if (pininfo->minlen < 1 || pininfo->minlen > 25 @@ -3371,14 +3371,15 @@ ccid_transceive_secure (ccid_driver_t handle, { case VENDOR_SCM: /* Tested with SPR 532. */ case VENDOR_KAAN: /* Tested with KAAN Advanced (1.02). */ - case VENDOR_FSIJ: /* Tested with the gnuk code (2011-01-05). */ + case VENDOR_FSIJ: /* Tested with Gnuk (0.21). */ + pininfo->maxlen = 25; enable_varlen = 1; break; case VENDOR_VASCO: /* Tested with DIGIPASS 920 */ enable_varlen = 1; - pininfo->maxlen = 15; break; case VENDOR_CHERRY: + pininfo->maxlen = 25; enable_varlen = 1; /* The CHERRY XX44 keyboard echos an asterisk for each entered character on the keyboard channel. We use a special variant ----------------------------------------------------------------------- Summary of changes: po/LINGUAS | 2 +- scd/apdu.c | 4 ++-- scd/ccid-driver.c | 7 ++++--- 3 files changed, 7 insertions(+), 6 deletions(-) hooks/post-receive -- The GNU Privacy Guard http://git.gnupg.org From cvs at cvs.gnupg.org Thu Mar 21 15:35:27 2013 From: cvs at cvs.gnupg.org (by Werner Koch) Date: Thu, 21 Mar 2013 15:35:27 +0100 Subject: [git] GCRYPT - branch, master, updated. libgcrypt-1.5.0-102-g2a1e03c Message-ID: This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "The GNU crypto library". The branch, master has been updated via 2a1e03c5a481689c43d197dd8034a1d73de0a1a4 (commit) from 5fb3501aa0cf5f2b2a9012706bb9ad2b1c4bfd7d (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 2a1e03c5a481689c43d197dd8034a1d73de0a1a4 Author: Werner Koch Date: Thu Mar 21 15:19:34 2013 +0100 Fix make dependency regression. * src/Makefile.am (libgcrypt_la_DEPENDENCIES): Add missing backslash. Reported by LRN. -- Fixes-commit: 09ac5d8 diff --git a/src/Makefile.am b/src/Makefile.am index 713e616..2fbe6ef 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -108,7 +108,7 @@ libgcrypt_la_LDFLAGS = $(no_undefined) $(export_symbols) \ $(libgcrypt_version_script_cmd) -version-info \ @LIBGCRYPT_LT_CURRENT@:@LIBGCRYPT_LT_REVISION@:@LIBGCRYPT_LT_AGE@ libgcrypt_la_DEPENDENCIES = \ - $(gcrypt_hwf_modules) + $(gcrypt_hwf_modules) \ ../cipher/libcipher.la \ ../random/librandom.la \ ../mpi/libmpi.la \ ----------------------------------------------------------------------- Summary of changes: src/Makefile.am | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) hooks/post-receive -- The GNU crypto library http://git.gnupg.org From cvs at cvs.gnupg.org Fri Mar 22 03:05:31 2013 From: cvs at cvs.gnupg.org (by NIIBE Yutaka) Date: Fri, 22 Mar 2013 03:05:31 +0100 Subject: [git] GnuPG - branch, master, updated. gnupg-2.1.0beta3-199-gee95c23 Message-ID: This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "The GNU Privacy Guard". The branch, master has been updated via ee95c23fcdc6673db0fc7287ab2197915d9b55b3 (commit) from a75a08d6e30e93e1793aa78a15d473a3ea7623cb (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit ee95c23fcdc6673db0fc7287ab2197915d9b55b3 Author: NIIBE Yutaka Date: Fri Mar 22 10:41:59 2013 +0900 scd: PC/SC cleanup. * scd/apdu.c (pcsc_dword_t): New. It was named as DWORD (double-word) when a word was 16-bit. (struct reader_table_s): Fixes for types. (struct pcsc_readerstate_s) [__APPLE__]: Enable #pragma pack(1). Throughout: Fixes for types. * scd/pcsc-wrapper.c: Likewise. -- Problem reported for 1.4.x by the issue 1358. diff --git a/scd/apdu.c b/scd/apdu.c index e920678..0eb148e 100644 --- a/scd/apdu.c +++ b/scd/apdu.c @@ -82,6 +82,12 @@ #define DLSTDCALL #endif +#if defined(__APPLE__) || defined(_WIN32) || defined(__CYGWIN__) +typedef unsinged int pcsc_dword_t; +#else +typedef unsigned long pcsc_dword_t; +#endif + /* A structure to collect information pertaining to one reader slot. */ struct reader_table_s { @@ -107,11 +113,11 @@ struct reader_table_s { ccid_driver_t handle; } ccid; struct { - unsigned long context; - unsigned long card; - unsigned long protocol; - unsigned long verify_ioctl; - unsigned long modify_ioctl; + long context; + long card; + pcsc_dword_t protocol; + pcsc_dword_t verify_ioctl; + pcsc_dword_t modify_ioctl; #ifdef NEED_PCSC_WRAPPER int req_fd; int rsp_fd; @@ -250,67 +256,75 @@ struct pcsc_io_request_s typedef struct pcsc_io_request_s *pcsc_io_request_t; +#ifdef __APPLE__ +#pragma pack(1) +#endif + struct pcsc_readerstate_s { const char *reader; void *user_data; - unsigned long current_state; - unsigned long event_state; - unsigned long atrlen; + pcsc_dword_t current_state; + pcsc_dword_t event_state; + pcsc_dword_t atrlen; unsigned char atr[33]; }; +#ifdef __APPLE__ +#pragma pack() +#endif + typedef struct pcsc_readerstate_s *pcsc_readerstate_t; -long (* DLSTDCALL pcsc_establish_context) (unsigned long scope, +long (* DLSTDCALL pcsc_establish_context) (pcsc_dword_t scope, const void *reserved1, const void *reserved2, - unsigned long *r_context); -long (* DLSTDCALL pcsc_release_context) (unsigned long context); -long (* DLSTDCALL pcsc_list_readers) (unsigned long context, + long *r_context); +long (* DLSTDCALL pcsc_release_context) (long context); +long (* DLSTDCALL pcsc_list_readers) (long context, const char *groups, - char *readers, unsigned long*readerslen); -long (* DLSTDCALL pcsc_get_status_change) (unsigned long context, - unsigned long timeout, + char *readers, pcsc_dword_t*readerslen); +long (* DLSTDCALL pcsc_get_status_change) (long context, + pcsc_dword_t timeout, pcsc_readerstate_t readerstates, - unsigned long nreaderstates); -long (* DLSTDCALL pcsc_connect) (unsigned long context, + pcsc_dword_t nreaderstates); +long (* DLSTDCALL pcsc_connect) (long context, const char *reader, - unsigned long share_mode, - unsigned long preferred_protocols, - unsigned long *r_card, - unsigned long *r_active_protocol); -long (* DLSTDCALL pcsc_reconnect) (unsigned long card, - unsigned long share_mode, - unsigned long preferred_protocols, - unsigned long initialization, - unsigned long *r_active_protocol); -long (* DLSTDCALL pcsc_disconnect) (unsigned long card, - unsigned long disposition); -long (* DLSTDCALL pcsc_status) (unsigned long card, - char *reader, unsigned long *readerlen, - unsigned long *r_state, - unsigned long *r_protocol, - unsigned char *atr, unsigned long *atrlen); -long (* DLSTDCALL pcsc_begin_transaction) (unsigned long card); -long (* DLSTDCALL pcsc_end_transaction) (unsigned long card, - unsigned long disposition); -long (* DLSTDCALL pcsc_transmit) (unsigned long card, + pcsc_dword_t share_mode, + pcsc_dword_t preferred_protocols, + long *r_card, + pcsc_dword_t *r_active_protocol); +long (* DLSTDCALL pcsc_reconnect) (long card, + pcsc_dword_t share_mode, + pcsc_dword_t preferred_protocols, + pcsc_dword_t initialization, + pcsc_dword_t *r_active_protocol); +long (* DLSTDCALL pcsc_disconnect) (long card, + pcsc_dword_t disposition); +long (* DLSTDCALL pcsc_status) (long card, + char *reader, pcsc_dword_t *readerlen, + pcsc_dword_t *r_state, + pcsc_dword_t *r_protocol, + unsigned char *atr, pcsc_dword_t *atrlen); +long (* DLSTDCALL pcsc_begin_transaction) (long card); +long (* DLSTDCALL pcsc_end_transaction) (long card, + pcsc_dword_t disposition); +long (* DLSTDCALL pcsc_transmit) (long card, const pcsc_io_request_t send_pci, const unsigned char *send_buffer, - unsigned long send_len, + pcsc_dword_t send_len, pcsc_io_request_t recv_pci, unsigned char *recv_buffer, - unsigned long *recv_len); -long (* DLSTDCALL pcsc_set_timeout) (unsigned long context, - unsigned long timeout); -long (* DLSTDCALL pcsc_control) (unsigned long card, - unsigned long control_code, + pcsc_dword_t *recv_len); +long (* DLSTDCALL pcsc_set_timeout) (long context, + pcsc_dword_t timeout); +long (* DLSTDCALL pcsc_control) (long card, + pcsc_dword_t control_code, const void *send_buffer, - unsigned long send_len, + pcsc_dword_t send_len, void *recv_buffer, - unsigned long recv_len, - unsigned long *bytes_returned); + pcsc_dword_t recv_len, + pcsc_dword_t *bytes_returned); /* Prototypes. */ @@ -1031,7 +1045,7 @@ pcsc_send_apdu_direct (int slot, unsigned char *apdu, size_t apdulen, { long err; struct pcsc_io_request_s send_pci; - unsigned long recv_len; + pcsc_dword_t recv_len; if (!reader_table[slot].atrlen && (err = reset_pcsc_reader (slot))) @@ -1195,7 +1209,7 @@ pcsc_send_apdu (int slot, unsigned char *apdu, size_t apdulen, #ifndef NEED_PCSC_WRAPPER static int -control_pcsc_direct (int slot, unsigned long ioctl_code, +control_pcsc_direct (int slot, pcsc_dword_t ioctl_code, const unsigned char *cntlbuf, size_t len, unsigned char *buffer, size_t *buflen) { @@ -1217,7 +1231,7 @@ control_pcsc_direct (int slot, unsigned long ioctl_code, #ifdef NEED_PCSC_WRAPPER static int -control_pcsc_wrapped (int slot, unsigned long ioctl_code, +control_pcsc_wrapped (int slot, pcsc_dword_t ioctl_code, const unsigned char *cntlbuf, size_t len, unsigned char *buffer, size_t *buflen) { @@ -1326,7 +1340,7 @@ control_pcsc_wrapped (int slot, unsigned long ioctl_code, actual output size will be stored at BUFLEN. Returns: A status word. This routine is used for PIN pad input support. */ static int -control_pcsc (int slot, unsigned long ioctl_code, +control_pcsc (int slot, pcsc_dword_t ioctl_code, const unsigned char *cntlbuf, size_t len, unsigned char *buffer, size_t *buflen) { @@ -1464,8 +1478,8 @@ connect_pcsc_card (int slot) else { char reader[250]; - unsigned long readerlen, atrlen; - unsigned long card_state, card_protocol; + pcsc_dword_t readerlen, atrlen; + long card_state, card_protocol; atrlen = DIM (reader_table[0].atr); readerlen = sizeof reader -1 ; @@ -1662,7 +1676,7 @@ open_pcsc_reader_direct (const char *portstr) long err; int slot; char *list = NULL; - unsigned long nreader, listlen; + pcsc_dword_t nreader, listlen; char *p; slot = new_reader_slot (); @@ -1991,14 +2005,14 @@ check_pcsc_pinpad (int slot, int command, pininfo_t *pininfo) check_again: if (command == ISO7816_VERIFY) { - if (reader_table[slot].pcsc.verify_ioctl == (unsigned long)-1) + if (reader_table[slot].pcsc.verify_ioctl == (pcsc_dword_t)-1) return SW_NOT_SUPPORTED; else if (reader_table[slot].pcsc.verify_ioctl != 0) return 0; /* Success */ } else if (command == ISO7816_CHANGE_REFERENCE_DATA) { - if (reader_table[slot].pcsc.modify_ioctl == (unsigned long)-1) + if (reader_table[slot].pcsc.modify_ioctl == (pcsc_dword_t)-1) return SW_NOT_SUPPORTED; else if (reader_table[slot].pcsc.modify_ioctl != 0) return 0; /* Success */ @@ -2006,8 +2020,8 @@ check_pcsc_pinpad (int slot, int command, pininfo_t *pininfo) else return SW_NOT_SUPPORTED; - reader_table[slot].pcsc.verify_ioctl = (unsigned long)-1; - reader_table[slot].pcsc.modify_ioctl = (unsigned long)-1; + reader_table[slot].pcsc.verify_ioctl = (pcsc_dword_t)-1; + reader_table[slot].pcsc.modify_ioctl = (pcsc_dword_t)-1; sw = control_pcsc (slot, CM_IOCTL_GET_FEATURE_REQUEST, NULL, 0, buf, &len); if (sw) diff --git a/scd/pcsc-wrapper.c b/scd/pcsc-wrapper.c index d0c30d1..a135d1e 100644 --- a/scd/pcsc-wrapper.c +++ b/scd/pcsc-wrapper.c @@ -65,6 +65,12 @@ static int verbose; +#if defined(__APPLE__) || defined(_WIN32) || defined(__CYGWIN__) +typedef unsinged int pcsc_dword_t; +#else +typedef unsigned long pcsc_dword_t; +#endif + /* PC/SC constants and function pointer. */ #define PCSC_SCOPE_USER 0 @@ -112,16 +118,24 @@ struct pcsc_io_request_s { typedef struct pcsc_io_request_s *pcsc_io_request_t; +#ifdef __APPLE__ +#pragma pack(1) +#endif + struct pcsc_readerstate_s { const char *reader; void *user_data; - unsigned long current_state; - unsigned long event_state; - unsigned long atrlen; + pcsc_dword_t current_state; + pcsc_dword_t event_state; + pcsc_dword_t atrlen; unsigned char atr[33]; }; +#ifdef __APPLE__ +#pragma pack() +#endif + typedef struct pcsc_readerstate_s *pcsc_readerstate_t; @@ -129,62 +143,62 @@ static int driver_is_open; /* True if the PC/SC driver has been initialzied and is ready for operations. The following variables are then valid. */ -static unsigned long pcsc_context; /* The current PC/CS context. */ +static long pcsc_context; /* The current PC/CS context. */ static char *current_rdrname; -static unsigned long pcsc_card; -static unsigned long pcsc_protocol; +static long pcsc_card; +static pcsc_dword_t pcsc_protocol; static unsigned char current_atr[33]; static size_t current_atrlen; -long (* pcsc_establish_context) (unsigned long scope, +long (* pcsc_establish_context) (pcsc_dword_t scope, const void *reserved1, const void *reserved2, - unsigned long *r_context); -long (* pcsc_release_context) (unsigned long context); -long (* pcsc_list_readers) (unsigned long context, + long *r_context); +long (* pcsc_release_context) (long context); +long (* pcsc_list_readers) (long context, const char *groups, - char *readers, unsigned long*readerslen); -long (* pcsc_get_status_change) (unsigned long context, - unsigned long timeout, + char *readers, pcsc_dword_t *readerslen); +long (* pcsc_get_status_change) (long context, + pcsc_dword_t timeout, pcsc_readerstate_t readerstates, - unsigned long nreaderstates); -long (* pcsc_connect) (unsigned long context, + pcsc_dword_t nreaderstates); +long (* pcsc_connect) (long context, const char *reader, - unsigned long share_mode, - unsigned long preferred_protocols, - unsigned long *r_card, - unsigned long *r_active_protocol); -long (* pcsc_reconnect) (unsigned long card, - unsigned long share_mode, - unsigned long preferred_protocols, - unsigned long initialization, - unsigned long *r_active_protocol); -long (* pcsc_disconnect) (unsigned long card, - unsigned long disposition); -long (* pcsc_status) (unsigned long card, - char *reader, unsigned long *readerlen, - unsigned long *r_state, - unsigned long *r_protocol, - unsigned char *atr, unsigned long *atrlen); -long (* pcsc_begin_transaction) (unsigned long card); -long (* pcsc_end_transaction) (unsigned long card, - unsigned long disposition); -long (* pcsc_transmit) (unsigned long card, + pcsc_dword_t share_mode, + pcsc_dword_t preferred_protocols, + long *r_card, + pcsc_dword_t *r_active_protocol); +long (* pcsc_reconnect) (long card, + pcsc_dword_t share_mode, + pcsc_dword_t preferred_protocols, + pcsc_dword_t initialization, + pcsc_dword_t *r_active_protocol); +long (* pcsc_disconnect) (long card, + pcsc_dword_t disposition); +long (* pcsc_status) (long card, + char *reader, pcsc_dword_t *readerlen, + pcsc_dword_t *r_state, + pcsc_dword_t *r_protocol, + unsigned char *atr, pcsc_dword_t *atrlen); +long (* pcsc_begin_transaction) (long card); +long (* pcsc_end_transaction) (long card, + pcsc_dword_t disposition); +long (* pcsc_transmit) (long card, const pcsc_io_request_t send_pci, const unsigned char *send_buffer, - unsigned long send_len, + pcsc_dword_t send_len, pcsc_io_request_t recv_pci, unsigned char *recv_buffer, - unsigned long *recv_len); -long (* pcsc_set_timeout) (unsigned long context, - unsigned long timeout); -long (* pcsc_control) (unsigned long card, - unsigned long control_code, + pcsc_dword_t *recv_len); +long (* pcsc_set_timeout) (long context, + pcsc_dword_t timeout); +long (* pcsc_control) (long card, + pcsc_dword_t control_code, const void *send_buffer, - unsigned long send_len, + pcsc_dword_t send_len, void *recv_buffer, - unsigned long recv_len, - unsigned long *bytes_returned); + pcsc_dword_t recv_len, + pcsc_dword_t *bytes_returned); @@ -394,9 +408,9 @@ handle_open (unsigned char *argbuf, size_t arglen) long err; const char * portstr; char *list = NULL; - unsigned long nreader, atrlen; + pcsc_dword_t nreader, atrlen; char *p; - unsigned long card_state, card_protocol; + pcsc_dword_t card_state, card_protocol; unsigned char atr[33]; /* Make sure there is only the port string */ @@ -492,7 +506,7 @@ handle_open (unsigned char *argbuf, size_t arglen) if (!err) { char reader[250]; - unsigned long readerlen; + pcsc_dword_t readerlen; atrlen = 33; readerlen = sizeof reader -1; @@ -626,8 +640,8 @@ handle_reset (unsigned char *argbuf, size_t arglen) { long err; char reader[250]; - unsigned long nreader, atrlen; - unsigned long card_state, card_protocol; + pcsc_dword_t nreader, atrlen; + pcsc_dword_t card_state, card_protocol; (void)argbuf; (void)arglen; @@ -697,7 +711,7 @@ handle_transmit (unsigned char *argbuf, size_t arglen) { long err; struct pcsc_io_request_s send_pci; - unsigned long recv_len; + pcsc_dword_t recv_len; unsigned char buffer[1024]; /* The apdu should at least be one byte. */ @@ -737,8 +751,8 @@ static void handle_control (unsigned char *argbuf, size_t arglen) { long err; - unsigned long ioctl_code; - unsigned long recv_len = 1024; + pcsc_dword_t ioctl_code; + pcsc_dword_t recv_len = 1024; unsigned char buffer[1024]; if (arglen < 4) ----------------------------------------------------------------------- Summary of changes: scd/apdu.c | 128 +++++++++++++++++++++++++++++----------------------- scd/pcsc-wrapper.c | 118 +++++++++++++++++++++++++++--------------------- 2 files changed, 137 insertions(+), 109 deletions(-) hooks/post-receive -- The GNU Privacy Guard http://git.gnupg.org From cvs at cvs.gnupg.org Fri Mar 22 03:06:53 2013 From: cvs at cvs.gnupg.org (by NIIBE Yutaka) Date: Fri, 22 Mar 2013 03:06:53 +0100 Subject: [git] GnuPG - branch, STABLE-BRANCH-2-0, updated. gnupg-2.0.19-93-gae22d62 Message-ID: This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "The GNU Privacy Guard". The branch, STABLE-BRANCH-2-0 has been updated via ae22d629b6028aa994ff09f012e1cb029575eeae (commit) from 33d276791c8169063b22fde96a1760f9f5ef1e63 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit ae22d629b6028aa994ff09f012e1cb029575eeae Author: NIIBE Yutaka Date: Fri Mar 22 10:41:59 2013 +0900 scd: PC/SC cleanup. * scd/apdu.c (pcsc_dword_t): New. It was named as DWORD (double-word) when a word was 16-bit. (struct reader_table_s): Fixes for types. (struct pcsc_readerstate_s) [__APPLE__]: Enable #pragma pack(1). Throughout: Fixes for types. * scd/pcsc-wrapper.c: Likewise. -- Problem reported for 1.4.x by the issue 1358. diff --git a/scd/apdu.c b/scd/apdu.c index 268c2fa..4734b12 100644 --- a/scd/apdu.c +++ b/scd/apdu.c @@ -81,6 +81,12 @@ #define DLSTDCALL #endif +#if defined(__APPLE__) || defined(_WIN32) || defined(__CYGWIN__) +typedef unsinged int pcsc_dword_t; +#else +typedef unsigned long pcsc_dword_t; +#endif + /* A structure to collect information pertaining to one reader slot. */ struct reader_table_s { @@ -106,11 +112,11 @@ struct reader_table_s { ccid_driver_t handle; } ccid; struct { - unsigned long context; - unsigned long card; - unsigned long protocol; - unsigned long verify_ioctl; - unsigned long modify_ioctl; + long context; + long card; + pcsc_dword_t protocol; + pcsc_dword_t verify_ioctl; + pcsc_dword_t modify_ioctl; #ifdef NEED_PCSC_WRAPPER int req_fd; int rsp_fd; @@ -232,67 +238,75 @@ struct pcsc_io_request_s typedef struct pcsc_io_request_s *pcsc_io_request_t; +#ifdef __APPLE__ +#pragma pack(1) +#endif + struct pcsc_readerstate_s { const char *reader; void *user_data; - unsigned long current_state; - unsigned long event_state; - unsigned long atrlen; + pcsc_dword_t current_state; + pcsc_dword_t event_state; + pcsc_dword_t atrlen; unsigned char atr[33]; }; +#ifdef __APPLE__ +#pragma pack() +#endif + typedef struct pcsc_readerstate_s *pcsc_readerstate_t; -long (* DLSTDCALL pcsc_establish_context) (unsigned long scope, +long (* DLSTDCALL pcsc_establish_context) (pcsc_dword_t scope, const void *reserved1, const void *reserved2, - unsigned long *r_context); -long (* DLSTDCALL pcsc_release_context) (unsigned long context); -long (* DLSTDCALL pcsc_list_readers) (unsigned long context, + long *r_context); +long (* DLSTDCALL pcsc_release_context) (long context); +long (* DLSTDCALL pcsc_list_readers) (long context, const char *groups, - char *readers, unsigned long*readerslen); -long (* DLSTDCALL pcsc_get_status_change) (unsigned long context, - unsigned long timeout, + char *readers, pcsc_dword_t*readerslen); +long (* DLSTDCALL pcsc_get_status_change) (long context, + pcsc_dword_t timeout, pcsc_readerstate_t readerstates, - unsigned long nreaderstates); -long (* DLSTDCALL pcsc_connect) (unsigned long context, + pcsc_dword_t nreaderstates); +long (* DLSTDCALL pcsc_connect) (long context, const char *reader, - unsigned long share_mode, - unsigned long preferred_protocols, - unsigned long *r_card, - unsigned long *r_active_protocol); -long (* DLSTDCALL pcsc_reconnect) (unsigned long card, - unsigned long share_mode, - unsigned long preferred_protocols, - unsigned long initialization, - unsigned long *r_active_protocol); -long (* DLSTDCALL pcsc_disconnect) (unsigned long card, - unsigned long disposition); -long (* DLSTDCALL pcsc_status) (unsigned long card, - char *reader, unsigned long *readerlen, - unsigned long *r_state, - unsigned long *r_protocol, - unsigned char *atr, unsigned long *atrlen); -long (* DLSTDCALL pcsc_begin_transaction) (unsigned long card); -long (* DLSTDCALL pcsc_end_transaction) (unsigned long card, - unsigned long disposition); -long (* DLSTDCALL pcsc_transmit) (unsigned long card, + pcsc_dword_t share_mode, + pcsc_dword_t preferred_protocols, + long *r_card, + pcsc_dword_t *r_active_protocol); +long (* DLSTDCALL pcsc_reconnect) (long card, + pcsc_dword_t share_mode, + pcsc_dword_t preferred_protocols, + pcsc_dword_t initialization, + pcsc_dword_t *r_active_protocol); +long (* DLSTDCALL pcsc_disconnect) (long card, + pcsc_dword_t disposition); +long (* DLSTDCALL pcsc_status) (long card, + char *reader, pcsc_dword_t *readerlen, + pcsc_dword_t *r_state, + pcsc_dword_t *r_protocol, + unsigned char *atr, pcsc_dword_t *atrlen); +long (* DLSTDCALL pcsc_begin_transaction) (long card); +long (* DLSTDCALL pcsc_end_transaction) (long card, + pcsc_dword_t disposition); +long (* DLSTDCALL pcsc_transmit) (long card, const pcsc_io_request_t send_pci, const unsigned char *send_buffer, - unsigned long send_len, + pcsc_dword_t send_len, pcsc_io_request_t recv_pci, unsigned char *recv_buffer, - unsigned long *recv_len); -long (* DLSTDCALL pcsc_set_timeout) (unsigned long context, - unsigned long timeout); -long (* DLSTDCALL pcsc_control) (unsigned long card, - unsigned long control_code, + pcsc_dword_t *recv_len); +long (* DLSTDCALL pcsc_set_timeout) (long context, + pcsc_dword_t timeout); +long (* DLSTDCALL pcsc_control) (long card, + pcsc_dword_t control_code, const void *send_buffer, - unsigned long send_len, + pcsc_dword_t send_len, void *recv_buffer, - unsigned long recv_len, - unsigned long *bytes_returned); + pcsc_dword_t recv_len, + pcsc_dword_t *bytes_returned); /* Prototypes. */ @@ -1053,7 +1067,7 @@ pcsc_send_apdu_direct (int slot, unsigned char *apdu, size_t apdulen, { long err; struct pcsc_io_request_s send_pci; - unsigned long recv_len; + pcsc_dword_t recv_len; if (!reader_table[slot].atrlen && (err = reset_pcsc_reader (slot))) @@ -1216,7 +1230,7 @@ pcsc_send_apdu (int slot, unsigned char *apdu, size_t apdulen, #ifndef NEED_PCSC_WRAPPER static int -control_pcsc_direct (int slot, unsigned long ioctl_code, +control_pcsc_direct (int slot, pcsc_dword_t ioctl_code, const unsigned char *cntlbuf, size_t len, unsigned char *buffer, size_t *buflen) { @@ -1238,7 +1252,7 @@ control_pcsc_direct (int slot, unsigned long ioctl_code, #ifdef NEED_PCSC_WRAPPER static int -control_pcsc_wrapped (int slot, unsigned long ioctl_code, +control_pcsc_wrapped (int slot, pcsc_dword_t ioctl_code, const unsigned char *cntlbuf, size_t len, unsigned char *buffer, size_t *buflen) { @@ -1346,7 +1360,7 @@ control_pcsc_wrapped (int slot, unsigned long ioctl_code, actual output size will be stored at BUFLEN. Returns: A status word. This routine is used for PIN pad input support. */ static int -control_pcsc (int slot, unsigned long ioctl_code, +control_pcsc (int slot, pcsc_dword_t ioctl_code, const unsigned char *cntlbuf, size_t len, unsigned char *buffer, size_t *buflen) { @@ -1483,8 +1497,8 @@ connect_pcsc_card (int slot) else { char reader[250]; - unsigned long readerlen, atrlen; - unsigned long card_state, card_protocol; + pcsc_dword_t readerlen, atrlen; + long card_state, card_protocol; atrlen = DIM (reader_table[0].atr); readerlen = sizeof reader -1 ; @@ -1680,7 +1694,7 @@ open_pcsc_reader_direct (const char *portstr) long err; int slot; char *list = NULL; - unsigned long nreader, listlen; + pcsc_dword_t nreader, listlen; char *p; slot = new_reader_slot (); @@ -2021,14 +2035,14 @@ check_pcsc_pinpad (int slot, int command, pininfo_t *pininfo) check_again: if (command == ISO7816_VERIFY) { - if (reader_table[slot].pcsc.verify_ioctl == (unsigned long)-1) + if (reader_table[slot].pcsc.verify_ioctl == (pcsc_dword_t)-1) return SW_NOT_SUPPORTED; else if (reader_table[slot].pcsc.verify_ioctl != 0) return 0; /* Success */ } else if (command == ISO7816_CHANGE_REFERENCE_DATA) { - if (reader_table[slot].pcsc.modify_ioctl == (unsigned long)-1) + if (reader_table[slot].pcsc.modify_ioctl == (pcsc_dword_t)-1) return SW_NOT_SUPPORTED; else if (reader_table[slot].pcsc.modify_ioctl != 0) return 0; /* Success */ @@ -2036,8 +2050,8 @@ check_pcsc_pinpad (int slot, int command, pininfo_t *pininfo) else return SW_NOT_SUPPORTED; - reader_table[slot].pcsc.verify_ioctl = (unsigned long)-1; - reader_table[slot].pcsc.modify_ioctl = (unsigned long)-1; + reader_table[slot].pcsc.verify_ioctl = (pcsc_dword_t)-1; + reader_table[slot].pcsc.modify_ioctl = (pcsc_dword_t)-1; sw = control_pcsc (slot, CM_IOCTL_GET_FEATURE_REQUEST, NULL, 0, buf, &len); if (sw) diff --git a/scd/pcsc-wrapper.c b/scd/pcsc-wrapper.c index 73b25f4..04d08a1 100644 --- a/scd/pcsc-wrapper.c +++ b/scd/pcsc-wrapper.c @@ -65,6 +65,12 @@ static int verbose; +#if defined(__APPLE__) || defined(_WIN32) || defined(__CYGWIN__) +typedef unsinged int pcsc_dword_t; +#else +typedef unsigned long pcsc_dword_t; +#endif + /* PC/SC constants and function pointer. */ #define PCSC_SCOPE_USER 0 @@ -112,16 +118,24 @@ struct pcsc_io_request_s { typedef struct pcsc_io_request_s *pcsc_io_request_t; +#ifdef __APPLE__ +#pragma pack(1) +#endif + struct pcsc_readerstate_s { const char *reader; void *user_data; - unsigned long current_state; - unsigned long event_state; - unsigned long atrlen; + pcsc_dword_t current_state; + pcsc_dword_t event_state; + pcsc_dword_t atrlen; unsigned char atr[33]; }; +#ifdef __APPLE__ +#pragma pack() +#endif + typedef struct pcsc_readerstate_s *pcsc_readerstate_t; @@ -129,62 +143,62 @@ static int driver_is_open; /* True if the PC/SC driver has been initialzied and is ready for operations. The following variables are then valid. */ -static unsigned long pcsc_context; /* The current PC/CS context. */ +static long pcsc_context; /* The current PC/CS context. */ static char *current_rdrname; -static unsigned long pcsc_card; -static unsigned long pcsc_protocol; +static long pcsc_card; +static pcsc_dword_t pcsc_protocol; static unsigned char current_atr[33]; static size_t current_atrlen; -long (* pcsc_establish_context) (unsigned long scope, +long (* pcsc_establish_context) (pcsc_dword_t scope, const void *reserved1, const void *reserved2, - unsigned long *r_context); -long (* pcsc_release_context) (unsigned long context); -long (* pcsc_list_readers) (unsigned long context, + long *r_context); +long (* pcsc_release_context) (long context); +long (* pcsc_list_readers) (long context, const char *groups, - char *readers, unsigned long*readerslen); -long (* pcsc_get_status_change) (unsigned long context, - unsigned long timeout, + char *readers, pcsc_dword_t *readerslen); +long (* pcsc_get_status_change) (long context, + pcsc_dword_t timeout, pcsc_readerstate_t readerstates, - unsigned long nreaderstates); -long (* pcsc_connect) (unsigned long context, + pcsc_dword_t nreaderstates); +long (* pcsc_connect) (long context, const char *reader, - unsigned long share_mode, - unsigned long preferred_protocols, - unsigned long *r_card, - unsigned long *r_active_protocol); -long (* pcsc_reconnect) (unsigned long card, - unsigned long share_mode, - unsigned long preferred_protocols, - unsigned long initialization, - unsigned long *r_active_protocol); -long (* pcsc_disconnect) (unsigned long card, - unsigned long disposition); -long (* pcsc_status) (unsigned long card, - char *reader, unsigned long *readerlen, - unsigned long *r_state, - unsigned long *r_protocol, - unsigned char *atr, unsigned long *atrlen); -long (* pcsc_begin_transaction) (unsigned long card); -long (* pcsc_end_transaction) (unsigned long card, - unsigned long disposition); -long (* pcsc_transmit) (unsigned long card, + pcsc_dword_t share_mode, + pcsc_dword_t preferred_protocols, + long *r_card, + pcsc_dword_t *r_active_protocol); +long (* pcsc_reconnect) (long card, + pcsc_dword_t share_mode, + pcsc_dword_t preferred_protocols, + pcsc_dword_t initialization, + pcsc_dword_t *r_active_protocol); +long (* pcsc_disconnect) (long card, + pcsc_dword_t disposition); +long (* pcsc_status) (long card, + char *reader, pcsc_dword_t *readerlen, + pcsc_dword_t *r_state, + pcsc_dword_t *r_protocol, + unsigned char *atr, pcsc_dword_t *atrlen); +long (* pcsc_begin_transaction) (long card); +long (* pcsc_end_transaction) (long card, + pcsc_dword_t disposition); +long (* pcsc_transmit) (long card, const pcsc_io_request_t send_pci, const unsigned char *send_buffer, - unsigned long send_len, + pcsc_dword_t send_len, pcsc_io_request_t recv_pci, unsigned char *recv_buffer, - unsigned long *recv_len); -long (* pcsc_set_timeout) (unsigned long context, - unsigned long timeout); -long (* pcsc_control) (unsigned long card, - unsigned long control_code, + pcsc_dword_t *recv_len); +long (* pcsc_set_timeout) (long context, + pcsc_dword_t timeout); +long (* pcsc_control) (long card, + pcsc_dword_t control_code, const void *send_buffer, - unsigned long send_len, + pcsc_dword_t send_len, void *recv_buffer, - unsigned long recv_len, - unsigned long *bytes_returned); + pcsc_dword_t recv_len, + pcsc_dword_t *bytes_returned); @@ -394,9 +408,9 @@ handle_open (unsigned char *argbuf, size_t arglen) long err; const char * portstr; char *list = NULL; - unsigned long nreader, atrlen; + pcsc_dword_t nreader, atrlen; char *p; - unsigned long card_state, card_protocol; + pcsc_dword_t card_state, card_protocol; unsigned char atr[33]; /* Make sure there is only the port string */ @@ -492,7 +506,7 @@ handle_open (unsigned char *argbuf, size_t arglen) if (!err) { char reader[250]; - unsigned long readerlen; + pcsc_dword_t readerlen; atrlen = 33; readerlen = sizeof reader -1; @@ -626,8 +640,8 @@ handle_reset (unsigned char *argbuf, size_t arglen) { long err; char reader[250]; - unsigned long nreader, atrlen; - unsigned long card_state, card_protocol; + pcsc_dword_t nreader, atrlen; + pcsc_dword_t card_state, card_protocol; (void)argbuf; (void)arglen; @@ -697,7 +711,7 @@ handle_transmit (unsigned char *argbuf, size_t arglen) { long err; struct pcsc_io_request_s send_pci; - unsigned long recv_len; + pcsc_dword_t recv_len; unsigned char buffer[1024]; /* The apdu should at least be one byte. */ @@ -737,8 +751,8 @@ static void handle_control (unsigned char *argbuf, size_t arglen) { long err; - unsigned long ioctl_code; - unsigned long recv_len = 1024; + pcsc_dword_t ioctl_code; + pcsc_dword_t recv_len = 1024; unsigned char buffer[1024]; if (arglen < 4) ----------------------------------------------------------------------- Summary of changes: scd/apdu.c | 128 +++++++++++++++++++++++++++++----------------------- scd/pcsc-wrapper.c | 118 +++++++++++++++++++++++++++--------------------- 2 files changed, 137 insertions(+), 109 deletions(-) hooks/post-receive -- The GNU Privacy Guard http://git.gnupg.org From cvs at cvs.gnupg.org Fri Mar 22 12:16:34 2013 From: cvs at cvs.gnupg.org (by Werner Koch) Date: Fri, 22 Mar 2013 12:16:34 +0100 Subject: [git] GCRYPT - branch, master, updated. libgcrypt-1.5.0-105-g8650b6c Message-ID: This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "The GNU crypto library". The branch, master has been updated via 8650b6ca7c77e477234f9a1586e6a86b1c79fff3 (commit) via d0c8fda5af45354ac32928c9a01e688d6893599d (commit) via 9f4df1612ae21a5ce70d98930cb194e5193f5e2d (commit) from 2a1e03c5a481689c43d197dd8034a1d73de0a1a4 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 8650b6ca7c77e477234f9a1586e6a86b1c79fff3 Author: Werner Koch Date: Fri Mar 22 11:57:46 2013 +0100 Add DCO by Christian Grothoff -- diff --git a/AUTHORS b/AUTHORS index b1bad22..67c46d9 100644 --- a/AUTHORS +++ b/AUTHORS @@ -1,7 +1,7 @@ Library: Libgcrypt Homepage: http://www.gnu.org/software/libgcrypt/ Maintainer: Werner Koch -Bug reports: or http://bugs.gnupg.org +Bug reports: http://bugs.gnupg.org Security related bug reports: License (library): LGPLv2.1+ License (manual and tools): GPLv2+ @@ -107,12 +107,26 @@ ulm at gentoo.org Authors with a DCO ================== -DCO:2012-04-16:Tom?? Mr?z -DCO:2012-04-20:Rafa?l Carr? -DCO:2012-11-14:Jussi Kivilinna -DCO:2012-12-05:Werner Koch -DCO:2012-12-14:Dmitry Kasatkin -DCO:2013-02-26:Christian Aistleitner +Christian Aistleitner +2013-02-26:20130226110144.GA12678 at quelltextlich.at: + +Christian Grothoff +2013-03-21:514B5D8A.6040705 at grothoff.org: + +Dmitry Kasatkin +2012-12-14:50CAE2DB.80302 at intel.com: + +Jussi Kivilinna +2012-11-15:20121115172331.150537dzb5i6jmy8 at www.dalek.fi: + +Rafa?l Carr? +2012-04-20:4F91988B.1080502 at videolan.org: + +Tom?? Mr?z +2012-04-16:1334571250.5056.52.camel at vespa.frost.loc: + +Werner Koch +2012-12-05:87obi8u4h2.fsf at vigenere.g10code.de: More credits commit d0c8fda5af45354ac32928c9a01e688d6893599d Author: Werner Koch Date: Fri Mar 22 11:44:15 2013 +0100 Replace deprecated AM_CONFIG_HEADER macro. * configure.ac: s/AM_CONFIG_HEADER/AC_CONFIG_HEADER/ diff --git a/configure.ac b/configure.ac index 2050824..cebf4b9 100644 --- a/configure.ac +++ b/configure.ac @@ -71,8 +71,8 @@ PACKAGE=$PACKAGE_NAME VERSION=$PACKAGE_VERSION AC_CONFIG_SRCDIR([src/libgcrypt.vers]) -AM_INIT_AUTOMAKE([]) -AM_CONFIG_HEADER(config.h) +AM_INIT_AUTOMAKE +AC_CONFIG_HEADER(config.h) AC_CONFIG_MACRO_DIR([m4]) AC_CONFIG_LIBOBJ_DIR([compat]) AC_CANONICAL_HOST commit 9f4df1612ae21a5ce70d98930cb194e5193f5e2d Author: Werner Koch Date: Fri Mar 22 11:41:11 2013 +0100 Disable AES-NI support if as does not support SSSE3. * configure.ac (HAVE_GCC_INLINE_ASM_SSSE3): New test. (ENABLE_AESNI_SUPPORT): Do not define without SSSE3 support. (HAVE_GCC_INLINE_ASM_SSSE3, ENABLE_AVX_SUPPORT): Split up detection and definition. -- For example the assembler of FreeBSD 7.3 does not know about pshufb and thus rijndael.c can't be compiled without using --disable-aesni-support. This check that the toolchain can use SSSE3 instructions before trying to build with AES_NI support. diff --git a/configure.ac b/configure.ac index 7504d76..2050824 100644 --- a/configure.ac +++ b/configure.ac @@ -541,10 +541,6 @@ AC_ARG_ENABLE(aesni-support, [Disable support for the Intel AES-NI instructions]), aesnisupport=$enableval,aesnisupport=yes) AC_MSG_RESULT($aesnisupport) -if test x"$aesnisupport" = xyes ; then - AC_DEFINE(ENABLE_AESNI_SUPPORT, 1, - [Enable support for Intel AES-NI instructions.]) -fi # Implementation of the --disable-drng-support switch. AC_MSG_CHECKING([whether DRNG support is requested]) @@ -852,6 +848,26 @@ fi # +# Check whether GCC inline assembler supports SSSE3 instructions +# This is required for the AES-NI instructions. +# +AC_CACHE_CHECK([whether GCC inline assembler supports SSSE3 instructions], + [gcry_cv_gcc_inline_asm_ssse3], + [gcry_cv_gcc_inline_asm_ssse3=no + AC_COMPILE_IFELSE([AC_LANG_SOURCE( + [[static unsigned char be_mask[16] __attribute__ ((aligned (16))) = + { 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 }; + void a(void) { + __asm__("pshufb %[mask], %%xmm2\n\t"::[mask]"m"(*be_mask):); + }]])], + [gcry_cv_gcc_inline_asm_ssse3=yes])]) +if test "$gcry_cv_gcc_inline_asm_ssse3" = "yes" ; then + AC_DEFINE(HAVE_GCC_INLINE_ASM_SSSE3,1, + [Defined if inline assembler supports SSSE3 instructions]) +fi + + +# # Check whether GCC inline assembler supports AVX instructions # AC_CACHE_CHECK([whether GCC inline assembler supports AVX instructions], @@ -865,15 +881,6 @@ AC_CACHE_CHECK([whether GCC inline assembler supports AVX instructions], if test "$gcry_cv_gcc_inline_asm_avx" = "yes" ; then AC_DEFINE(HAVE_GCC_INLINE_ASM_AVX,1, [Defined if inline assembler supports AVX instructions]) - - if test x"$avxsupport" = xyes ; then - AC_DEFINE(ENABLE_AVX_SUPPORT,1, - [Enable support for Intel AVX instructions.]) - fi -else - if test x"$avxsupport" = xyes ; then - avxsupport="no (unsupported by compiler)" - fi fi @@ -1113,6 +1120,30 @@ DATADIRNAME=$DATADIRNAME #### Conclusion. #### ##################### +# Check that requested feature can actually be used and define +# ENABLE_foo_SUPPORT macros. + +if test x"$aesnisupport" = xyes ; then + if test "$gcry_cv_gcc_inline_asm_ssse3" != "yes" ; then + aesnisupport="no (unsupported by compiler)" + fi +fi +if test x"$avxsupport" = xyes ; then + if test "$gcry_cv_gcc_inline_asm_avx" != "yes" ; then + avxsupport="no (unsupported by compiler)" + fi +fi + +if test x"$aesnisupport" = xyes ; then + AC_DEFINE(ENABLE_AESNI_SUPPORT, 1, + [Enable support for Intel AES-NI instructions.]) +fi +if test x"$avxsupport" = xyes ; then + AC_DEFINE(ENABLE_AVX_SUPPORT,1, + [Enable support for Intel AVX instructions.]) +fi + + # Define conditional sources and config.h symbols depending on the # selected ciphers, pubkey-ciphers, digests and random modules. ----------------------------------------------------------------------- Summary of changes: AUTHORS | 28 ++++++++++++++++++++------ configure.ac | 61 +++++++++++++++++++++++++++++++++++++++++++-------------- 2 files changed, 67 insertions(+), 22 deletions(-) hooks/post-receive -- The GNU crypto library http://git.gnupg.org From cvs at cvs.gnupg.org Tue Mar 26 00:58:57 2013 From: cvs at cvs.gnupg.org (by NIIBE Yutaka) Date: Tue, 26 Mar 2013 00:58:57 +0100 Subject: [git] GnuPG - branch, STABLE-BRANCH-2-0, updated. gnupg-2.0.19-94-ged0328d Message-ID: This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "The GNU Privacy Guard". The branch, STABLE-BRANCH-2-0 has been updated via ed0328d49ad7d3361e608330205c92a06a508d06 (commit) from ae22d629b6028aa994ff09f012e1cb029575eeae (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit ed0328d49ad7d3361e608330205c92a06a508d06 Author: NIIBE Yutaka Date: Tue Mar 26 08:43:15 2013 +0900 scd: call update_card_removed only when detecting removal. * scd/command.c (update_reader_status_file): Add condition ss->status == 0. -- To reproduce the bug: (1) insert card, (2) run "gpg2 --card-status", (3) remove card, (4) invoke "gpg2 --card-edit", (5) invoke some command like "verify" The last step fails (but with no error message to user). diff --git a/scd/command.c b/scd/command.c index e45153f..fc1f5a2 100644 --- a/scd/command.c +++ b/scd/command.c @@ -2310,10 +2310,8 @@ update_reader_status_file (int set_card_removed_flag) xfree (homestr); } - /* Set the card removed flag for all current sessions. We - will set this on any card change because a reset or - SERIALNO request must be done in any case. */ - if (ss->any && set_card_removed_flag) + /* Set the card removed flag for all current sessions. */ + if (ss->any && ss->status == 0 && set_card_removed_flag) update_card_removed (idx, 1); ss->any = 1; ----------------------------------------------------------------------- Summary of changes: scd/command.c | 6 ++---- 1 files changed, 2 insertions(+), 4 deletions(-) hooks/post-receive -- The GNU Privacy Guard http://git.gnupg.org From cvs at cvs.gnupg.org Tue Mar 26 01:26:21 2013 From: cvs at cvs.gnupg.org (by NIIBE Yutaka) Date: Tue, 26 Mar 2013 01:26:21 +0100 Subject: [git] GnuPG - branch, STABLE-BRANCH-2-0, updated. gnupg-2.0.19-95-g247bec6 Message-ID: This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "The GNU Privacy Guard". The branch, STABLE-BRANCH-2-0 has been updated via 247bec6a6f6a3358b38818a972430c7329f5b0d9 (commit) from ed0328d49ad7d3361e608330205c92a06a508d06 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 247bec6a6f6a3358b38818a972430c7329f5b0d9 Author: NIIBE Yutaka Date: Tue Mar 26 09:03:55 2013 +0900 scd: PC/SC cleanup (more). * scd/apdu.c (control_pcsc_direct, control_pcsc_wrapped, control_pcsc) (check_pcsc_pinpad, pcsc_pinpad_verify, pcsc_pinpad_modify): Use pcsc_dword_t. diff --git a/scd/apdu.c b/scd/apdu.c index 4734b12..d8f7c5f 100644 --- a/scd/apdu.c +++ b/scd/apdu.c @@ -1232,7 +1232,7 @@ pcsc_send_apdu (int slot, unsigned char *apdu, size_t apdulen, static int control_pcsc_direct (int slot, pcsc_dword_t ioctl_code, const unsigned char *cntlbuf, size_t len, - unsigned char *buffer, size_t *buflen) + unsigned char *buffer, pcsc_dword_t *buflen) { long err; @@ -1254,7 +1254,7 @@ control_pcsc_direct (int slot, pcsc_dword_t ioctl_code, static int control_pcsc_wrapped (int slot, pcsc_dword_t ioctl_code, const unsigned char *cntlbuf, size_t len, - unsigned char *buffer, size_t *buflen) + unsigned char *buffer, pcsc_dword_t *buflen) { long err = PCSC_E_NOT_TRANSACTED; reader_table_t slotp; @@ -1362,7 +1362,7 @@ control_pcsc_wrapped (int slot, pcsc_dword_t ioctl_code, static int control_pcsc (int slot, pcsc_dword_t ioctl_code, const unsigned char *cntlbuf, size_t len, - unsigned char *buffer, size_t *buflen) + unsigned char *buffer, pcsc_dword_t *buflen) { #ifdef NEED_PCSC_WRAPPER return control_pcsc_wrapped (slot, ioctl_code, cntlbuf, len, buffer, buflen); @@ -2027,7 +2027,7 @@ static int check_pcsc_pinpad (int slot, int command, pininfo_t *pininfo) { unsigned char buf[256]; - size_t len = 256; + pcsc_dword_t len = 256; int sw; (void)pininfo; /* XXX: Identify reader and set pininfo->fixedlen. */ @@ -2088,7 +2088,7 @@ pcsc_pinpad_verify (int slot, int class, int ins, int p0, int p1, unsigned char *pin_verify; int len = PIN_VERIFY_STRUCTURE_SIZE + pininfo->fixedlen; unsigned char result[2]; - size_t resultlen = 2; + pcsc_dword_t resultlen = 2; if (!reader_table[slot].atrlen && (sw = reset_pcsc_reader (slot))) @@ -2169,7 +2169,7 @@ pcsc_pinpad_modify (int slot, int class, int ins, int p0, int p1, unsigned char *pin_modify; int len = PIN_MODIFY_STRUCTURE_SIZE + 2 * pininfo->fixedlen; unsigned char result[2]; - size_t resultlen = 2; + pcsc_dword_t resultlen = 2; if (!reader_table[slot].atrlen && (sw = reset_pcsc_reader (slot))) ----------------------------------------------------------------------- Summary of changes: scd/apdu.c | 12 ++++++------ 1 files changed, 6 insertions(+), 6 deletions(-) hooks/post-receive -- The GNU Privacy Guard http://git.gnupg.org From cvs at cvs.gnupg.org Tue Mar 26 01:26:40 2013 From: cvs at cvs.gnupg.org (by NIIBE Yutaka) Date: Tue, 26 Mar 2013 01:26:40 +0100 Subject: [git] GnuPG - branch, master, updated. gnupg-2.1.0beta3-201-gb9aceaa Message-ID: This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "The GNU Privacy Guard". The branch, master has been updated via b9aceaa442914beb4f5359283053b43ba5a46b4c (commit) via 1062893832bb15eaac853f52e1cb673e5e03790a (commit) from ee95c23fcdc6673db0fc7287ab2197915d9b55b3 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit b9aceaa442914beb4f5359283053b43ba5a46b4c Author: NIIBE Yutaka Date: Tue Mar 26 09:03:55 2013 +0900 scd: PC/SC cleanup (more). * scd/apdu.c (control_pcsc_direct, control_pcsc_wrapped, control_pcsc) (check_pcsc_pinpad, pcsc_pinpad_verify, pcsc_pinpad_modify): Use pcsc_dword_t. diff --git a/scd/apdu.c b/scd/apdu.c index 0eb148e..87c0426 100644 --- a/scd/apdu.c +++ b/scd/apdu.c @@ -1211,7 +1211,7 @@ pcsc_send_apdu (int slot, unsigned char *apdu, size_t apdulen, static int control_pcsc_direct (int slot, pcsc_dword_t ioctl_code, const unsigned char *cntlbuf, size_t len, - unsigned char *buffer, size_t *buflen) + unsigned char *buffer, pcsc_dword_t *buflen) { long err; @@ -1233,7 +1233,7 @@ control_pcsc_direct (int slot, pcsc_dword_t ioctl_code, static int control_pcsc_wrapped (int slot, pcsc_dword_t ioctl_code, const unsigned char *cntlbuf, size_t len, - unsigned char *buffer, size_t *buflen) + unsigned char *buffer, pcsc_dword_t *buflen) { long err = PCSC_E_NOT_TRANSACTED; reader_table_t slotp; @@ -1342,7 +1342,7 @@ control_pcsc_wrapped (int slot, pcsc_dword_t ioctl_code, static int control_pcsc (int slot, pcsc_dword_t ioctl_code, const unsigned char *cntlbuf, size_t len, - unsigned char *buffer, size_t *buflen) + unsigned char *buffer, pcsc_dword_t *buflen) { #ifdef NEED_PCSC_WRAPPER return control_pcsc_wrapped (slot, ioctl_code, cntlbuf, len, buffer, buflen); @@ -1997,7 +1997,7 @@ static int check_pcsc_pinpad (int slot, int command, pininfo_t *pininfo) { unsigned char buf[256]; - size_t len = 256; + pcsc_dword_t len = 256; int sw; (void)pininfo; /* XXX: Identify reader and set pininfo->fixedlen. */ @@ -2058,7 +2058,7 @@ pcsc_pinpad_verify (int slot, int class, int ins, int p0, int p1, unsigned char *pin_verify; int len = PIN_VERIFY_STRUCTURE_SIZE + pininfo->fixedlen; unsigned char result[2]; - size_t resultlen = 2; + pcsc_dword_t resultlen = 2; if (!reader_table[slot].atrlen && (sw = reset_pcsc_reader (slot))) @@ -2141,7 +2141,7 @@ pcsc_pinpad_modify (int slot, int class, int ins, int p0, int p1, unsigned char *pin_modify; int len = PIN_MODIFY_STRUCTURE_SIZE + 2 * pininfo->fixedlen; unsigned char result[2]; - size_t resultlen = 2; + pcsc_dword_t resultlen = 2; if (!reader_table[slot].atrlen && (sw = reset_pcsc_reader (slot))) commit 1062893832bb15eaac853f52e1cb673e5e03790a Author: NIIBE Yutaka Date: Tue Mar 26 08:43:15 2013 +0900 scd: call update_card_removed only when detecting removal. * scd/command.c (update_reader_status_file): Add condition vr->status == 0. -- To reproduce the bug: (1) insert card, (2) run "gpg2 --card-status", (3) remove card, (4) invoke "gpg2 --card-edit", (5) invoke some command like "verify" The last step fails (but with no error message to user). diff --git a/scd/command.c b/scd/command.c index 6267bb0..d5cc32c 100644 --- a/scd/command.c +++ b/scd/command.c @@ -2365,10 +2365,8 @@ update_reader_status_file (int set_card_removed_flag) xfree (homestr); } - /* Set the card removed flag for all current sessions. We - will set this on any card change because a reset or - SERIALNO request must be done in any case. */ - if (vr->any && set_card_removed_flag) + /* Set the card removed flag for all current sessions. */ + if (vr->any && vr->status == 0 && set_card_removed_flag) update_card_removed (idx, 1); vr->any = 1; ----------------------------------------------------------------------- Summary of changes: scd/apdu.c | 12 ++++++------ scd/command.c | 6 ++---- 2 files changed, 8 insertions(+), 10 deletions(-) hooks/post-receive -- The GNU Privacy Guard http://git.gnupg.org From cvs at cvs.gnupg.org Tue Mar 26 05:03:11 2013 From: cvs at cvs.gnupg.org (by NIIBE Yutaka) Date: Tue, 26 Mar 2013 05:03:11 +0100 Subject: [git] GnuPG - branch, master, updated. gnupg-2.1.0beta3-202-g64b1a2c Message-ID: This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "The GNU Privacy Guard". The branch, master has been updated via 64b1a2cf6f18348544a2d2cd4d49fd27bf01c150 (commit) from b9aceaa442914beb4f5359283053b43ba5a46b4c (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 64b1a2cf6f18348544a2d2cd4d49fd27bf01c150 Author: NIIBE Yutaka Date: Tue Mar 26 12:43:24 2013 +0900 scd: PC/SC status fix. * scd/apdu.c (pcsc_get_status_direct): Check PCSC_STATE_MUTE only when PCSC_STATE_PRESENT. * scd/pcsc-wrapper.c (handle_status): Ditto. diff --git a/scd/apdu.c b/scd/apdu.c index 87c0426..92c9864 100644 --- a/scd/apdu.c +++ b/scd/apdu.c @@ -891,9 +891,11 @@ pcsc_get_status_direct (int slot, unsigned int *status) *status = 0; if ( (rdrstates[0].event_state & PCSC_STATE_PRESENT) ) - *status |= APDU_CARD_PRESENT; - if ( !(rdrstates[0].event_state & PCSC_STATE_MUTE) ) - *status |= APDU_CARD_ACTIVE; + { + *status |= APDU_CARD_PRESENT; + if ( !(rdrstates[0].event_state & PCSC_STATE_MUTE) ) + *status |= APDU_CARD_ACTIVE; + } #ifndef HAVE_W32_SYSTEM /* We indicate a useful card if it is not in use by another application. This is because we only use exclusive access diff --git a/scd/pcsc-wrapper.c b/scd/pcsc-wrapper.c index a135d1e..86e4afb 100644 --- a/scd/pcsc-wrapper.c +++ b/scd/pcsc-wrapper.c @@ -602,9 +602,11 @@ handle_status (unsigned char *argbuf, size_t arglen) if ( !(rdrstates[0].event_state & PCSC_STATE_UNKNOWN) ) { if ( (rdrstates[0].event_state & PCSC_STATE_PRESENT) ) - status |= 2; - if ( !(rdrstates[0].event_state & PCSC_STATE_MUTE) ) - status |= 4; + { + status |= 2; + if ( !(rdrstates[0].event_state & PCSC_STATE_MUTE) ) + status |= 4; + } /* We indicate a useful card if it is not in use by another application. This is because we only use exclusive access mode. */ ----------------------------------------------------------------------- Summary of changes: scd/apdu.c | 8 +++++--- scd/pcsc-wrapper.c | 8 +++++--- 2 files changed, 10 insertions(+), 6 deletions(-) hooks/post-receive -- The GNU Privacy Guard http://git.gnupg.org From cvs at cvs.gnupg.org Tue Mar 26 05:03:30 2013 From: cvs at cvs.gnupg.org (by NIIBE Yutaka) Date: Tue, 26 Mar 2013 05:03:30 +0100 Subject: [git] GnuPG - branch, STABLE-BRANCH-2-0, updated. gnupg-2.0.19-96-gc349520 Message-ID: This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "The GNU Privacy Guard". The branch, STABLE-BRANCH-2-0 has been updated via c3495209ee6bdac6d6c631ded632fd540596f6e4 (commit) from 247bec6a6f6a3358b38818a972430c7329f5b0d9 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit c3495209ee6bdac6d6c631ded632fd540596f6e4 Author: NIIBE Yutaka Date: Tue Mar 26 12:43:24 2013 +0900 scd: PC/SC status fix. * scd/apdu.c (pcsc_get_status_direct): Check PCSC_STATE_MUTE only when PCSC_STATE_PRESENT. * scd/pcsc-wrapper.c (handle_status): Ditto. diff --git a/scd/apdu.c b/scd/apdu.c index d8f7c5f..4f40a69 100644 --- a/scd/apdu.c +++ b/scd/apdu.c @@ -914,9 +914,11 @@ pcsc_get_status_direct (int slot, unsigned int *status) *status = 0; if ( (rdrstates[0].event_state & PCSC_STATE_PRESENT) ) - *status |= APDU_CARD_PRESENT; - if ( !(rdrstates[0].event_state & PCSC_STATE_MUTE) ) - *status |= APDU_CARD_ACTIVE; + { + *status |= APDU_CARD_PRESENT; + if ( !(rdrstates[0].event_state & PCSC_STATE_MUTE) ) + *status |= APDU_CARD_ACTIVE; + } #ifndef HAVE_W32_SYSTEM /* We indicate a useful card if it is not in use by another application. This is because we only use exclusive access diff --git a/scd/pcsc-wrapper.c b/scd/pcsc-wrapper.c index 04d08a1..7d9415a 100644 --- a/scd/pcsc-wrapper.c +++ b/scd/pcsc-wrapper.c @@ -602,9 +602,11 @@ handle_status (unsigned char *argbuf, size_t arglen) if ( !(rdrstates[0].event_state & PCSC_STATE_UNKNOWN) ) { if ( (rdrstates[0].event_state & PCSC_STATE_PRESENT) ) - status |= 2; - if ( !(rdrstates[0].event_state & PCSC_STATE_MUTE) ) - status |= 4; + { + status |= 2; + if ( !(rdrstates[0].event_state & PCSC_STATE_MUTE) ) + status |= 4; + } /* We indicate a useful card if it is not in use by another application. This is because we only use exclusive access mode. */ ----------------------------------------------------------------------- Summary of changes: scd/apdu.c | 8 +++++--- scd/pcsc-wrapper.c | 8 +++++--- 2 files changed, 10 insertions(+), 6 deletions(-) hooks/post-receive -- The GNU Privacy Guard http://git.gnupg.org From cvs at cvs.gnupg.org Fri Mar 29 09:29:37 2013 From: cvs at cvs.gnupg.org (by Werner Koch) Date: Fri, 29 Mar 2013 09:29:37 +0100 Subject: [git] GnuPG - branch, master, updated. gnupg-2.1.0beta3-203-g0722727 Message-ID: This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "The GNU Privacy Guard". The branch, master has been updated via 07227279c44e3af0939f90025a0d22b782d0f185 (commit) from 64b1a2cf6f18348544a2d2cd4d49fd27bf01c150 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 07227279c44e3af0939f90025a0d22b782d0f185 Author: Werner Koch Date: Fri Mar 29 09:13:05 2013 +0100 copyright assignments are not anymore required. diff --git a/AUTHORS b/AUTHORS index cfcf984..374111b 100644 --- a/AUTHORS +++ b/AUTHORS @@ -6,8 +6,8 @@ Security related bug reports: License: GPLv3+ -Authors -======= +Authors with a FSF copyright assignment +======================================= Ales Nyakhaychyk Translations [be] @@ -131,11 +131,19 @@ Yutaka Niibe Assigns Past and Future Changes (scd/) +Authors with a DCO +================== + +Werner Koch +2013-03-29:87620ahchj.fsf at vigenere.g10code.de: + + Other authors ============= -The need for copyright disclaimers for translations has been waived in -December 2012. +The need for copyright assignments to the FSF has been waived on +2013-03-29; the need for copyright disclaimers for translations +already in December 2012. The files common/libestream.[ch] are maintained as a separate project by g10 Code GmbH. These files, as used here, are considered part of @@ -181,7 +189,7 @@ name gpg2keys_*. Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, - 2012 Free Software Foundation, Inc. + 2012, 2013 Free Software Foundation, Inc. This file is free software; as a special exception the author gives unlimited permission to copy and/or distribute it, with or without diff --git a/doc/HACKING b/doc/HACKING index 0ef5b89..8116c3f 100644 --- a/doc/HACKING +++ b/doc/HACKING @@ -1,9 +1,15 @@ - A Hacker's Guide to GNUPG - ================================ - (Some notes on GNUPG internals.) +# HACKING -*- org -*- +#+TITLE: A Hacker's Guide to GnuPG +#+TEXT: Some notes on GnuPG internals +#+STARTUP: showall +#+OPTIONS: ^:{} +* How to contribute -* No more ChangeLog files + The following stuff explains some basic procedures you need to + follow if you want to contribute code or documentation. + +** No more ChangeLog files Do not modify any of the ChangeLog files in GnuPG. Starting on December 1st, 2011 we put change information only in the GIT commit @@ -12,26 +18,88 @@ time. As such, there are strict requirements on the form of the commit log messages. The old ChangeLog files have all be renamed to ChangeLog-2011 +** Commit log requirements + +Your commit log should always start with a one-line summary, the +second line should be blank, and the remaining lines are usually +ChangeLog-style entries for all affected files. However, it's fine +--- even recommended --- to write a few lines of prose describing the +change, when the summary and ChangeLog entries don't give enough of +the big picture. Omit the leading TABs that you are seeing in a +"real" ChangeLog file, but keep the maximum line length at 72 or +smaller, so that the generated ChangeLog lines, each with its leading +TAB, will not exceed 80 columns. If you want to add text which shall +not be copied to the ChangeLog, separate it by a line consisting of +two dashes at the begin of a line. + +Typo fixes and documentation updates don't need a ChangeLog Entry, +thus you would use a commit message like + +#+begin_example +Fix type in a comment + +-- +#+end_example + +The marker line here is important; without it the first line would +appear in the ChangeLog. + +** License policy + + GnuPG is licensed under the GPLv3+ with some files under a mixed + LGPLv3+/GPLv2+ license. It is thus important, that all contributed + code allows for an update of the license; for example we can't + accept code under the GPLv2(only). + + GnuPG used to have a strict policy of requiring copyright + assignments to the FSF. To avoid this major organizational overhead + and to allow inclusion of code, not copyrighted by the FSF, this + policy has been relaxed on 2013-03-29. It is now also possible to + contribute code by asserting that the contribution is in accordance + to the "Libgcrypt Developer's Certificate of Origin" as found in the + file "DCO". (Except for a slight wording change, this DCO is + identical to the one used by the Linux kernel.) + + If your want to contribute code or documentation to GnuPG and you + didn't signed a copyright assignment with the FSF in the past, you + need to take these simple steps: + + - Decide which mail address you want to use. Please have your real + name in the address and not a pseudonym. Anonymous contributions + can only be done if you find a proxy who certifies for you. -* Commit log requirements + - If your employer or school might claim ownership of code written + by you; you need to talk to them to make sure that you have the + right to contribute under the DCO. -Your commit log should always start with a one-line summary, the second -line should be blank, and the remaining lines are usually ChangeLog-style -entries for all affected files. However, it's fine -- even recommended -- -to write a few lines of prose describing the change, when the summary -and ChangeLog entries don't give enough of the big picture. Omit the -leading TABs that you're used to seeing in a "real" ChangeLog file, but -keep the maximum line length at 72 or smaller, so that the generated -ChangeLog lines, each with its leading TAB, will not exceed 80 columns. -If you want to add text which shall not be copied to the ChangeLog, -separate it by a line consisting of two dashes at the begin of a line. + - Send an OpenPGP signed mail to the gnupg-devel at gnupg.org mailing + list from your mail address. Include a copy of the DCO as found + in the official master branch. Insert your name and email address + into the DCO in the same way you want to use it later. Example: + Signed-off-by: Joe R. Hacker -===> What follows is probably out of date <=== + (If you really need it, you may perform simple transformations of + the mail address: Replacing "@" by " at " or "." by " dot ".) + - That's it. From now on you only need to add a "Signed-off-by:" + line with your name and mail address to the commit message. It is + recommended to send the patches using a PGP/MIME signed mail. -RFCs -==== +** Coding standards + + Please follow the GNU coding standards. If you are in doubt consult + the existing code as an example. Do no re-indent code without a + need. If you really need to do it, use a separate commit for such a + change. + +* Debug hints + + See the manual for some hints. + +* Standards + +** RFCs 1423 Privacy Enhancement for Internet Electronic Mail: Part III: Algorithms, Modes, and Identifiers. @@ -52,110 +120,110 @@ RFCs 4880 Current OpenPGP specification. +* Various information + +** Directory Layout + + - ./ :: Readme, configure + - ./agent :: Gpg-agent and related tools + - ./doc :: Documentation + - ./g10 :: Gpg program here called gpg2 + - ./sm :: Gpgsm program + - ./jnlib :: Not used (formerly used utility functions) + - ./common :: Utility functions + - ./kbx :: Keybox library + - ./scd :: Smartcard daemon + - ./scripts :: Scripts needed by configure and others + - ./dirmngr :: The directory manager + +** Detailed Roadmap + + This list of file is not up to date! + + - g10/gpg.c :: Main module with option parsing and all the stuff you + have to do on startup. Also has the exout handler + and some helper functions. + + - g10/sign.c :: Create signature and optionally encrypt + + - g10/parse-packet.c :: + - g10/build-packet.c :: + - g10/free-packet.c :: Parsing and creating of OpenPGP message packets. + + - g10/getkey.c :: Key selection code + - g10/pkclist.c :: Build a list of public keys + - g10/skclist.c :: Build a list of secret keys + - g10/ringedit.c :: Keyring I/O + - g10/keydb.h :: + + - g10/keyid.c :: Helper functions to get the keyid, fingerprint etc. + + + - g10/trustdb.c :: + - g10/trustdb.h :: + - g10/tdbdump.c :: Management of the trustdb.gpg + - g10/tdbio.c :: + - g10/tdbio.h :: I/O handling for the trustdb.gpg + + - g10/compress.c :: Filter to handle compression + - g10/filter.h :: Declarations for all filter functions + - g10/delkey.c :: Delete a key + - g10/kbnode.c :: Helper for the KBNODE linked list + - g10/main.h :: Prototypes and some constants + - g10/mainproc.c :: Message processing + - g10/armor.c :: Ascii armor filter + - g10/mdfilter.c :: Filter to calculate hashs + - g10/textfilter.c :: Filter to handle CR/LF and trailing white space + - g10/cipher.c :: En-/Decryption filter + - g10/misc.c :: Utlity functions + - g10/options.h :: Structure with all the command line options + and related constants + - g10/openfile.c :: Create/Open Files + - g10/hkp.h :: Keyserver access + - g10/hkp.c :: Ditto. + - g10/packet.h :: Defintion of OpenPGP structures. + - g10/passphrase.c :: Passphrase handling code + + - g10/pubkey-enc.c :: + - g10/seckey-cert.c :: + - g10/seskey.c :: + - g10/import.c :: + - g10/export.c :: + - g10/comment.c :: + - g10/status.c :: + - g10/status.h :: + - g10/sign.c :: + - g10/plaintext.c :: + - g10/encr-data.c :: + - g10/encode.c :: + - g10/revoke.c :: + - g10/keylist.c :: + - g10/sig-check.c :: + - g10/signal.c :: + - g10/helptext.c :: + - g10/verify.c :: + - g10/decrypt.c :: + - g10/keyedit.c :: + - g10/dearmor.c :: + - g10/keygen.c :: + +** Memory allocation - -Directory Layout ----------------- - ./ Readme, configure - ./agent Gpg-agent and related tools - ./doc Documentation - ./doc Documentation - ./g10 Gpg program here called gpg2 - ./jnlib Utility functions - ./kbx Keybox library - ./scd Smartcard daemon - ./scripts Scripts needed by configure and others - ./sm Gpgsm program - - -Detailed Roadmap ----------------- -g10/gpg.c Main module with option parsing and all the stuff you have - to do on startup. Also has the exout handler and some - helper functions. -g10/sign.c Create signature and optionally encrypt - -g10/parse-packet.c -g10/build-packet.c -g10/free-packet.c - Parsing and creating of OpenPGP message packets. - -g10/getkey.c Key selection code -g10/pkclist.c Build a list of public keys -g10/skclist.c Build a list of secret keys -g10/ringedit.c Keyring I/O -g10/keydb.h - -g10/keyid.c Helper functions to get the keyid, fingerprint etc. - - -g10/trustdb.c -g10/trustdb.h -g10/tdbdump.c - Management of the trustdb.gpg - -g10/compress.c Filter to handle compression -g10/filter.h Declarations for all filter functions -g10/delkey.c Delete a key -g10/kbnode.c Helper for the KBNODE linked list -g10/main.h Prototypes and some constants -g10/mainproc.c Message processing -g10/armor.c Ascii armor filter -g10/mdfilter.c Filter to calculate hashs -g10/textfilter.c Filter to handle CR/LF and trailing white space -g10/cipher.c En-/Decryption filter -g10/misc.c Utlity functions -g10/options.h Structure with all the command line options - and related constants -g10/openfile.c Create/Open Files -g10/tdbio.c I/O handling for the trustdb.gpg -g10/tdbio.h -g10/hkp.h Keyserver access -g10/hkp.c -g10/packet.h Defintion of OpenPGP structures. -g10/passphrase.c Passphrase handling code -g10/pubkey-enc.c -g10/seckey-cert.c -g10/seskey.c -g10/import.c -g10/export.c -g10/comment.c -g10/status.c -g10/status.h -g10/sign.c -g10/plaintext.c -g10/encr-data.c -g10/encode.c -g10/revoke.c -g10/keylist.c -g10/sig-check.c -g10/signal.c -g10/helptext.c -g10/verify.c -g10/decrypt.c -g10/keyedit.c -g10/dearmor.c -g10/keygen.c - - - -Memory allocation ------------------ Use only the functions: - xmalloc - xmalloc_secure - xtrymalloc - xtrymalloc_secure - xcalloc - xcalloc_secure - xtrycalloc - xtrycalloc_secure - xrealloc - xtryrealloc - xstrdup - xtrystrdup - xfree + - xmalloc + - xmalloc_secure + - xtrymalloc + - xtrymalloc_secure + - xcalloc + - xcalloc_secure + - xtrycalloc + - xtrycalloc_secure + - xrealloc + - xtryrealloc + - xstrdup + - xtrystrdup + - xfree The *secure versions allocated memory in the secure memory. That is, @@ -166,37 +234,31 @@ k. In general the function don't print a memeory message and terminate the process if there is not enough memory available. The "try" versions of the functions return NULL instead. +** Logging -Logging -------- - - - - - + TODO -Option parsing ---------------- -GNUPG does not use getopt or GNU getopt but functions of it's own. See -util/argparse.c for details. The advantage of these functions is that -it is more easy to display and maintain the help texts for the options. -The same option table is also used to parse resource files. +** Option parsing +GnuPG does not use getopt or GNU getopt but functions of it's own. +See util/argparse.c for details. The advantage of these functions is +that it is more easy to display and maintain the help texts for the +options. The same option table is also used to parse resource files. +** What is an IOBUF -What is an IOBUF ----------------- -This is the data structure used for most I/O of gnupg. It is similar -to System V Streams but much simpler. Because OpenPGP messages are nested -in different ways; the use of such a system has big advantages. Here is -an example, how it works: If the parser sees a packet header with a partial -length, it pushes the block_filter onto the IOBUF to handle these partial -length packets: from now on you don't have to worry about this. When it sees -a compressed packet it pushes the uncompress filter and the next read byte -is one which has already been uncompressed by this filter. Same goes for -enciphered packet, plaintext packets and so on. The file g10/encode.c -might be a good staring point to see how it is used - actually this is -the other way: constructing messages using pushed filters but it may be -easier to understand. +This is the data structure used for most I/O of gnupg. It is similar +to System?V Streams but much simpler. Because OpenPGP messages are +nested in different ways; the use of such a system has big advantages. +Here is an example, how it works: If the parser sees a packet header +with a partial length, it pushes the block_filter onto the IOBUF to +handle these partial length packets: from now on you don't have to +worry about this. When it sees a compressed packet it pushes the +uncompress filter and the next read byte is one which has already been +uncompressed by this filter. Same goes for enciphered packet, +plaintext packets and so on. The file g10/encode.c might be a good +staring point to see how it is used - actually this is the other way: +constructing messages using pushed filters but it may be easier to +understand. diff --git a/doc/Makefile.am b/doc/Makefile.am index 9a46a07..17d5997 100644 --- a/doc/Makefile.am +++ b/doc/Makefile.am @@ -43,7 +43,7 @@ info_TEXINFOS = gnupg.texi dist_pkgdata_DATA = qualified.txt com-certs.pem $(helpfiles) -nobase_dist_doc_DATA = FAQ DETAILS HACKING TRANSLATE OpenPGP KEYSERVER \ +nobase_dist_doc_DATA = FAQ DETAILS HACKING DCO TRANSLATE OpenPGP KEYSERVER \ $(examples) #dist_html_DATA = diff --git a/doc/TRANSLATE b/doc/TRANSLATE index 8dfc183..38a6fd9 100644 --- a/doc/TRANSLATE +++ b/doc/TRANSLATE @@ -57,6 +57,5 @@ also strongly advise to get subscribed to i18n at gnupg.org and request assistance if it is not clear on how to translate certain strings. A wrongly translated string may lead to a security problem. -A copyright disclaimer to the FSF is required by all translators. - - +A copyright disclaimer to the FSF is not anymore required since +December 2012. ----------------------------------------------------------------------- Summary of changes: AUTHORS | 18 ++- doc/HACKING | 354 ++++++++++++++++++++++++++++++++----------------------- doc/Makefile.am | 2 +- doc/TRANSLATE | 5 +- 4 files changed, 224 insertions(+), 155 deletions(-) hooks/post-receive -- The GNU Privacy Guard http://git.gnupg.org