From cvs at cvs.gnupg.org Fri Aug 1 12:48:38 2008 From: cvs at cvs.gnupg.org (svn author wk) Date: Fri, 01 Aug 2008 12:48:38 +0200 Subject: [svn] GnuPG - r4804 - branches/STABLE-BRANCH-1-4/g10 Message-ID: Author: wk Date: 2008-08-01 12:48:36 +0200 (Fri, 01 Aug 2008) New Revision: 4804 Modified: branches/STABLE-BRANCH-1-4/g10/ChangeLog branches/STABLE-BRANCH-1-4/g10/tdbio.c Log: Fix !EROFS bug Modified: branches/STABLE-BRANCH-1-4/g10/ChangeLog =================================================================== --- branches/STABLE-BRANCH-1-4/g10/ChangeLog 2008-07-30 10:25:18 UTC (rev 4803) +++ branches/STABLE-BRANCH-1-4/g10/ChangeLog 2008-08-01 10:48:36 UTC (rev 4804) @@ -1,3 +1,8 @@ +2008-08-01 Werner Koch + + * tdbio.c (open_db) [!EROFS]: Move closing parens out of the + ifdef. Reported by Ken Takusagawa. + 2008-04-30 Werner Koch * getkey.c (parse_auto_key_locate): Ignore nodefault and local Modified: branches/STABLE-BRANCH-1-4/g10/tdbio.c =================================================================== --- branches/STABLE-BRANCH-1-4/g10/tdbio.c 2008-07-30 10:25:18 UTC (rev 4803) +++ branches/STABLE-BRANCH-1-4/g10/tdbio.c 2008-08-01 10:48:36 UTC (rev 4804) @@ -592,8 +592,9 @@ db_fd = open (db_name, O_RDWR | MY_O_BINARY ); if (db_fd == -1 && (errno == EACCES #ifdef EROFS - || errno == EROFS) + || errno == EROFS #endif + ) ) { db_fd = open (db_name, O_RDONLY | MY_O_BINARY ); if (db_fd != -1) From cvs at cvs.gnupg.org Fri Aug 1 12:51:14 2008 From: cvs at cvs.gnupg.org (svn author wk) Date: Fri, 01 Aug 2008 12:51:14 +0200 Subject: [svn] GnuPG - r4805 - in trunk: . doc g10 tools Message-ID: Author: wk Date: 2008-08-01 12:51:11 +0200 (Fri, 01 Aug 2008) New Revision: 4805 Modified: trunk/THANKS trunk/doc/ChangeLog trunk/doc/debugging.texi trunk/doc/gpgsm.texi trunk/doc/scdaemon.texi trunk/g10/ChangeLog trunk/g10/tdbio.c trunk/tools/ChangeLog Log: Fix !EROFS bug. Doc updates Modified: trunk/doc/ChangeLog =================================================================== --- trunk/doc/ChangeLog 2008-08-01 10:48:36 UTC (rev 4804) +++ trunk/doc/ChangeLog 2008-08-01 10:51:11 UTC (rev 4805) @@ -1,3 +1,7 @@ +2008-07-30 Werner Koch + + * gpgsm.texi (GPGSM Configuration): Mention com-cert.pem. + 2008-06-25 Werner Koch * qualified.txt: Add new BnetzA certs 12R and 13R. Modified: trunk/g10/ChangeLog =================================================================== --- trunk/g10/ChangeLog 2008-08-01 10:48:36 UTC (rev 4804) +++ trunk/g10/ChangeLog 2008-08-01 10:51:11 UTC (rev 4805) @@ -1,3 +1,8 @@ +2008-08-01 Werner Koch + + * tdbio.c (open_db) [!EROFS]: Move closing parens out of the + ifdef. Reported by Ken Takusagawa. + 2008-06-25 Marcus Brinkmann * gpg.c (enum cmd_and_opt_values): Remove option Modified: trunk/tools/ChangeLog =================================================================== --- trunk/tools/ChangeLog 2008-08-01 10:48:36 UTC (rev 4804) +++ trunk/tools/ChangeLog 2008-08-01 10:51:11 UTC (rev 4805) @@ -1,7 +1,7 @@ 2008-06-19 Werner Koch * gpgconf-comp.c (GC_ARG_TYPE_ALIAS_LIST): New. - (gc_arg_type): Add fallbacl type. + (gc_arg_type): Add fallback type. (gc_options_gpg): Add option "group". 2008-06-12 Marcus Brinkmann Modified: trunk/THANKS =================================================================== --- trunk/THANKS 2008-08-01 10:48:36 UTC (rev 4804) +++ trunk/THANKS 2008-08-01 10:51:11 UTC (rev 4805) @@ -138,6 +138,7 @@ Kazu Yamamoto kazu at iij.ad.jp Kazuyoshi Kakihara Keith Clayton keith at claytons.org +Ken Takusagawa ken.takusagawa.2 at gmail.com Kevin Ryde user42 at zip.com.au Klaus Singvogel ks at caldera.de Kurt Garloff garloff at suse.de Modified: trunk/doc/debugging.texi =================================================================== --- trunk/doc/debugging.texi 2008-08-01 10:48:36 UTC (rev 4804) +++ trunk/doc/debugging.texi 2008-08-01 10:51:11 UTC (rev 4805) @@ -208,6 +208,26 @@ number N is the internal algorighm indentifier; for example 8 refers to SHA-256. + + at item The Windows version does not work under Wine + +When running the W32 version of @command{gpg} under Wine you may get +an error messages like: + + at smallexample +gpg: fatal: WriteConsole failed: Access denied + at end smallexample + + at noindent +The solution is to use the command @command{wineconsole}. + +Some operations like gen-key really want to talk to the console directly +for increased security (for example to prevent the passphrase from +appearing on the screen). So, you should use @command{wineconsole} +instead of @command{wine}, which will launch a windows console that +implements those additional features. + + @end itemize Modified: trunk/doc/gpgsm.texi =================================================================== --- trunk/doc/gpgsm.texi 2008-08-01 10:48:36 UTC (rev 4804) +++ trunk/doc/gpgsm.texi 2008-08-01 10:51:11 UTC (rev 4805) @@ -787,6 +787,14 @@ @file{help.txt} file. + at item com-certs.pem + at cindex com-certs.pem +This file is a collection of common certificates used to populated a +newly created @file{pubring.kbx}. An administrator may replace this +file with a custom one. The format is a concatenation of PEM encoded +X.509 certificates. This global file is installed in the data directory +(e.g. @file{/usr/share/gnupg/qualified.txt}). + @end table @c man:.RE @@ -796,7 +804,7 @@ helper script is provided to create these files (@pxref{addgnupghome}). For internal purposes gpgsm creates and maintaines a few other files; -They all live in in the current home directory (@pxref{option +they all live in in the current home directory (@pxref{option --homedir}). Only @command{gpgsm} may modify these files. @@ -806,7 +814,7 @@ This a database file storing the certificates as well as meta information. For debugging purposes the tool @command{kbxutil} may be used to show the internal structure of this file. - + @item random_seed @cindex random_seed This content of this file is used to maintain the internal state of the Modified: trunk/doc/scdaemon.texi =================================================================== --- trunk/doc/scdaemon.texi 2008-08-01 10:48:36 UTC (rev 4804) +++ trunk/doc/scdaemon.texi 2008-08-01 10:51:11 UTC (rev 4805) @@ -266,7 +266,7 @@ where this is supported. Currently we support it for the OpenPGP card. Deny is the default. This commands is useful to inhibit accidental access to admin class command which could ultimately lock -the card through worng PIN numbers. +the card through wrong PIN numbers. @item --disable-application @var{name} @opindex disable-application Modified: trunk/g10/tdbio.c =================================================================== --- trunk/g10/tdbio.c 2008-08-01 10:48:36 UTC (rev 4804) +++ trunk/g10/tdbio.c 2008-08-01 10:51:11 UTC (rev 4805) @@ -603,8 +603,9 @@ db_fd = open (db_name, O_RDWR | MY_O_BINARY ); if (db_fd == -1 && (errno == EACCES #ifdef EROFS - || errno == EROFS) + || errno == EROFS #endif + ) ) { db_fd = open (db_name, O_RDONLY | MY_O_BINARY ); if (db_fd != -1) From cvs at cvs.gnupg.org Fri Aug 1 14:04:31 2008 From: cvs at cvs.gnupg.org (svn author marcus) Date: Fri, 01 Aug 2008 14:04:31 +0200 Subject: [svn] GpgEX - r58 - trunk Message-ID: Author: marcus Date: 2008-08-01 14:04:30 +0200 (Fri, 01 Aug 2008) New Revision: 58 Added: trunk/TODO Log: Add todo file. From cvs at cvs.gnupg.org Fri Aug 1 15:53:16 2008 From: cvs at cvs.gnupg.org (svn author wk) Date: Fri, 01 Aug 2008 15:53:16 +0200 Subject: [svn] GpgOL - r263 - in trunk: . src Message-ID: Author: wk Date: 2008-08-01 15:53:15 +0200 (Fri, 01 Aug 2008) New Revision: 263 Modified: trunk/NEWS trunk/src/ChangeLog trunk/src/common.h trunk/src/ext-commands.cpp trunk/src/ext-commands.h trunk/src/mapihelp.cpp trunk/src/mapihelp.h trunk/src/message-events.cpp trunk/src/message.cpp trunk/src/session-events.cpp trunk/src/user-events.cpp Log: Reverting a folder is now possible. Modified: trunk/src/ChangeLog =================================================================== --- trunk/src/ChangeLog 2008-07-30 17:53:36 UTC (rev 262) +++ trunk/src/ChangeLog 2008-08-01 13:53:15 UTC (rev 263) @@ -1,5 +1,17 @@ -2008-07-30 Werner Koch +2008-07-31 Werner Koch + * ext-commands.h (class GpgolExtCommands): Add m_nCmdRevertFolder. + * ext-commands.cpp (GpgolExtCommands, InstallCommands): Ditto. + (DoCommand): Implement RevertFolder command. + + * common.h (struct): Add variable DISABLE_GPGOL. + * session-events.cpp (OnDelivery): Make use of that variable. + * message.cpp (message_incoming_handler): Ditto. + * user-events.cpp (OnSelectionChange): Ditto + * message-events.cpp (OnRead, OnReadComplete, OnWrite) + (OnWriteComplete): Ditto + * mapihelp.cpp (mapi_get_int_prop): New. + * olflange.cpp (Install): Improve version check. * revert.cpp, revert.h: New. Modified: trunk/NEWS =================================================================== --- trunk/NEWS 2008-07-30 17:53:36 UTC (rev 262) +++ trunk/NEWS 2008-08-01 13:53:15 UTC (rev 263) @@ -5,7 +5,10 @@ is useful to make sure that the body will never show up in plaintext in the message store. + * New menu item to remove all GpgOL created flags and attachments + from all messages in a folder. + Noteworthy changes for version 0.10.14 (2008-05-28) =================================================== Modified: trunk/src/common.h =================================================================== --- trunk/src/common.h 2008-07-30 17:53:36 UTC (rev 262) +++ trunk/src/common.h 2008-08-01 13:53:15 UTC (rev 263) @@ -134,6 +134,11 @@ /* The SVN revision as stored in the registry. */ int svn_revision; + + /* Disable message processing until restart. This is required to + implement message reverting as a perparation to remove GpgOL. */ + int disable_gpgol; + } opt; Modified: trunk/src/ext-commands.cpp =================================================================== --- trunk/src/ext-commands.cpp 2008-07-30 17:53:36 UTC (rev 262) +++ trunk/src/ext-commands.cpp 2008-08-01 13:53:15 UTC (rev 263) @@ -106,6 +106,7 @@ m_nCmdEncrypt = 0; m_nCmdSign = 0; m_nCmdKeyManager = 0; + m_nCmdRevertFolder = 0; m_nCmdCryptoState = 0; m_nCmdDebug0 = 0; m_nCmdDebug1 = 0; @@ -528,26 +529,29 @@ an already decrypted message. */ add_menu (eecb, pnCommandIDBase, "@", NULL, - _("GpgOL Decrypt/Verify"), &m_nCmdCryptoState, + opt.disable_gpgol? "":_("GpgOL Decrypt/Verify"), &m_nCmdCryptoState, opt.enable_debug? "GpgOL Debug-0 (display crypto info)":"", &m_nCmdDebug0, - opt.enable_debug? "GpgOL Debug-1 (open_inspector)":"", &m_nCmdDebug1, - opt.enable_debug? "GpgOL Debug-2 (change msg class)":"", &m_nCmdDebug2, + (opt.enable_debug && !opt.disable_gpgol)? + "GpgOL Debug-1 (open_inspector)":"", &m_nCmdDebug1, + (opt.enable_debug && !opt.disable_gpgol)? + "GpgOL Debug-2 (change msg class)":"", &m_nCmdDebug2, opt.enable_debug? "GpgOL Debug-3 (revert message class)":"", &m_nCmdDebug3, NULL); - add_toolbar (pTBEArray, nTBECnt, - is_encrypted - ? _("This is an encrypted message.\n" - "Click for more information. ") - : _("This is a signed message.\n" + if ( !opt.disable_gpgol) + add_toolbar (pTBEArray, nTBECnt, + is_encrypted + ? _("This is an encrypted message.\n" + "Click for more information. ") + : _("This is a signed message.\n" "Click for more information. "), - IDB_CRYPTO_STATE, m_nCmdCryptoState, - NULL, 0, 0); + IDB_CRYPTO_STATE, m_nCmdCryptoState, + NULL, 0, 0); } - else if (m_lContext == EECONTEXT_SENDNOTEMESSAGE) + else if (m_lContext == EECONTEXT_SENDNOTEMESSAGE && !opt.disable_gpgol) { add_menu (eecb, pnCommandIDBase, "@", NULL, @@ -584,6 +588,7 @@ add_menu (eecb, pnCommandIDBase, "@", NULL, _("GnuPG Certificate &Manager"), &m_nCmdKeyManager, + _("Remove GpgOL flags from this folder"), &m_nCmdRevertFolder, NULL); add_toolbar (pTBEArray, nTBECnt, @@ -755,6 +760,39 @@ MessageBox (NULL, _("Could not start certificate manager"), _("GpgOL"), MB_ICONERROR|MB_OK); } + else if (nCommandID == m_nCmdRevertFolder + && m_lContext == EECONTEXT_VIEWER) + { + log_debug ("%s:%s: command ReverFoldert called\n", SRCNAME, __func__); + /* Notify the user that the general GpgOl fucntionaly will be + disabled when calling this function the first time. */ + if ( opt.disable_gpgol + || (MessageBox + (hwnd, + _("You are about to start the process of reversing messages " + "created by GpgOL to prepare deinstalling of GpgOL. " + "Running this command will put GpgOL into a disabled state " + "so that messages are not anymore processed by GpgOL.\n" + "\n" + "You should convert all folders one after the other with " + "this command, close Outlook and then deinstall GpgOL.\n" + "\n" + "Note that if you start Outlook again with GpgOL still " + "being installed, GpgOL will again process messages."), + _("GpgOL"), MB_ICONWARNING|MB_OKCANCEL) == IDOK)) + { + if ( MessageBox + (hwnd, + _("Do you want to revert this folder?"), + _("GpgOL"), MB_ICONQUESTION|MB_YESNO) == IDYES ) + { + if (!opt.disable_gpgol) + opt.disable_gpgol = 1; + + gpgol_folder_revert (eecb); + } + } + } else if (opt.enable_debug && nCommandID == m_nCmdDebug0 && m_lContext == EECONTEXT_READNOTEMESSAGE) { Modified: trunk/src/ext-commands.h =================================================================== --- trunk/src/ext-commands.h 2008-07-30 17:53:36 UTC (rev 262) +++ trunk/src/ext-commands.h 2008-08-01 13:53:15 UTC (rev 263) @@ -46,6 +46,7 @@ UINT m_nCmdEncrypt; UINT m_nCmdSign; UINT m_nCmdKeyManager; + UINT m_nCmdRevertFolder; UINT m_nCmdCryptoState; UINT m_nCmdDebug0; UINT m_nCmdDebug1; Modified: trunk/src/mapihelp.cpp =================================================================== --- trunk/src/mapihelp.cpp 2008-07-30 17:53:36 UTC (rev 262) +++ trunk/src/mapihelp.cpp 2008-08-01 13:53:15 UTC (rev 263) @@ -1367,7 +1367,41 @@ return data; } +/* Return an integer property at R_VALUE. On error the function + returns -1 and sets R_VALUE to 0, on success 0 is returned. */ +int +mapi_get_int_prop (LPMAPIPROP object, ULONG proptype, LONG *r_value) +{ + int rc = -1; + HRESULT hr; + LPSPropValue propval = NULL; + *r_value = 0; + hr = HrGetOneProp (object, proptype, &propval); + if (FAILED (hr)) + { + log_error ("%s:%s: error getting property %#lx: hr=%#lx", + SRCNAME, __func__, proptype, hr); + return -1; + } + switch ( PROP_TYPE (propval->ulPropTag) ) + { + case PT_LONG: + *r_value = propval->Value.l; + rc = 0; + + break; + + default: + log_debug ("%s:%s: requested property %#lx has unknown tag %#lx\n", + SRCNAME, __func__, proptype, propval->ulPropTag); + break; + } + MAPIFreeBuffer (propval); + return rc; +} + + /* Return the attachment method for attachment OBJ. In case of error we return 0 which happens not to be defined. */ static int Modified: trunk/src/mapihelp.h =================================================================== --- trunk/src/mapihelp.h 2008-07-30 17:53:36 UTC (rev 262) +++ trunk/src/mapihelp.h 2008-08-01 13:53:15 UTC (rev 263) @@ -118,6 +118,7 @@ int mapi_to_mime (LPMESSAGE message, const char *filename); char *mapi_get_binary_prop (LPMESSAGE message,ULONG proptype,size_t *r_nbytes); +int mapi_get_int_prop (LPMAPIPROP object, ULONG proptype, LONG *r_value); char *mapi_get_from_address (LPMESSAGE message); char *mapi_get_subject (LPMESSAGE message); Modified: trunk/src/message-events.cpp =================================================================== --- trunk/src/message-events.cpp 2008-07-30 17:53:36 UTC (rev 262) +++ trunk/src/message-events.cpp 2008-08-01 13:53:15 UTC (rev 263) @@ -98,7 +98,76 @@ } +#if 0 +#warning test code +static void +show_event_object (LPEXCHEXTCALLBACK eecb) +{ + HRESULT hr; + LPOUTLOOKEXTCALLBACK outlook_cb; + LPUNKNOWN obj; + LPDISPATCH disp; + LPTYPEINFO tinfo; + BSTR bstrname; + char *name; + outlook_cb = NULL; + eecb->QueryInterface(IID_IOutlookExtCallback, (void **)&outlook_cb); + if (!outlook_cb) + { + log_debug ("%s%s: no outlook callback found\n", SRCNAME, __func__); + return; + } + + obj = NULL; + outlook_cb->GetObject (&obj); + if (!obj) + { + log_debug ("%s%s: no object found for event\n", SRCNAME, __func__); + outlook_cb->Release (); + return; + } + + disp = NULL; + obj->QueryInterface (IID_IDispatch, (void **)&disp); + obj->Release (); + obj = NULL; + if (!disp) + { + log_debug ("%s%s: no dispatcher found for event\n", SRCNAME, __func__); + outlook_cb->Release (); + return; + } + + tinfo = NULL; + disp->GetTypeInfo (0, 0, &tinfo); + if (!tinfo) + { + log_debug ("%s%s: no dispatcher found for event\n", SRCNAME, __func__); + disp->Release (); + outlook_cb->Release (); + return; + } + + name = NULL; + hr = tinfo->GetDocumentation (MEMBERID_NIL, &bstrname, 0, 0, 0); + if (hr) + log_debug ("%s%s: GetDocumentation failed: hr=%#lx\n", + SRCNAME, __func__, hr); + + name = wchar_to_utf8 (bstrname); + SysFreeString (bstrname); + log_debug ("%s:%s: event fired by item type `%s'\n", + SRCNAME, __func__, name); + xfree (name); + + disp->Release (); + outlook_cb->Release (); +} +#endif /* Test code */ + + + /* Called from Exchange on reading a message. Returns: S_FALSE to signal Exchange to continue calling extensions. EECB is a pointer to the IExchExtCallback interface. */ @@ -118,6 +187,8 @@ log_debug ("%s:%s: received (hwnd=%p) %s\n", SRCNAME, __func__, hwnd, m_gotinspector? "got_inspector":""); +// show_event_object (eecb); + /* Fixme: If preview decryption is not enabled and we have an encrypted message, we might want to show a greyed out preview window. There are two ways to clear the preview window: @@ -132,7 +203,7 @@ result that the preview decryption can't be disabled. */ m_gotinspector = 1; - if (m_gotinspector || opt.preview_decrypt) + if ( (m_gotinspector || opt.preview_decrypt) && !opt.disable_gpgol ) { eecb->GetObject (&mdb, (LPMAPIPROP *)&message); switch (message_incoming_handler (message, hwnd, false)) @@ -167,7 +238,7 @@ /* If the message has been processed by us (i.e. in OnRead), we now use our own display code. */ - if (!flags && m_processed) + if (!flags && m_processed && !opt.disable_gpgol) { HWND hwnd = NULL; @@ -197,11 +268,11 @@ DISPPARAMS dispparamsNoArgs = {NULL, NULL, 0, 0}; HWND hWnd = NULL; - /* If we are going to encrypt, check that the BodyFormat is something we support. This helps avoiding surprise by sending out unencrypted messages. */ - if (m_pExchExt->m_gpgEncrypt || m_pExchExt->m_gpgSign) + if ( (m_pExchExt->m_gpgEncrypt || m_pExchExt->m_gpgSign) + && !opt.disable_gpgol) { pDisp = find_outlook_property (eecb, "BodyFormat", &dispid); if (!pDisp) @@ -289,6 +360,9 @@ if (flags & (EEME_FAILED|EEME_COMPLETE_FAILED)) return S_FALSE; /* We don't need to rollback anything in case other extensions flagged a failure. */ + + if (opt.disable_gpgol) + return S_FALSE; if (!m_bOnSubmitActive) /* The user is just saving the message. */ return S_FALSE; Modified: trunk/src/message.cpp =================================================================== --- trunk/src/message.cpp 2008-07-30 17:53:36 UTC (rev 262) +++ trunk/src/message.cpp 2008-08-01 13:53:15 UTC (rev 263) @@ -80,7 +80,8 @@ been set. Note that we should have similar code for some message classes in GpgolUserEvents:OnSelectionChange; but tehre are a couple of problems. */ - if (pass == 1 && !force && !mapi_has_sig_status (message)) + if (pass == 1 && !force && !mapi_has_sig_status (message) + && !opt.disable_gpgol) { log_debug ("%s:%s: message class not yet checked - doing now\n", SRCNAME, __func__); @@ -89,7 +90,7 @@ } break; case MSGTYPE_SMIME: - if (pass == 1 && !force && opt.enable_smime) + if (pass == 1 && !force && opt.enable_smime && !opt.disable_gpgol) { log_debug ("%s:%s: message class not checked with smime enabled " "- doing now\n", SRCNAME, __func__); Modified: trunk/src/session-events.cpp =================================================================== --- trunk/src/session-events.cpp 2008-07-30 17:53:36 UTC (rev 262) +++ trunk/src/session-events.cpp 2008-08-01 13:53:15 UTC (rev 263) @@ -103,16 +103,19 @@ LPMESSAGE pMessage = NULL; log_debug ("%s:%s: received\n", SRCNAME, __func__); - pEECB->GetObject (&pMDB, (LPMAPIPROP *)&pMessage); - log_mapi_property (pMessage, PR_MESSAGE_CLASS,"PR_MESSAGE_CLASS"); - /* Note, that at this point even an OpenPGP signed message has the - message class IPM.Note.SMIME.MultipartSigned. If we would not - change the message class here, OL will change it later (before an - OnRead) to IPM.Note. */ - mapi_change_message_class (pMessage, 0); - log_mapi_property (pMessage, PR_MESSAGE_CLASS,"PR_MESSAGE_CLASS"); - ul_release (pMessage); - ul_release (pMDB); + if ( !opt.disable_gpgol ) + { + pEECB->GetObject (&pMDB, (LPMAPIPROP *)&pMessage); + log_mapi_property (pMessage, PR_MESSAGE_CLASS,"PR_MESSAGE_CLASS"); + /* Note, that at this point even an OpenPGP signed message has + the message class IPM.Note.SMIME.MultipartSigned. If we + would not change the message class here, OL will change it + later (before an OnRead) to IPM.Note. */ + mapi_change_message_class (pMessage, 0); + log_mapi_property (pMessage, PR_MESSAGE_CLASS,"PR_MESSAGE_CLASS"); + ul_release (pMessage); + ul_release (pMDB); + } return S_FALSE; } Modified: trunk/src/user-events.cpp =================================================================== --- trunk/src/user-events.cpp 2008-07-30 17:53:36 UTC (rev 262) +++ trunk/src/user-events.cpp 2008-08-01 13:53:15 UTC (rev 263) @@ -160,7 +160,7 @@ &objtype, (IUnknown**)&message); if (SUCCEEDED (hr)) { - if (objtype == MAPI_MESSAGE) + if (objtype == MAPI_MESSAGE && !opt.disable_gpgol) { log_debug ("%s:%s: about to change or sync " "the message class", From cvs at cvs.gnupg.org Mon Aug 4 13:11:43 2008 From: cvs at cvs.gnupg.org (svn author wk) Date: Mon, 04 Aug 2008 13:11:43 +0200 Subject: [svn] GpgOL - r264 - in trunk: . forms src Message-ID: Author: wk Date: 2008-08-04 13:11:42 +0200 (Mon, 04 Aug 2008) New Revision: 264 Added: trunk/forms/ trunk/forms/Makefile.am trunk/forms/encr-l.ico trunk/forms/encr-s.ico trunk/forms/gpgol-ms_de.cfg trunk/forms/gpgol_de.cfg trunk/forms/sign-l.ico trunk/forms/sign-s.ico Modified: trunk/ChangeLog trunk/Makefile.am trunk/NEWS trunk/configure.ac trunk/src/ChangeLog trunk/src/common.c trunk/src/common.h trunk/src/ext-commands.cpp trunk/src/main.c trunk/src/mymapi.h trunk/src/olflange.cpp Log: New code to install forms so that appropriate icons are shown in the Viewer. Note that we do not have these icons yet . [The diff below has been truncated] Modified: trunk/ChangeLog =================================================================== --- trunk/ChangeLog 2008-08-01 13:53:15 UTC (rev 263) +++ trunk/ChangeLog 2008-08-04 11:11:42 UTC (rev 264) @@ -1,3 +1,9 @@ +2008-08-04 Werner Koch + + * Makefile.am (SUBDIRS): Add forms. + * forms/Makefile.am: New. + * forms/gpgol_de.cfg, forms/gpgol-ms_de.cfg: New. + 2008-06-04 Werner Koch * doc/gpgol.texi (Assuan Protocol): Remove protocol specs. They Modified: trunk/src/ChangeLog =================================================================== --- trunk/src/ChangeLog 2008-08-01 13:53:15 UTC (rev 263) +++ trunk/src/ChangeLog 2008-08-04 11:11:42 UTC (rev 264) @@ -1,3 +1,11 @@ +2008-08-04 Werner Koch + + * olflange.cpp (install_forms): New. + (GpgolExt): Install forms if needed. + * common.c (get_data_dir): New. + * common.h (struct): Add field FORMS_REVISION. + * main.c (read_options, write_options): Read and write that option. + 2008-07-31 Werner Koch * ext-commands.h (class GpgolExtCommands): Add m_nCmdRevertFolder. Modified: trunk/Makefile.am =================================================================== --- trunk/Makefile.am 2008-08-01 13:53:15 UTC (rev 263) +++ trunk/Makefile.am 2008-08-04 11:11:42 UTC (rev 264) @@ -23,7 +23,7 @@ EXTRA_DIST = autogen.sh -SUBDIRS = src po m4 doc +SUBDIRS = src forms po m4 doc dist-hook: echo "$(VERSION)" > $(distdir)/VERSION Modified: trunk/NEWS =================================================================== --- trunk/NEWS 2008-08-01 13:53:15 UTC (rev 263) +++ trunk/NEWS 2008-08-04 11:11:42 UTC (rev 264) @@ -8,7 +8,10 @@ * New menu item to remove all GpgOL created flags and attachments from all messages in a folder. + * Icons are now installed for messages processed by GpgOL. For now + only for the German version of Outlook. + Noteworthy changes for version 0.10.14 (2008-05-28) =================================================== Modified: trunk/configure.ac =================================================================== --- trunk/configure.ac 2008-08-01 13:53:15 UTC (rev 263) +++ trunk/configure.ac 2008-08-04 11:11:42 UTC (rev 264) @@ -251,6 +251,7 @@ AC_CONFIG_FILES([ Makefile src/Makefile src/versioninfo.rc +forms/Makefile doc/Makefile po/Makefile.in m4/Makefile Added: trunk/forms/Makefile.am =================================================================== --- trunk/forms/Makefile.am 2008-08-01 13:53:15 UTC (rev 263) +++ trunk/forms/Makefile.am 2008-08-04 11:11:42 UTC (rev 264) @@ -0,0 +1,22 @@ +# forms - Automake template +# Copyright (C) 2008 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 +# modifications, as long as this notice is preserved. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY, to the extent permitted by law; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + +## Process this file with automake to produce Makefile.in + +icons = encr-l.ico encr-s.ico sign-l.ico sign-s.ico + +cfg_german = gpgol_de.cfg gpgol-ms_de.cfg + + +dist_pkgdata_DATA = $(icons) $(cfg_german) + + + Added: trunk/forms/encr-l.ico =================================================================== (Binary files differ) Property changes on: trunk/forms/encr-l.ico ___________________________________________________________________ Name: svn:executable + * Name: svn:mime-type + application/octet-stream Added: trunk/forms/encr-s.ico =================================================================== (Binary files differ) Property changes on: trunk/forms/encr-s.ico ___________________________________________________________________ Name: svn:executable + * Name: svn:mime-type + application/octet-stream Added: trunk/forms/gpgol-ms_de.cfg =================================================================== --- trunk/forms/gpgol-ms_de.cfg 2008-08-01 13:53:15 UTC (rev 263) +++ trunk/forms/gpgol-ms_de.cfg 2008-08-04 11:11:42 UTC (rev 264) @@ -0,0 +1,35 @@ +[Description] +MessageClass=IPM.Note.GpgOL.MultipartSigned +DesignerRuntimeGuid={0006F020-0000-0000-C000-000000000046} +CLSID={00061033-0000-0000-C000-000000000046} +DisplayName=Form for class IPM.Note.GpgOL.MultipartSigned +Category=Standard +Subcategory=Formular +Comment= +LargeIcon=sign-l.ico +SmallIcon=sign-s.ico +VersionMajor=1 +VersionMinor=0 +Locale=deu +Hidden=1 +Owner=Public Domain + +[Properties] + +[Verbs] +Verb1=1 + +[Verb.1] +DisplayName=?&ffnen +Code=0 +Flags=0 +Attribs=2 + +[Extensions] +Extensions1=1 + +[Extension.1] +Type=30 +NmidPropset={00020D0C-0000-0000-C000-000000000046} +NmidInteger=1 +Value=1011111111111111 Added: trunk/forms/gpgol_de.cfg =================================================================== --- trunk/forms/gpgol_de.cfg 2008-08-01 13:53:15 UTC (rev 263) +++ trunk/forms/gpgol_de.cfg 2008-08-04 11:11:42 UTC (rev 264) @@ -0,0 +1,36 @@ +[Description] +MessageClass=IPM.Note.GpgOL +DesignerRuntimeGuid={0006F020-0000-0000-C000-000000000046} +CLSID={00061033-0000-0000-C000-000000000046} +DisplayName=Form for class IPM.Note.GpgOL +Category=Standard +Subcategory=Formular +Comment= +LargeIcon=encr-l.ico +SmallIcon=encr-s.ico +VersionMajor=1 +VersionMinor=0 +Locale=deu +Hidden=1 +Owner=Public Domain + +[Properties] + +[Verbs] +Verb1=1 + +[Verb.1] +DisplayName=?&ffnen +Code=0 +Flags=0 +Attribs=2 + +[Extensions] +Extensions1=1 + +[Extension.1] +Type=30 +NmidPropset={00020D0C-0000-0000-C000-000000000046} +NmidInteger=1 +Value=1011111111111111 + Added: trunk/forms/sign-l.ico =================================================================== (Binary files differ) Property changes on: trunk/forms/sign-l.ico ___________________________________________________________________ Name: svn:executable + * Name: svn:mime-type + application/octet-stream Added: trunk/forms/sign-s.ico =================================================================== (Binary files differ) Property changes on: trunk/forms/sign-s.ico ___________________________________________________________________ Name: svn:executable + * Name: svn:mime-type + application/octet-stream Modified: trunk/src/common.c =================================================================== --- trunk/src/common.c 2008-08-01 13:53:15 UTC (rev 263) +++ trunk/src/common.c 2008-08-04 11:11:42 UTC (rev 264) @@ -628,7 +628,40 @@ return dir; } +/* Return the data dir used for forms etc. Returns NULL on error. */ +char * +get_data_dir (void) +{ + char *instdir; + char *p; + char *dname; + instdir = read_w32_registry_string ("HKEY_LOCAL_MACHINE", GNUPG_REGKEY, + "Install Directory"); + if (!instdir) + return NULL; + + /* Build the key: "/share/gpgol". */ +#define SDDIR "\\share\\gpgol" + dname = malloc (strlen (instdir) + strlen (SDDIR) + 1); + if (!dname) + { + free (instdir); + return NULL; + } + p = dname; + strcpy (p, instdir); + p += strlen (instdir); + strcpy (p, SDDIR); + + free (instdir); + +#undef SDDIR + return dname; +} + + + /* Do in-place decoding of quoted-printable data of LENGTH in BUFFER. Returns the new length of the buffer and stores true at R_SLBRK if the line ended with a soft line break; false is stored if not. Modified: trunk/src/common.h =================================================================== --- trunk/src/common.h 2008-08-01 13:53:15 UTC (rev 263) +++ trunk/src/common.h 2008-08-04 11:11:42 UTC (rev 264) @@ -135,6 +135,9 @@ /* The SVN revision as stored in the registry. */ int svn_revision; + /* The SVN revision of the the binary used to install the forms. */ + int forms_revision; + /* Disable message processing until restart. This is required to implement message reverting as a perparation to remove GpgOL. */ int disable_gpgol; @@ -195,6 +198,7 @@ char *utf8_to_wincp (const char *string); const char *default_homedir (void); +char *get_data_dir (void); size_t qp_decode (char *buffer, size_t length, int *r_slbrk); void b64_init (b64_state_t *state); Modified: trunk/src/ext-commands.cpp =================================================================== --- trunk/src/ext-commands.cpp 2008-08-01 13:53:15 UTC (rev 263) +++ trunk/src/ext-commands.cpp 2008-08-04 11:11:42 UTC (rev 264) @@ -92,8 +92,6 @@ - - /* Constructor */ GpgolExtCommands::GpgolExtCommands (GpgolExt* pParentInterface) { Modified: trunk/src/main.c =================================================================== --- trunk/src/main.c 2008-08-01 13:53:15 UTC (rev 263) +++ trunk/src/main.c 2008-08-04 11:11:42 UTC (rev 264) @@ -633,6 +633,10 @@ opt.svn_revision = val? atol (val) : 0; xfree (val); val = NULL; + load_extension_value ("formsRevision", &val); + opt.forms_revision = val? atol (val) : 0; + xfree (val); val = NULL; + load_extension_value ("bodyAsAttachment", &val); opt.body_as_attachment = val == NULL || *val != '1'? 0 : 1; xfree (val); val = NULL; @@ -710,6 +714,7 @@ {"enableDefaultKey", 0, opt.enable_default_key}, {"preferHtml", 0, opt.prefer_html}, {"svnRevision", 1, opt.svn_revision}, + {"formsRevision", 1, opt.forms_revision}, {"bodyAsAttachment", 0, opt.body_as_attachment}, {NULL, 0} }; Modified: trunk/src/mymapi.h =================================================================== --- trunk/src/mymapi.h 2008-08-01 13:53:15 UTC (rev 263) +++ trunk/src/mymapi.h 2008-08-04 11:11:42 UTC (rev 264) @@ -32,6 +32,7 @@ 2007-07-23 Add IMAPISession; taken from WINE. 2007-07-24 Add IMsgStore, IMAPIContainer and IMAPIFolder taken from specs. Reorganized code. + 2008-08-01 Add IMAPIFormContainer taken from specs. */ #ifndef MAPI_H @@ -114,8 +115,8 @@ #define MAPI_MESSAGE 0x00000005u #define MAPI_MAILUSER 0x00000006u #define MAPI_ATTACH 0x00000007u -#define MAPI_DISTLIST 0x00000008u -#define MAPI_PROFSECT 0x00000009u +#define MAPI_DISTLIST 0x00000008u +#define MAPI_PROFSECT 0x00000009u #define MAPI_STATUS 0x0000000Au #define MAPI_SESSION 0x0000000Bu #define MAPI_FORMINFO 0x0000000Cu @@ -174,7 +175,7 @@ #define FORCE_SUBMIT 0x00000001ul - + #define MSGFLAG_READ 0x00000001ul #define MSGFLAG_UNMODIFIED 0x00000002ul #define MSGFLAG_SUBMIT 0x00000004ul @@ -185,7 +186,7 @@ #define MSGFLAG_RESEND 0x00000080ul #define MSGFLAG_RN_PENDING 0x00000100ul #define MSGFLAG_NRN_PENDING 0x00000200ul - + #define SUBMITFLAG_LOCKED 0x00000001ul #define SUBMITFLAG_PREPROCESS 0x00000002ul @@ -672,7 +673,10 @@ struct ISpoolerHook; typedef struct ISpoolerHook *LPSPOOLERHOOK; +struct IMAPIFormContainer; +typedef struct IMAPIFormContainer *LPMAPIFORMCONTAINER; + /*** IUnknown methods ***/ #define MY_IUNKNOWN_METHODS \ STDMETHOD(QueryInterface)(THIS_ REFIID, PVOID*) PURE; \ @@ -1013,6 +1017,84 @@ }; + +/* IMAPIFormContainer */ + +#define MAPIFORM_INSTALL_OVERWRITEONCONFLICT 0x10 + +typedef struct _SMAPIFormPropEnumVal +{ + LPTSTR pszDisplayName; + ULONG nVal; +} SMAPIFormPropEnumVal, *LPMAPIFORMPROPENUMVAL; + + +typedef struct _SMAPIFormProp +{ + ULONG ulFlags; + ULONG nPropType; + MAPINAMEID nmid; + LPTSTR pszDisplayName; + ULONG nSpecialType; + union { + struct { + MAPINAMEID nmidIdx; + ULONG cfpevAvailable; + LPMAPIFORMPROPENUMVAL pfpevAvailable; + } s1; + } u; +} SMAPIFormProp, *LPMAPIFORMPROP; + +typedef struct _SMAPIFormPropArray +{ + ULONG cProps; + ULONG ulPad; + SMAPIFormProp aFormProp[MAPI_DIM]; +} SMAPIFormPropArray, *LPMAPIFORMPROPARRAY; + +typedef struct _SMessageClassArray +{ + ULONG cValues; + LPCSTR aMessageClass[MAPI_DIM]; +} SMessageClassArray, *LPSMESSAGECLASSARRAY; + + +/* Fixme: The void ptr in ResolveMessageClass and SMAPIFormInfoArray + should be a LPMAPIFORMINFO, but we have not yet defined the + corresponding class. */ +typedef struct _SMAPIFormInfoArray +{ + ULONG cForms; + void * aFormInfo[MAPI_DIM]; +} SMAPIFormInfoArray, *LPSMAPIFORMINFOARRAY; + +#define MY_IMAPIFORMCONTAINER_METHODS \ + STDMETHOD(GetLastError)(THIS_ HRESULT, ULONG, LPMAPIERROR FAR*) PURE; \ + STDMETHOD(InstallForm)(THIS_ ULONG ulUIParam, ULONG ulFlags, \ + LPCTSTR szCfgPathName) PURE; \ + STDMETHOD(RemoveForm)(THIS_ LPCSTR szMessageClass) PURE; \ + STDMETHOD(ResolveMessageClass) (THIS_ LPCSTR szMessageClass, ULONG ulFlags, \ + void * FAR *pforminfo) PURE; \ + STDMETHOD(ResolveMultipleMessageClasses) \ + (THIS_ LPSMESSAGECLASSARRAY pMsgClassArray, ULONG ulFlags, \ + LPSMAPIFORMINFOARRAY FAR *ppfrminfoarray) PURE; \ + STDMETHOD(CalcFormPropSet)(THIS_ ULONG ulFlags, \ + LPMAPIFORMPROPARRAY FAR *ppResults) PURE; \ + STDMETHOD(GetDisplay)(THIS_ ULONG ulFlags, \ + LPTSTR FAR *pszDisplayName) PURE; + + +EXTERN_C const IID IID_IMAPIFormContainer; +#undef INTERFACE +#define INTERFACE IMAPIFormContainer +DECLARE_INTERFACE_(IMAPIFormContainer, IUnknown) +{ + MY_IUNKNOWN_METHODS; + MY_IMAPIFORMCONTAINER_METHODS; +}; + + + #undef MY_IUNKNOWN_METHODS #undef MY_IMAPIPROP_METHODS #undef MY_IMSGSTORE_METHODS @@ -1022,6 +1104,7 @@ #undef MY_IMAPITABLE_METHODS #undef MY_IMAPISESSION_METHODS #undef MY_ISPOOLERHOOK_METHODS +#undef MY_IMAPIFORMCONTAINER_METHODS @@ -1087,6 +1170,10 @@ ULONG,LPSTR,LPSTR,LPSTREAM*); #endif + +STDAPI MAPIOpenLocalFormContainer (LPMAPIFORMCONTAINER FAR *ppfcnt); + + #ifdef __cplusplus } #endif Modified: trunk/src/olflange.cpp =================================================================== --- trunk/src/olflange.cpp 2008-08-01 13:53:15 UTC (rev 263) +++ trunk/src/olflange.cpp 2008-08-04 11:11:42 UTC (rev 264) @@ -1,6 +1,6 @@ /* olflange.cpp - Connect GpgOL to Outlook * Copyright (C) 2001 G Data Software AG, http://www.gdata.de - * Copyright (C) 2004, 2005, 2007 g10 Code GmbH + * Copyright (C) 2004, 2005, 2007, 2008 g10 Code GmbH * * This file is part of GpgOL. * @@ -67,6 +67,7 @@ static bool g_initdll = FALSE; +static void install_forms (void); @@ -429,6 +430,8 @@ " dialog can be found in the main menu at:" " Extras->Options->GpgOL.\n"), "GpgOL", MB_ICONINFORMATION|MB_OK); + if ( SVN_REVISION > opt.forms_revision ) + install_forms (); } } @@ -635,3 +638,77 @@ } +static void From cvs at cvs.gnupg.org Mon Aug 4 15:16:47 2008 From: cvs at cvs.gnupg.org (svn author wk) Date: Mon, 04 Aug 2008 15:16:47 +0200 Subject: [svn] gcry - r1294 - in trunk: . random Message-ID: Author: wk Date: 2008-08-04 15:16:45 +0200 (Mon, 04 Aug 2008) New Revision: 1294 Modified: trunk/AUTHORS trunk/random/rndunix.c Log: Clarify license entry. Small indentation change. Modified: trunk/AUTHORS =================================================================== --- trunk/AUTHORS 2008-07-05 16:44:03 UTC (rev 1293) +++ trunk/AUTHORS 2008-08-04 13:16:45 UTC (rev 1294) @@ -2,7 +2,8 @@ Maintainer: Werner Koch Bug reports: or http://bugs.gnupg.org Security related bug reports: -License: LGPLv2.1+ +License (library): LGPLv2.1+ +License (manual and tools): GPLv2+ Libgcrypt used to be part of GnuPG but has been taken out into its own package on 2000-12-21. Modified: trunk/random/rndunix.c =================================================================== --- trunk/random/rndunix.c 2008-07-05 16:44:03 UTC (rev 1293) +++ trunk/random/rndunix.c 2008-08-04 13:16:45 UTC (rev 1294) @@ -820,8 +820,8 @@ return 0; if( !gatherer_pid ) { - /* make sure we are not setuid */ - if( getuid() != geteuid() ) + /* Make sure we are not setuid. */ + if ( getuid() != geteuid() ) BUG(); /* time to start the gatherer process */ if( pipe( pipedes ) ) { From cvs at cvs.gnupg.org Tue Aug 5 16:08:39 2008 From: cvs at cvs.gnupg.org (svn author wk) Date: Tue, 05 Aug 2008 16:08:39 +0200 Subject: [svn] GpgOL - r265 - in trunk: forms src Message-ID: Author: wk Date: 2008-08-05 16:08:38 +0200 (Tue, 05 Aug 2008) New Revision: 265 Modified: trunk/forms/encr-l.ico trunk/forms/encr-s.ico trunk/forms/sign-l.ico trunk/forms/sign-s.ico trunk/src/ChangeLog trunk/src/engine.c trunk/src/engine.h trunk/src/ext-commands.cpp trunk/src/message.cpp trunk/src/mimeparser.c trunk/src/mimeparser.h trunk/src/olflange.cpp trunk/src/olflange.h Log: yeah, we have icons for the Viewer pane. Removed icons for protocol selection for OL2003. Fixed signature verification of encrypted messages. Modified: trunk/src/ChangeLog =================================================================== --- trunk/src/ChangeLog 2008-08-04 11:11:42 UTC (rev 264) +++ trunk/src/ChangeLog 2008-08-05 14:08:38 UTC (rev 265) @@ -1,3 +1,15 @@ +2008-08-05 Werner Koch + + * ext-commands.cpp (InstallCommands): Display protocolicons only + for OL2007. + * olflange.cpp (get_ol_main_version): New. + + * message.cpp (message_decrypt): Save a signature verification + result. + * mimeparser.c (mime_decrypt): Implement verification of included + signatrues. This feature got lost during the removal of nested + crypto operations. + 2008-08-04 Werner Koch * olflange.cpp (install_forms): New. Modified: trunk/forms/encr-l.ico =================================================================== (Binary files differ) Modified: trunk/forms/encr-s.ico =================================================================== (Binary files differ) Modified: trunk/forms/sign-l.ico =================================================================== (Binary files differ) Modified: trunk/forms/sign-s.ico =================================================================== (Binary files differ) Modified: trunk/src/engine.c =================================================================== --- trunk/src/engine.c 2008-08-04 11:11:42 UTC (rev 264) +++ trunk/src/engine.c 2008-08-05 14:08:38 UTC (rev 265) @@ -638,7 +638,7 @@ /* Set the FILTER in a mode which pushes an extra linefeed out. */ void -engine_request_exra_lf (engine_filter_t filter) +engine_request_extra_lf (engine_filter_t filter) { filter->add_extra_lf = 1; } Modified: trunk/src/engine.h =================================================================== --- trunk/src/engine.h 2008-08-04 11:11:42 UTC (rev 264) +++ trunk/src/engine.h 2008-08-05 14:08:38 UTC (rev 265) @@ -63,7 +63,7 @@ int engine_create_filter (engine_filter_t *r_filter, int (*outfnc) (void *, const void *, size_t), void *outfncdata); -void engine_request_exra_lf (engine_filter_t filter); +void engine_request_extra_lf (engine_filter_t filter); void engine_set_session_number (engine_filter_t filter, unsigned int value); void engine_set_session_title (engine_filter_t filter, const char *title); void engine_set_sender_address (engine_filter_t filter, const char *addr); Modified: trunk/src/ext-commands.cpp =================================================================== --- trunk/src/ext-commands.cpp 2008-08-04 11:11:42 UTC (rev 264) +++ trunk/src/ext-commands.cpp 2008-08-05 14:08:38 UTC (rev 265) @@ -515,6 +515,8 @@ case MSGTYPE_GPGOL_OPAQUE_ENCRYPTED: case MSGTYPE_GPGOL_PGP_MESSAGE: is_encrypted = 1; + if ( mapi_test_sig_status (message) ) + is_encrypted++; break; default: break; @@ -538,9 +540,12 @@ &m_nCmdDebug3, NULL); - if ( !opt.disable_gpgol) + if (!opt.disable_gpgol) add_toolbar (pTBEArray, nTBECnt, - is_encrypted + is_encrypted == 2 + ? _("This is a signed and encrypted message.\n" + "Click for more information. ") + : is_encrypted ? _("This is an encrypted message.\n" "Click for more information. ") : _("This is a signed message.\n" @@ -561,14 +566,23 @@ _("&encrypt message with GnuPG"), &m_nCmdEncrypt, _("&sign message with GnuPG"), &m_nCmdSign, NULL ); + + /* We display the protocol icons only for Outlook 2007 becuase + there seems to be no way to add a plain menu item. */ + if (get_ol_main_version () > 11) + add_toolbar (pTBEArray, nTBECnt, + "Encrypt", IDB_ENCRYPT, m_nCmdEncrypt, + "Sign", IDB_SIGN, m_nCmdSign, + "Autoselect", IDB_PROTO_AUTO, m_nCmdProtoAuto, + "Use PGP/MIME", IDB_PROTO_PGPMIME, m_nCmdProtoPgpmime, + "Use/MIME", IDB_PROTO_SMIME, m_nCmdProtoSmime, + NULL, 0, 0); + else + add_toolbar (pTBEArray, nTBECnt, + "Encrypt", IDB_ENCRYPT, m_nCmdEncrypt, + "Sign", IDB_SIGN, m_nCmdSign, + NULL, 0, 0); - add_toolbar (pTBEArray, nTBECnt, - "Encrypt", IDB_ENCRYPT, m_nCmdEncrypt, - "Sign", IDB_SIGN, m_nCmdSign, - "Autoselect", IDB_PROTO_AUTO, m_nCmdProtoAuto, - "Use PGP/MIME", IDB_PROTO_PGPMIME, m_nCmdProtoPgpmime, - "Use/MIME", IDB_PROTO_SMIME, m_nCmdProtoSmime, - NULL, 0, 0); m_pExchExt->m_protoSelection = opt.default_protocol; update_protocol_menu (eecb); Modified: trunk/src/message.cpp =================================================================== --- trunk/src/message.cpp 2008-08-04 11:11:42 UTC (rev 264) +++ trunk/src/message.cpp 2008-08-05 14:08:38 UTC (rev 265) @@ -807,7 +807,7 @@ int tblidx; int retval = -1; LPSTREAM cipherstream; - gpg_error_t err; + gpg_error_t err, sig_err; int is_opaque = 0; protocol_t protocol; LPATTACH saved_attach = NULL; @@ -1037,8 +1037,9 @@ goto leave; /* Problem getting the attachment. */ } + sig_err = gpg_error (GPG_ERR_NO_DATA); err = mime_decrypt (protocol, cipherstream, message, - need_rfc822_parser, is_simple_pgp, hwnd, 0); + need_rfc822_parser, is_simple_pgp, hwnd, 0, &sig_err); log_debug ("mime_decrypt returned %d (%s)", err, gpg_strerror (err)); if (err && opt.enable_debug) { @@ -1060,6 +1061,25 @@ { if (saved_attach) mapi_set_attach_hidden (saved_attach); + + if (gpg_err_code (sig_err) != GPG_ERR_NO_DATA) + { + /* Note: Saving the result of the signature in a property + will reveal that there is a signature inside the + encrypted message - however it does reveal only a + common assumption and thus it is acceptable to do + this. */ + if (sig_err) + { + char buf[200]; + snprintf (buf, sizeof buf, "- %s", gpg_strerror (sig_err)); + mapi_set_sig_status (message, gpg_strerror (sig_err)); + } + else + mapi_set_sig_status (message, "! Good signature"); + mapi_save_changes (message, KEEP_OPEN_READWRITE); + } + } cipherstream->Release (); retval = 0; Modified: trunk/src/mimeparser.c =================================================================== --- trunk/src/mimeparser.c 2008-08-04 11:11:42 UTC (rev 264) +++ trunk/src/mimeparser.c 2008-08-05 14:08:38 UTC (rev 265) @@ -1223,6 +1223,7 @@ assert (messagelen >= len); messagelen -= len; } + /* Note: the last character should be a LF, if not we ignore such an incomplete last line. */ if (ctx->sig_data && gpgme_data_write (ctx->sig_data, "", 1) == 1) @@ -1651,20 +1652,25 @@ window to be used for message box and such. In PREVIEW_MODE no verification will be done, no messages saved and no messages boxes will pop up. If IS_RFC822 is set, the message is expected to be in - rfc822 format. The caller should send SIMPLE_PGP is the input - message is a simple PGP message. */ + rfc822 format. The caller should send SIMPLE_PGP if the input + message is a simple (non-MIME) PGP message. If SIG_ERR is not null + and a signature was found and verified, its status is returned + there. If no signature was found SIG_ERR is not changed. */ int mime_decrypt (protocol_t protocol, LPSTREAM instream, LPMESSAGE mapi_message, - int is_rfc822, int simple_pgp, HWND hwnd, int preview_mode) + int is_rfc822, int simple_pgp, HWND hwnd, int preview_mode, + gpg_error_t *sig_err) { gpg_error_t err; mime_context_t decctx, ctx; engine_filter_t filter = NULL; int opaque_signed = 0; int last_part_counter = 0; + unsigned int session_number; + char *signature = NULL; - log_debug ("%s:%s: enter (protocol=%d, is_rfc822=%d)", - SRCNAME, __func__, protocol, is_rfc822); + log_debug ("%s:%s: enter (protocol=%d, is_rfc822=%d, simple_pgp=%d)", + SRCNAME, __func__, protocol, is_rfc822, simple_pgp); if (is_rfc822) { @@ -1680,6 +1686,7 @@ ctx->protect_mode = 1; ctx->hwnd = hwnd; ctx->preview = preview_mode; + ctx->verify_mode = simple_pgp? 0 : 1; ctx->mapi_message = mapi_message; ctx->mimestruct_tail = &ctx->mimestruct; ctx->no_mail_header = simple_pgp; @@ -1706,13 +1713,12 @@ } /* Prepare the decryption. */ -/* title = native_to_utf8 (_("[Encrypted S/MIME message]")); */ -/* title = native_to_utf8 (_("[Encrypted PGP/MIME message]")); */ if ((err=engine_create_filter (&filter, plaintext_handler, ctx))) goto leave; if (simple_pgp) - engine_request_exra_lf (filter); - engine_set_session_number (filter, engine_new_session_number ()); + engine_request_extra_lf (filter); + session_number = engine_new_session_number (); + engine_set_session_number (filter, session_number); { char *tmp = mapi_get_subject (mapi_message); engine_set_session_title (filter, tmp); @@ -1790,8 +1796,81 @@ else if (ctx->line_too_long) err = gpg_error (GPG_ERR_GENERAL); + /* Verify an optional inner signature. */ + if (!err && !preview_mode + && ctx->sig_data && ctx->signed_data && !ctx->is_opaque_signed) + { + size_t sig_len; + + assert (!filter); + + if (gpgme_data_write (ctx->sig_data, "", 1) == 1) + { + signature = gpgme_data_release_and_get_mem (ctx->sig_data, &sig_len); + ctx->sig_data = NULL; + } + + if (!err && signature) + { + gpgme_data_seek (ctx->signed_data, 0, SEEK_SET); + + if ((err=engine_create_filter (&filter, NULL, NULL))) + goto leave; + engine_set_session_number (filter, session_number); + { + char *tmp = mapi_get_subject (mapi_message); + engine_set_session_title (filter, tmp); + xfree (tmp); + } + { + char *from = mapi_get_from_address (mapi_message); + err = engine_verify_start (filter, hwnd, signature, sig_len, + ctx->protocol, from); + xfree (from); + } + if (err) + goto leave; + + /* Filter the data. */ + do + { + int nread; + char buffer[4096]; + + nread = gpgme_data_read (ctx->signed_data, buffer,sizeof buffer); + if (nread < 0) + { + err = gpg_error_from_syserror (); + log_error ("%s:%s: gpgme_data_read failed in verify: %s", + SRCNAME, __func__, gpg_strerror (err)); + } + else if (nread) + { + err = engine_filter (filter, buffer, nread); + } + else + break; /* EOF */ + } + while (!err); + if (err) + goto leave; + + /* Wait for the engine to finish. */ + if ((err = engine_filter (filter, NULL, 0))) + goto leave; + err = engine_wait (filter); + if (sig_err) + *sig_err = err; + err = 0; + filter = NULL; + } + } + + leave: engine_cancel (filter); + xfree (signature); + signature = NULL; if (ctx) { /* Cancel any left over attachment which means that the MIME @@ -1871,11 +1950,16 @@ log_debug ("%s:%s: mime_verify_opaque returned %d", SRCNAME, __func__, err); + if (sig_err) + *sig_err = err; + err = 0; + leave_verify: xfree (plainbuffer); mapi_release_attach_table (table); } + return err; } Modified: trunk/src/mimeparser.h =================================================================== --- trunk/src/mimeparser.h 2008-08-04 11:11:42 UTC (rev 264) +++ trunk/src/mimeparser.h 2008-08-05 14:08:38 UTC (rev 265) @@ -37,7 +37,8 @@ int start_part_counter); int mime_decrypt (protocol_t protocol, LPSTREAM instream, LPMESSAGE mapi_message, int is_rfc822, - int simple_pgp, HWND hwnd, int preview_mode); + int simple_pgp, HWND hwnd, int preview_mode, + gpg_error_t *sig_err); #ifdef __cplusplus Modified: trunk/src/olflange.cpp =================================================================== --- trunk/src/olflange.cpp 2008-08-04 11:11:42 UTC (rev 264) +++ trunk/src/olflange.cpp 2008-08-05 14:08:38 UTC (rev 265) @@ -69,7 +69,9 @@ static void install_forms (void); +static char *olversion; + /* Return a string for the context NO. This never return NULL. */ const char * @@ -96,6 +98,13 @@ } +EXTERN_C int +get_ol_main_version (void) +{ + return olversion? atoi (olversion): 0; +} + + /* Wrapper around UlRelease with error checking. */ // static void // ul_release (LPVOID punk, const char *func) @@ -533,7 +542,6 @@ GpgolExt::Install(LPEXCHEXTCALLBACK pEECB, ULONG lContext, ULONG lFlags) { static int version_shown; - static char *olversion; ULONG lBuildVersion; ULONG lActualVersion; ULONG lVirtualVersion; @@ -662,7 +670,7 @@ case LANG_GERMAN: langsuffix = "de"; break; default: log_debug ("%s:%s: No forms available for primary language %d\n", - SRCNAME, __func__, buffer); + SRCNAME, __func__, (int)langid); /* Don't try again. */ opt.forms_revision = SVN_REVISION; write_options (); Modified: trunk/src/olflange.h =================================================================== --- trunk/src/olflange.h 2008-08-04 11:11:42 UTC (rev 264) +++ trunk/src/olflange.h 2008-08-05 14:08:38 UTC (rev 265) @@ -74,5 +74,7 @@ EXTERN_C const char * __stdcall gpgol_check_version (const char *req_version); +EXTERN_C int get_ol_main_version (void); + #endif /*OLFLANGE_H*/ From cvs at cvs.gnupg.org Wed Aug 6 08:40:41 2008 From: cvs at cvs.gnupg.org (svn author wk) Date: Wed, 06 Aug 2008 08:40:41 +0200 Subject: [svn] GpgOL - r266 - in trunk: . po src Message-ID: Author: wk Date: 2008-08-06 08:40:39 +0200 (Wed, 06 Aug 2008) New Revision: 266 Modified: trunk/AUTHORS trunk/ChangeLog trunk/NEWS trunk/configure.ac trunk/po/de.po trunk/po/sv.po trunk/src/ChangeLog trunk/src/olflange-dlgs.cpp Log: preparing a release. Modified: trunk/ChangeLog =================================================================== --- trunk/ChangeLog 2008-08-05 14:08:38 UTC (rev 265) +++ trunk/ChangeLog 2008-08-06 06:40:39 UTC (rev 266) @@ -1,3 +1,10 @@ +2008-08-06 Werner Koch + + Release 0.10.15. + + * forms/sign-l.ico, forms/sign-s.ico: New. + * forms/encr-l.ico, forms/encr-s.ico: New + 2008-08-04 Werner Koch * Makefile.am (SUBDIRS): Add forms. Modified: trunk/src/ChangeLog =================================================================== --- trunk/src/ChangeLog 2008-08-05 14:08:38 UTC (rev 265) +++ trunk/src/ChangeLog 2008-08-06 06:40:39 UTC (rev 266) @@ -1,3 +1,7 @@ +2008-08-06 Werner Koch + + * olflange-dlgs.cpp (GPGOptionsDlgProc): Disable S/MIME notice. + 2008-08-05 Werner Koch * ext-commands.cpp (InstallCommands): Display protocolicons only Modified: trunk/AUTHORS =================================================================== --- trunk/AUTHORS 2008-08-05 14:08:38 UTC (rev 265) +++ trunk/AUTHORS 2008-08-06 06:40:39 UTC (rev 266) @@ -17,5 +17,3 @@ Some files may still contain code from the orginal plugin: Copyright (C) 2001 G Data Software AG, http://www.gdata.de - - Modified: trunk/NEWS =================================================================== --- trunk/NEWS 2008-08-05 14:08:38 UTC (rev 265) +++ trunk/NEWS 2008-08-06 06:40:39 UTC (rev 266) @@ -1,8 +1,8 @@ -Noteworthy changes for version 0.10.15 +Noteworthy changes for version 0.10.15 (2008-08-06) =================================================== * New option to present the body of a message as an attachment. This - is useful to make sure that the body will never show up in + is useful to make sure that the body will never show up as plaintext in the message store. * New menu item to remove all GpgOL created flags and attachments Modified: trunk/configure.ac =================================================================== --- trunk/configure.ac 2008-08-05 14:08:38 UTC (rev 265) +++ trunk/configure.ac 2008-08-06 06:40:39 UTC (rev 266) @@ -17,7 +17,7 @@ # Set my_issvn to "yes" for non-released code. Remember to run an # "svn up" and "autogen.sh" right before creating a distribution. m4_define([my_version], [0.10.15]) -m4_define([my_issvn], [yes]) +m4_define([my_issvn], [no]) m4_define([svn_revision], m4_esyscmd([echo -n $( (svn info 2>/dev/null \ || echo 'Revision: 0')|sed -n '/^Revision:/ {s/[^0-9]//gp;q;}')])) Modified: trunk/po/de.po [not shown] Modified: trunk/po/sv.po [not shown] Modified: trunk/src/olflange-dlgs.cpp =================================================================== --- trunk/src/olflange-dlgs.cpp 2008-08-05 14:08:38 UTC (rev 265) +++ trunk/src/olflange-dlgs.cpp 2008-08-06 06:40:39 UTC (rev 266) @@ -209,6 +209,7 @@ opt.sign_default = !!SendDlgItemMessage (hDlg, IDC_SIGN_DEFAULT, BM_GETCHECK, 0, 0L); +#if 0 /* The mentioned tool is now available. */ if (opt.enable_smime) { MessageBox (hDlg, @@ -220,6 +221,7 @@ "provided when GpgOL arrives at production quality status."), "GpgOL", MB_ICONINFORMATION|MB_OK); } +#endif /*0*/ if (openpgp_state) opt.default_protocol = PROTOCOL_OPENPGP; From cvs at cvs.gnupg.org Wed Aug 6 08:49:10 2008 From: cvs at cvs.gnupg.org (svn author wk) Date: Wed, 06 Aug 2008 08:49:10 +0200 Subject: [svn] GpgOL - r267 - tags Message-ID: Author: wk Date: 2008-08-06 08:49:09 +0200 (Wed, 06 Aug 2008) New Revision: 267 Added: tags/gpgol-0.10.15/ Log: Release tag From cvs at cvs.gnupg.org Wed Aug 6 13:46:39 2008 From: cvs at cvs.gnupg.org (svn author marcus) Date: Wed, 06 Aug 2008 13:46:39 +0200 Subject: [svn] dirmngr - r307 - trunk/src Message-ID: Author: marcus Date: 2008-08-06 13:46:39 +0200 (Wed, 06 Aug 2008) New Revision: 307 Modified: trunk/src/ChangeLog trunk/src/dirmngr.c Log: 2008-08-06 Marcus Brinkmann * dirmngr.c (main): Mark the ldapserverlist-file option as read-only. Modified: trunk/src/ChangeLog =================================================================== --- trunk/src/ChangeLog 2008-07-31 17:05:26 UTC (rev 306) +++ trunk/src/ChangeLog 2008-08-06 11:46:39 UTC (rev 307) @@ -1,3 +1,8 @@ +2008-08-06 Marcus Brinkmann + + * dirmngr.c (main): Mark the ldapserverlist-file option as + read-only. + 2008-06-16 Werner Koch * get-path.c (w32_commondir): New. Modified: trunk/src/dirmngr.c =================================================================== --- trunk/src/dirmngr.c 2008-07-31 17:05:26 UTC (rev 306) +++ trunk/src/dirmngr.c 2008-08-06 11:46:39 UTC (rev 307) @@ -1208,7 +1208,7 @@ "ldapservers.conf":"dirmngr_ldapservers.conf", NULL); filename_esc = percent_escape (filename, NULL); - printf ("ldapserverlist-file:%lu:\"%s\n", GC_OPT_FLAG_DEFAULT, + printf ("ldapserverlist-file:%lu:\"%s\n", flags | GC_OPT_FLAG_DEFAULT, filename_esc); xfree (filename_esc); xfree (filename); From cvs at cvs.gnupg.org Wed Aug 6 13:48:24 2008 From: cvs at cvs.gnupg.org (svn author marcus) Date: Wed, 06 Aug 2008 13:48:24 +0200 Subject: [svn] GnuPG - r4806 - trunk/tools Message-ID: Author: marcus Date: 2008-08-06 13:48:23 +0200 (Wed, 06 Aug 2008) New Revision: 4806 Modified: trunk/tools/ChangeLog trunk/tools/gpgconf-comp.c Log: Marcus Brinkmann * gpgconf-comp.c (retrieve_options_from_file): Transfer the NO_CHANGE flag from the file name option to the list option. Modified: trunk/tools/ChangeLog =================================================================== --- trunk/tools/ChangeLog 2008-08-01 10:51:11 UTC (rev 4805) +++ trunk/tools/ChangeLog 2008-08-06 11:48:23 UTC (rev 4806) @@ -1,3 +1,8 @@ +2008-08-06 Marcus Brinkmann + + * gpgconf-comp.c (retrieve_options_from_file): Transfer the + NO_CHANGE flag from the file name option to the list option. + 2008-06-19 Werner Koch * gpgconf-comp.c (GC_ARG_TYPE_ALIAS_LIST): New. Modified: trunk/tools/gpgconf-comp.c =================================================================== --- trunk/tools/gpgconf-comp.c 2008-08-01 10:51:11 UTC (rev 4805) +++ trunk/tools/gpgconf-comp.c 2008-08-06 11:48:23 UTC (rev 4806) @@ -165,7 +165,7 @@ /* The option name for the configuration filename of this backend. This must be an absolute filename. It can be an option from a different backend (but then ordering of the options might - matter). */ + matter). Note: This must be unique among all components. */ const char *option_config_filename; /* If this is a file backend rather than a program backend, then @@ -1949,6 +1949,7 @@ retrieve_options_from_file (gc_component_t component, gc_backend_t backend) { gc_option_t *list_option; + gc_option_t *config_option; char *list_filename; FILE *list_file; char *line = NULL; @@ -2008,6 +2009,12 @@ list_option->active = 1; list_option->value = list; + /* Fix up the read-only flag. */ + config_option = find_option + (component, gc_backend[backend].option_config_filename, GC_BACKEND_ANY); + if (config_option->flags & GC_OPT_FLAG_NO_CHANGE) + list_option->flags |= GC_OPT_FLAG_NO_CHANGE; + if (list_file && fclose (list_file) && ferror (list_file)) gc_error (1, errno, "error closing %s", list_filename); xfree (line); From cvs at cvs.gnupg.org Wed Aug 6 16:38:42 2008 From: cvs at cvs.gnupg.org (svn author marcus) Date: Wed, 06 Aug 2008 16:38:42 +0200 Subject: [svn] GnuPG - r4807 - trunk/tools Message-ID: Author: marcus Date: 2008-08-06 16:38:41 +0200 (Wed, 06 Aug 2008) New Revision: 4807 Modified: trunk/tools/ChangeLog trunk/tools/gpgconf-comp.c Log: 2008-08-06 Marcus Brinkmann * gpgconf-comp.c (gc_options_gpgsm): Change type of keyserver option to GC_ARG_TYPE_LDAP_SERVER. Modified: trunk/tools/ChangeLog =================================================================== --- trunk/tools/ChangeLog 2008-08-06 11:48:23 UTC (rev 4806) +++ trunk/tools/ChangeLog 2008-08-06 14:38:41 UTC (rev 4807) @@ -1,5 +1,8 @@ 2008-08-06 Marcus Brinkmann + * gpgconf-comp.c (gc_options_gpgsm): Change type of keyserver + option to GC_ARG_TYPE_LDAP_SERVER. + * gpgconf-comp.c (retrieve_options_from_file): Transfer the NO_CHANGE flag from the file name option to the list option. Modified: trunk/tools/gpgconf-comp.c =================================================================== --- trunk/tools/gpgconf-comp.c 2008-08-06 11:48:23 UTC (rev 4806) +++ trunk/tools/gpgconf-comp.c 2008-08-06 14:38:41 UTC (rev 4807) @@ -742,7 +742,7 @@ GC_ARG_TYPE_STRING, GC_BACKEND_GPGSM }, { "keyserver", GC_OPT_FLAG_LIST, GC_LEVEL_BASIC, "gnupg", N_("|SPEC|use this keyserver to lookup keys"), - GC_ARG_TYPE_STRING, GC_BACKEND_GPGSM }, + GC_ARG_TYPE_LDAP_SERVER, GC_BACKEND_GPGSM }, { "Debug", GC_OPT_FLAG_GROUP, GC_LEVEL_ADVANCED, From cvs at cvs.gnupg.org Wed Aug 6 18:08:53 2008 From: cvs at cvs.gnupg.org (svn author wk) Date: Wed, 06 Aug 2008 18:08:53 +0200 Subject: [svn] gpg-error - r205 - in trunk: . po src Message-ID: Author: wk Date: 2008-08-06 18:08:52 +0200 (Wed, 06 Aug 2008) New Revision: 205 Modified: trunk/ChangeLog trunk/Makefile.am trunk/NEWS trunk/configure.ac trunk/po/de.po trunk/po/fr.po trunk/po/libgpg-error.pot trunk/po/pl.po trunk/po/ro.po trunk/po/sv.po trunk/po/vi.po trunk/src/err-codes.h.in Log: Add a new error code. Modified: trunk/ChangeLog =================================================================== --- trunk/ChangeLog 2007-12-11 13:34:07 UTC (rev 204) +++ trunk/ChangeLog 2008-08-06 16:08:52 UTC (rev 205) @@ -1,3 +1,11 @@ +2008-08-06 Werner Koch + + * src/err-codes.h.in (GPG_ERR_NOT_OPERATIONAL): New. + +2008-04-01 Werner Koch + + * configure.ac (AC_INIT): Fix m4 quoting. + 2007-12-11 Werner Koch * Makefile.am (EXTRA_DIST): Add COPYING. Modified: trunk/Makefile.am =================================================================== --- trunk/Makefile.am 2007-12-11 13:34:07 UTC (rev 204) +++ trunk/Makefile.am 2008-08-06 16:08:52 UTC (rev 205) @@ -20,7 +20,7 @@ ACLOCAL_AMFLAGS = -I m4 AUTOMAKE_OPTIONS = dist-bzip2 -EXTRA_DIST = autogen.sh config.rpath libgpg-error.spec.in COPYING +EXTRA_DIST = autogen.sh config.rpath libgpg-error.spec.in COPYING COPYING.LIB if LANGUAGES_SOME lang_subdirs = lang Modified: trunk/NEWS =================================================================== --- trunk/NEWS 2007-12-11 13:34:07 UTC (rev 204) +++ trunk/NEWS 2008-08-06 16:08:52 UTC (rev 205) @@ -2,6 +2,11 @@ ---------------------------------------------- + * Interface changes relative to the 1.6 release: + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + GPG_ERR_NOT_OPERATIONAL NEW + + Noteworthy changes in version 1.6 (2007-10-29) ---------------------------------------------- Modified: trunk/configure.ac =================================================================== --- trunk/configure.ac 2007-12-11 13:34:07 UTC (rev 204) +++ trunk/configure.ac 2008-08-06 16:08:52 UTC (rev 205) @@ -30,7 +30,8 @@ m4_define([svn_revision], m4_esyscmd([echo -n $( (svn info 2>/dev/null \ || echo 'Revision: 0')|sed -n '/^Revision:/ {s/[^0-9]//gp;q;}')])) -AC_INIT([libgpg-error], my_version[]m4_if(my_issvn,[yes],[-svn[]svn_revision]), +AC_INIT([libgpg-error], + [my_version[]m4_if(my_issvn,[yes],[-svn[]svn_revision])], [bug-gnupg at gnupg.org]) # LT Version numbers, remember to change them just *before* a release. # (Code changed: REVISION++) Modified: trunk/po/de.po [not shown] Modified: trunk/po/fr.po [not shown] Modified: trunk/po/libgpg-error.pot =================================================================== --- trunk/po/libgpg-error.pot 2007-12-11 13:34:07 UTC (rev 204) +++ trunk/po/libgpg-error.pot 2008-08-06 16:08:52 UTC (rev 205) @@ -8,7 +8,7 @@ msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: translations at gnupg.org\n" -"POT-Creation-Date: 2007-10-29 12:46+0100\n" +"POT-Creation-Date: 2008-08-06 17:30+0200\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -801,238 +801,242 @@ msgstr "" #: src/err-codes.h:204 +msgid "Not operational" +msgstr "" + +#: src/err-codes.h:205 msgid "Operation not yet finished" msgstr "" -#: src/err-codes.h:205 +#: src/err-codes.h:206 msgid "Buffer too short" msgstr "" -#: src/err-codes.h:206 +#: src/err-codes.h:207 msgid "Invalid length specifier in S-expression" msgstr "" -#: src/err-codes.h:207 +#: src/err-codes.h:208 msgid "String too long in S-expression" msgstr "" -#: src/err-codes.h:208 +#: src/err-codes.h:209 msgid "Unmatched parentheses in S-expression" msgstr "" -#: src/err-codes.h:209 +#: src/err-codes.h:210 msgid "S-expression not canonical" msgstr "" -#: src/err-codes.h:210 +#: src/err-codes.h:211 msgid "Bad character in S-expression" msgstr "" -#: src/err-codes.h:211 +#: src/err-codes.h:212 msgid "Bad quotation in S-expression" msgstr "" -#: src/err-codes.h:212 +#: src/err-codes.h:213 msgid "Zero prefix in S-expression" msgstr "" -#: src/err-codes.h:213 +#: src/err-codes.h:214 msgid "Nested display hints in S-expression" msgstr "" -#: src/err-codes.h:214 +#: src/err-codes.h:215 msgid "Unmatched display hints" msgstr "" -#: src/err-codes.h:215 +#: src/err-codes.h:216 msgid "Unexpected reserved punctuation in S-expression" msgstr "" -#: src/err-codes.h:216 +#: src/err-codes.h:217 msgid "Bad hexadecimal character in S-expression" msgstr "" -#: src/err-codes.h:217 +#: src/err-codes.h:218 msgid "Odd hexadecimal numbers in S-expression" msgstr "" -#: src/err-codes.h:218 +#: src/err-codes.h:219 msgid "Bad octadecimal character in S-expression" msgstr "" -#: src/err-codes.h:219 +#: src/err-codes.h:220 msgid "General IPC error" msgstr "" -#: src/err-codes.h:220 +#: src/err-codes.h:221 msgid "IPC accept call failed" msgstr "" -#: src/err-codes.h:221 +#: src/err-codes.h:222 msgid "IPC connect call failed" msgstr "" -#: src/err-codes.h:222 +#: src/err-codes.h:223 msgid "Invalid IPC response" msgstr "" -#: src/err-codes.h:223 +#: src/err-codes.h:224 msgid "Invalid value passed to IPC" msgstr "" -#: src/err-codes.h:224 +#: src/err-codes.h:225 msgid "Incomplete line passed to IPC" msgstr "" -#: src/err-codes.h:225 +#: src/err-codes.h:226 msgid "Line passed to IPC too long" msgstr "" -#: src/err-codes.h:226 +#: src/err-codes.h:227 msgid "Nested IPC commands" msgstr "" -#: src/err-codes.h:227 +#: src/err-codes.h:228 msgid "No data callback in IPC" msgstr "" -#: src/err-codes.h:228 +#: src/err-codes.h:229 msgid "No inquire callback in IPC" msgstr "" -#: src/err-codes.h:229 +#: src/err-codes.h:230 msgid "Not an IPC server" msgstr "" -#: src/err-codes.h:230 +#: src/err-codes.h:231 msgid "Not an IPC client" msgstr "" -#: src/err-codes.h:231 +#: src/err-codes.h:232 msgid "Problem starting IPC server" msgstr "" -#: src/err-codes.h:232 +#: src/err-codes.h:233 msgid "IPC read error" msgstr "" -#: src/err-codes.h:233 +#: src/err-codes.h:234 msgid "IPC write error" msgstr "" -#: src/err-codes.h:234 +#: src/err-codes.h:235 msgid "Too much data for IPC layer" msgstr "" -#: src/err-codes.h:235 +#: src/err-codes.h:236 msgid "Unexpected IPC command" msgstr "" -#: src/err-codes.h:236 +#: src/err-codes.h:237 msgid "Unknown IPC command" msgstr "" -#: src/err-codes.h:237 +#: src/err-codes.h:238 msgid "IPC syntax error" msgstr "" -#: src/err-codes.h:238 +#: src/err-codes.h:239 msgid "IPC call has been cancelled" msgstr "" -#: src/err-codes.h:239 +#: src/err-codes.h:240 msgid "No input source for IPC" msgstr "" -#: src/err-codes.h:240 +#: src/err-codes.h:241 msgid "No output source for IPC" msgstr "" -#: src/err-codes.h:241 +#: src/err-codes.h:242 msgid "IPC parameter error" msgstr "" -#: src/err-codes.h:242 +#: src/err-codes.h:243 msgid "Unknown IPC inquire" msgstr "" -#: src/err-codes.h:243 +#: src/err-codes.h:244 msgid "User defined error code 1" msgstr "" -#: src/err-codes.h:244 +#: src/err-codes.h:245 msgid "User defined error code 2" msgstr "" -#: src/err-codes.h:245 +#: src/err-codes.h:246 msgid "User defined error code 3" msgstr "" -#: src/err-codes.h:246 +#: src/err-codes.h:247 msgid "User defined error code 4" msgstr "" -#: src/err-codes.h:247 +#: src/err-codes.h:248 msgid "User defined error code 5" msgstr "" -#: src/err-codes.h:248 +#: src/err-codes.h:249 msgid "User defined error code 6" msgstr "" -#: src/err-codes.h:249 +#: src/err-codes.h:250 msgid "User defined error code 7" msgstr "" -#: src/err-codes.h:250 +#: src/err-codes.h:251 msgid "User defined error code 8" msgstr "" -#: src/err-codes.h:251 +#: src/err-codes.h:252 msgid "User defined error code 9" msgstr "" -#: src/err-codes.h:252 +#: src/err-codes.h:253 msgid "User defined error code 10" msgstr "" -#: src/err-codes.h:253 +#: src/err-codes.h:254 msgid "User defined error code 11" msgstr "" -#: src/err-codes.h:254 +#: src/err-codes.h:255 msgid "User defined error code 12" msgstr "" -#: src/err-codes.h:255 +#: src/err-codes.h:256 msgid "User defined error code 13" msgstr "" -#: src/err-codes.h:256 +#: src/err-codes.h:257 msgid "User defined error code 14" msgstr "" -#: src/err-codes.h:257 +#: src/err-codes.h:258 msgid "User defined error code 15" msgstr "" -#: src/err-codes.h:258 +#: src/err-codes.h:259 msgid "User defined error code 16" msgstr "" -#: src/err-codes.h:259 +#: src/err-codes.h:260 msgid "System error w/o errno" msgstr "" -#: src/err-codes.h:260 +#: src/err-codes.h:261 msgid "Unknown system error" msgstr "" -#: src/err-codes.h:261 +#: src/err-codes.h:262 msgid "End of file" msgstr "" -#: src/err-codes.h:262 +#: src/err-codes.h:263 msgid "Unknown error code" msgstr "" Modified: trunk/po/pl.po [not shown] Modified: trunk/po/ro.po [not shown] Modified: trunk/po/sv.po [not shown] Modified: trunk/po/vi.po [not shown] Modified: trunk/src/err-codes.h.in =================================================================== --- trunk/src/err-codes.h.in 2007-12-11 13:34:07 UTC (rev 204) +++ trunk/src/err-codes.h.in 2008-08-06 16:08:52 UTC (rev 205) @@ -205,7 +205,7 @@ 173 GPG_ERR_LOCKED Locked 174 GPG_ERR_UNKNOWN_OPTION Unknown option 175 GPG_ERR_UNKNOWN_COMMAND Unknown command - +176 GPG_ERR_NOT_OPERATIONAL Not operational # 176 to 198 are free to be used. 199 GPG_ERR_UNFINISHED Operation not yet finished From cvs at cvs.gnupg.org Thu Aug 7 09:46:53 2008 From: cvs at cvs.gnupg.org (svn author wk) Date: Thu, 07 Aug 2008 09:46:53 +0200 Subject: [svn] GnuPG - r4808 - trunk/doc Message-ID: Author: wk Date: 2008-08-07 09:46:52 +0200 (Thu, 07 Aug 2008) New Revision: 4808 Modified: trunk/doc/faq.raw trunk/doc/gpg.texi Log: Add a warning note to --allow-multiple-messages. s/Sylpeed-Claws/Claws-Mail/. Modified: trunk/doc/faq.raw =================================================================== --- trunk/doc/faq.raw 2008-08-06 14:38:41 UTC (rev 4807) +++ trunk/doc/faq.raw 2008-08-07 07:46:52 UTC (rev 4808) @@ -509,7 +509,7 @@ Mulberry Y Y P Mutt Y Y N Sylpheed Y Y N - Sylpheed-claws Y Y N + Claws-mail Y Y N TkRat Y Y N XEmacs/Gnus Y Y T (Mailcrypt) XEmacs/Mew Y Y N Modified: trunk/doc/gpg.texi =================================================================== --- trunk/doc/gpg.texi 2008-08-06 14:38:41 UTC (rev 4807) +++ trunk/doc/gpg.texi 2008-08-07 07:46:52 UTC (rev 4808) @@ -2458,12 +2458,16 @@ @item --allow-multiple-messages @item --no-allow-multiple-messages -Allow processing of multiple OpenPGP messages contained in a single -file or stream. Some programs that call GPG are not prepared to deal -with multiple messages being processed together, so this option -defaults to no. Note that versions of GPG prior to 1.4.7 always -allowed multiple messages. +Allow processing of multiple OpenPGP messages contained in a single file +or stream. Some programs that call GPG are not prepared to deal with +multiple messages being processed together, so this option defaults to +no. Note that versions of GPG prior to 1.4.7 always allowed multiple +messages. +Warning: Do not use this option unless you need it as a temporary +workaround! + + @item --enable-special-filenames This options enables a mode in which filenames of the form @file{-&n}, where n is a non-negative decimal number, From cvs at cvs.gnupg.org Fri Aug 8 03:06:49 2008 From: cvs at cvs.gnupg.org (svn author marcus) Date: Fri, 08 Aug 2008 03:06:49 +0200 Subject: [svn] GnuPG - r4809 - trunk/sm Message-ID: Author: marcus Date: 2008-08-08 03:06:48 +0200 (Fri, 08 Aug 2008) New Revision: 4809 Modified: trunk/sm/ChangeLog trunk/sm/call-dirmngr.c trunk/sm/gpgsm.h Log: 2008-08-08 Marcus Brinkmann * gpgsm.h (struct server_control_s): Remove member dirmngr_seen. * call-dirmngr.c (dirmngr2_ctx, dirmngr_ctx_locked) (dirmngr2_ctx_locked): New global variables. (prepare_dirmngr): Don't check dirmngr_seen anymore. (start_dirmngr): Move bunch of code to ... (start_dirmngr_ext): ... this new function. (release_dirmngr, start_dirmngr2, release_dirmngr2): New functions. (gpgsm_dirmngr_isvalid): Call release_dirmngr. (gpgsm_dirmngr_lookup): Call release_dirmngr. If dirmngr_ctx is locked, use dirmngr2_locked. (gpgsm_dirmngr_run_command): Call release_dirmngr. Modified: trunk/sm/ChangeLog =================================================================== --- trunk/sm/ChangeLog 2008-08-07 07:46:52 UTC (rev 4808) +++ trunk/sm/ChangeLog 2008-08-08 01:06:48 UTC (rev 4809) @@ -1,3 +1,18 @@ +2008-08-08 Marcus Brinkmann + + * gpgsm.h (struct server_control_s): Remove member dirmngr_seen. + * call-dirmngr.c (dirmngr2_ctx, dirmngr_ctx_locked) + (dirmngr2_ctx_locked): New global variables. + (prepare_dirmngr): Don't check dirmngr_seen anymore. + (start_dirmngr): Move bunch of code to ... + (start_dirmngr_ext): ... this new function. + (release_dirmngr, start_dirmngr2, release_dirmngr2): New + functions. + (gpgsm_dirmngr_isvalid): Call release_dirmngr. + (gpgsm_dirmngr_lookup): Call release_dirmngr. If dirmngr_ctx is + locked, use dirmngr2_locked. + (gpgsm_dirmngr_run_command): Call release_dirmngr. + 2008-06-25 Werner Koch * sign.c (gpgsm_sign): Revamp the hash algorithm selection. Modified: trunk/sm/call-dirmngr.c =================================================================== --- trunk/sm/call-dirmngr.c 2008-08-07 07:46:52 UTC (rev 4808) +++ trunk/sm/call-dirmngr.c 2008-08-08 01:06:48 UTC (rev 4809) @@ -44,7 +44,14 @@ +/* fixme: We need a context for each thread or serialize the access to + the dirmngr. */ static assuan_context_t dirmngr_ctx = NULL; +static assuan_context_t dirmngr2_ctx = NULL; + +static int dirmngr_ctx_locked; +static int dirmngr2_ctx_locked; + static int force_pipe_server = 0; struct inq_certificate_parm_s { @@ -142,18 +149,14 @@ { struct keyserver_spec *server; - if (!ctrl->dirmngr_seen) + if (!err) { - ctrl->dirmngr_seen = 1; - if (!err) - { - err = assuan_transact (ctx, "OPTION audit-events=1", - NULL, NULL, NULL, NULL, NULL, NULL); - if (gpg_err_code (err) == GPG_ERR_UNKNOWN_OPTION) - err = 0; /* Allow the use of old dirmngr versions. */ - } - audit_log_ok (ctrl->audit, AUDIT_DIRMNGR_READY, err); + err = assuan_transact (ctx, "OPTION audit-events=1", + NULL, NULL, NULL, NULL, NULL, NULL); + if (gpg_err_code (err) == GPG_ERR_UNKNOWN_OPTION) + err = 0; /* Allow the use of old dirmngr versions. */ } + audit_log_ok (ctrl->audit, AUDIT_DIRMNGR_READY, err); server = opt.keyserver; while (server) @@ -162,7 +165,7 @@ char *user = server->user ? server->user : ""; char *pass = server->pass ? server->pass : ""; char *base = server->base ? server->base : ""; - + snprintf (line, DIM (line) - 1, "LDAPSERVER %s:%i:%s:%s:%s", server->host, server->port, user, pass, base); line[DIM (line) - 1] = 0; @@ -180,7 +183,7 @@ /* Try to connect to the agent via socket or fork it off and work by pipes. Handle the server's initial greeting */ static int -start_dirmngr (ctrl_t ctrl) +start_dirmngr_ext (ctrl_t ctrl, assuan_context_t *ctx_r) { int rc; char *infostr, *p; @@ -190,12 +193,9 @@ if (opt.disable_dirmngr) return gpg_error (GPG_ERR_NO_DIRMNGR); - if (dirmngr_ctx) - { - prepare_dirmngr (ctrl, dirmngr_ctx, 0); - return 0; /* fixme: We need a context for each thread or serialize - the access to the dirmngr */ - } + if (*ctx_r) + return 0; + /* Note: if you change this to multiple connections, you also need to take care of the implicit option sending caching. */ @@ -266,7 +266,7 @@ log_error (_("malformed DIRMNGR_INFO environment variable\n")); xfree (infostr); force_pipe_server = 1; - return start_dirmngr (ctrl); + return start_dirmngr_ext (ctrl, ctx_r); } *p++ = 0; pid = atoi (p); @@ -279,7 +279,7 @@ prot); xfree (infostr); force_pipe_server = 1; - return start_dirmngr (ctrl); + return start_dirmngr_ext (ctrl, ctx_r); } } else @@ -297,7 +297,7 @@ { log_info (_("can't connect to the dirmngr - trying fall back\n")); force_pipe_server = 1; - return start_dirmngr (ctrl); + return start_dirmngr_ext (ctrl, ctx_r); } #endif /*!HAVE_W32_SYSTEM*/ } @@ -309,7 +309,7 @@ log_error ("can't connect to the dirmngr: %s\n", gpg_strerror (rc)); return gpg_error (GPG_ERR_NO_DIRMNGR); } - dirmngr_ctx = ctx; + *ctx_r = ctx; if (DBG_ASSUAN) log_debug ("connection to dirmngr established\n"); @@ -317,6 +317,42 @@ } +static int +start_dirmngr (ctrl_t ctrl) +{ + assert (! dirmngr_ctx_locked); + dirmngr_ctx_locked = 1; + + return start_dirmngr_ext (ctrl, &dirmngr_ctx); +} + + +static void +release_dirmngr (ctrl_t ctrl) +{ + assert (dirmngr_ctx_locked); + dirmngr_ctx_locked = 0; +} + + +static int +start_dirmngr2 (ctrl_t ctrl) +{ + assert (! dirmngr2_ctx_locked); + dirmngr2_ctx_locked = 1; + + return start_dirmngr_ext (ctrl, &dirmngr2_ctx); +} + + +static void +release_dirmngr2 (ctrl_t ctrl) +{ + assert (dirmngr2_ctx_locked); + dirmngr2_ctx_locked = 0; +} + + /* Handle a SENDCERT inquiry. */ static int @@ -485,6 +521,7 @@ if (!certid) { log_error ("error getting the certificate ID\n"); + release_dirmngr (ctrl); return gpg_error (GPG_ERR_GENERAL); } } @@ -584,6 +621,7 @@ ksba_cert_release (rspcert); } } + release_dirmngr (ctrl); return rc; } @@ -738,31 +776,59 @@ char line[ASSUAN_LINELENGTH]; struct lookup_parm_s parm; size_t len; + assuan_context_t ctx; - rc = start_dirmngr (ctrl); - if (rc) - return rc; + /* The lookup function can be invoked from the callback of a lookup + function, for example to walk the chain. */ + assert (!dirmngr_ctx_locked || !dirmngr2_ctx_locked); + if (! dirmngr_ctx_locked) + { + rc = start_dirmngr (ctrl); + if (rc) + return rc; + ctx = dirmngr_ctx; + } + else + { + rc = start_dirmngr2 (ctrl); + if (rc) + return rc; + ctx = dirmngr2_ctx; + } pattern = pattern_from_strlist (names); if (!pattern) - return out_of_core (); + { + if (ctx == dirmngr_ctx) + release_dirmngr (ctrl); + else + release_dirmngr2 (ctrl); + + return out_of_core (); + } snprintf (line, DIM(line)-1, "LOOKUP%s %s", cache_only? " --cache-only":"", pattern); line[DIM(line)-1] = 0; xfree (pattern); parm.ctrl = ctrl; - parm.ctx = dirmngr_ctx; + parm.ctx = ctx; parm.cb = cb; parm.cb_value = cb_value; parm.error = 0; init_membuf (&parm.data, 4096); - rc = assuan_transact (dirmngr_ctx, line, lookup_cb, &parm, + rc = assuan_transact (ctx, line, lookup_cb, &parm, NULL, NULL, lookup_status_cb, &parm); xfree (get_membuf (&parm.data, &len)); + + if (ctx == dirmngr_ctx) + release_dirmngr (ctrl); + else + release_dirmngr2 (ctrl); + if (rc) - return rc; + return rc; return parm.error; } @@ -881,7 +947,10 @@ len += 1 + 3*strlen (argv[i]); /* enough space for percent escaping */ line = xtrymalloc (len); if (!line) - return out_of_core (); + { + release_dirmngr (ctrl); + return out_of_core (); + } p = stpcpy (line, command); for (i=0; i < argc; i++) @@ -910,5 +979,6 @@ run_command_status_cb, ctrl); xfree (line); log_info ("response of dirmngr: %s\n", rc? gpg_strerror (rc): "okay"); + release_dirmngr (ctrl); return rc; } Modified: trunk/sm/gpgsm.h =================================================================== --- trunk/sm/gpgsm.h 2008-08-07 07:46:52 UTC (rev 4808) +++ trunk/sm/gpgsm.h 2008-08-08 01:06:48 UTC (rev 4809) @@ -172,8 +172,6 @@ audit_ctx_t audit; /* NULL or a context for the audit subsystem. */ int agent_seen; /* Flag indicating that the gpg-agent has been accessed. */ - int dirmngr_seen; /* Flag indicating that the dirmngr has been - accessed. */ int with_colons; /* Use column delimited output format */ int with_chain; /* Include the certifying certs in a listing */ From cvs at cvs.gnupg.org Fri Aug 8 19:53:23 2008 From: cvs at cvs.gnupg.org (svn author marcus) Date: Fri, 08 Aug 2008 19:53:23 +0200 Subject: [svn] gpgme - r1329 - trunk/gpgme Message-ID: Author: marcus Date: 2008-08-08 19:53:22 +0200 (Fri, 08 Aug 2008) New Revision: 1329 Modified: trunk/gpgme/ChangeLog trunk/gpgme/rungpg.c Log: 2008-08-08 Marcus Brinkmann * rungpg.c (command_handler): Remove I/O callback on error, too. Modified: trunk/gpgme/ChangeLog =================================================================== --- trunk/gpgme/ChangeLog 2008-07-17 17:09:39 UTC (rev 1328) +++ trunk/gpgme/ChangeLog 2008-08-08 17:53:22 UTC (rev 1329) @@ -1,3 +1,7 @@ +2008-08-08 Marcus Brinkmann + + * rungpg.c (command_handler): Remove I/O callback on error, too. + 2008-06-29 Marcus Brinkmann * gpgme.c (gpgme_cancel_async): Remove unused variable. Modified: trunk/gpgme/rungpg.c =================================================================== --- trunk/gpgme/rungpg.c 2008-07-17 17:09:39 UTC (rev 1328) +++ trunk/gpgme/rungpg.c 2008-08-08 17:53:22 UTC (rev 1329) @@ -645,13 +645,7 @@ err = gpg->cmd.fnc (gpg->cmd.fnc_value, gpg->cmd.code, gpg->cmd.keyword, fd, &processed); - if (err) - return err; - /* We always need to send at least a newline character. */ - if (!processed) - _gpgme_io_write (fd, "\n", 1); - gpg->cmd.code = 0; /* And sleep again until read_status will wake us up again. */ /* XXX We must check if there are any more fds active after removing @@ -660,6 +654,13 @@ gpg->cmd.fd = gpg->fd_data_map[gpg->cmd.idx].fd; gpg->fd_data_map[gpg->cmd.idx].fd = -1; + if (err) + return err; + + /* We always need to send at least a newline character. */ + if (!processed) + _gpgme_io_write (fd, "\n", 1); + return 0; } From cvs at cvs.gnupg.org Mon Aug 11 09:42:26 2008 From: cvs at cvs.gnupg.org (svn author wk) Date: Mon, 11 Aug 2008 09:42:26 +0200 Subject: [svn] GnuPG - r4810 - trunk/scd Message-ID: Author: wk Date: 2008-08-11 09:42:25 +0200 (Mon, 11 Aug 2008) New Revision: 4810 Modified: trunk/scd/ChangeLog trunk/scd/apdu.c Log: Fix APDU buffer problem under MAC OS. Modified: trunk/scd/ChangeLog =================================================================== --- trunk/scd/ChangeLog 2008-08-08 01:06:48 UTC (rev 4809) +++ trunk/scd/ChangeLog 2008-08-11 07:42:25 UTC (rev 4810) @@ -1,3 +1,11 @@ +2008-08-11 Werner Koch + + * apdu.c (reset_pcsc_reader, open_pcsc_reader) + (reset_rapdu_reader, open_rapdu_reader): Allow ATRs of up to 33 + bytes. Provide maximum size of ATR buffer using DIM. Such long + ATR are never seen in reality but the PC/SC library of MAC OS X is + just too buggy. Reported by Ludovic Rousseau. Fixes bug #948. + 2008-07-30 Werner Koch * app-openpgp.c (verify_a_chv): Use xtrymalloc and make the prompt Modified: trunk/scd/apdu.c =================================================================== --- trunk/scd/apdu.c 2008-08-08 01:06:48 UTC (rev 4809) +++ trunk/scd/apdu.c 2008-08-11 07:42:25 UTC (rev 4810) @@ -912,7 +912,7 @@ } - atrlen = 33; + atrlen = DIM(reader_table[0].atr); nreader = sizeof reader - 1; err = pcsc_status (reader_table[slot].pcsc.card, reader, &nreader, @@ -925,7 +925,7 @@ reader_table[slot].atrlen = 0; return pcsc_error_to_sw (err); } - if (atrlen >= DIM (reader_table[0].atr)) + if (atrlen > DIM (reader_table[0].atr)) log_bug ("ATR returned by pcsc_status is too large\n"); reader_table[slot].atrlen = atrlen; reader_table[slot].is_t0 = !!(card_protocol & PCSC_PROTOCOL_T0); @@ -1632,7 +1632,7 @@ char reader[250]; unsigned long readerlen; - atrlen = 32; + atrlen = DIM (reader_table[0].atr); readerlen = sizeof reader -1 ; err = pcsc_status (reader_table[slot].pcsc.card, reader, &readerlen, @@ -1643,7 +1643,7 @@ pcsc_error_string (err), err, readerlen); else { - if (atrlen >= DIM (reader_table[0].atr)) + if (atrlen > DIM (reader_table[0].atr)) log_bug ("ATR returned by pcsc_status is too large\n"); reader_table[slot].atrlen = atrlen; /* If we got to here we know that a card is present @@ -1933,7 +1933,7 @@ rapdu_msg_release (msg); return sw; } - if (msg->datalen >= DIM (slotp->atr)) + if (msg->datalen > DIM (slotp->atr)) { log_error ("ATR returned by the RAPDU layer is too large\n"); rapdu_msg_release (msg); @@ -2114,7 +2114,7 @@ rapdu_strerror (msg->cmd)); goto failure; } - if (msg->datalen >= DIM (slotp->atr)) + if (msg->datalen > DIM (slotp->atr)) { log_error ("ATR returned by the RAPDU layer is too large\n"); goto failure; From cvs at cvs.gnupg.org Mon Aug 11 10:08:10 2008 From: cvs at cvs.gnupg.org (svn author wk) Date: Mon, 11 Aug 2008 10:08:10 +0200 Subject: [svn] GnuPG - r4811 - in trunk: doc g10 Message-ID: Author: wk Date: 2008-08-11 10:08:08 +0200 (Mon, 11 Aug 2008) New Revision: 4811 Modified: trunk/doc/DETAILS trunk/g10/keygen.c Log: Cehck for expire date overflows. Modified: trunk/doc/DETAILS =================================================================== --- trunk/doc/DETAILS 2008-08-11 07:42:25 UTC (rev 4810) +++ trunk/doc/DETAILS 2008-08-11 08:08:08 UTC (rev 4811) @@ -839,10 +839,16 @@ The 3 parts of a key. Remember to use UTF-8 here. If you don't give any of them, no user ID is created. Expire-Date: |([d|w|m|y]) - Set the expiration date for the key (and the subkey). It - may either be entered in ISO date format (2000-08-15) or as - number of days, weeks, month or years. Without a letter days - are assumed. + Set the expiration date for the key (and the subkey). It may + either be entered in ISO date format (2000-08-15) or as number + of days, weeks, month or years. The special notation + "seconds=N" is also allowed to directly give an Epoch + value. Without a letter days are assumed. Note that there is + no check done on the overflow of the type used by OpenPGP for + timestamps. Thus you better make sure that the given value + make sense. Although OpenPGP works with time intervals, GnuPG + uses an absolute value internally and thus the last year we + can represent is 2105. Creation-Date: Set the creation date of the key as stored in the key information and which is also part of the fingerprint Modified: trunk/g10/keygen.c =================================================================== --- trunk/g10/keygen.c 2008-08-11 07:42:25 UTC (rev 4810) +++ trunk/g10/keygen.c 2008-08-11 08:08:08 UTC (rev 4811) @@ -1789,21 +1789,23 @@ u32 parse_expire_string( const char *string ) { - int mult; - u32 seconds,abs_date=0,curtime = make_timestamp(); - - if( !*string ) - seconds = 0; - else if ( !strncmp (string, "seconds=", 8) ) - seconds = atoi (string+8); - else if( (abs_date = scan_isodatestr(string)) && abs_date > curtime ) - seconds = abs_date - curtime; - else if( (mult=check_valid_days(string)) ) - seconds = atoi(string) * 86400L * mult; - else - seconds=(u32)-1; - - return seconds; + int mult; + u32 seconds; + u32 abs_date = 0; + u32 curtime = make_timestamp (); + + if (!*string) + seconds = 0; + else if (!strncmp (string, "seconds=", 8)) + seconds = atoi (string+8); + else if ((abs_date = scan_isodatestr(string)) && abs_date > curtime) + seconds = abs_date - curtime; + else if ((mult = check_valid_days (string))) + seconds = atoi (string) * 86400L * mult; + else + seconds = (u32)(-1); + + return seconds; } /* Parsean Creation-Date string which is either "1986-04-26" or @@ -1916,7 +1918,13 @@ tty_printf (_("Your system can't display dates beyond 2038.\n" "However, it will be correctly handled up to" " 2106.\n")); + else #endif /*SIZEOF_TIME_T*/ + if ( (time_t)((unsigned long)(curtime+interval)) < curtime ) + { + tty_printf (_("invalid value\n")); + continue; + } } if( cpr_enabled() || cpr_get_answer_is_yes("keygen.valid.okay", From cvs at cvs.gnupg.org Mon Aug 11 10:19:51 2008 From: cvs at cvs.gnupg.org (svn author wk) Date: Mon, 11 Aug 2008 10:19:51 +0200 Subject: [svn] GnuPG - r4812 - in branches/STABLE-BRANCH-1-4: . g10 Message-ID: Author: wk Date: 2008-08-11 10:19:48 +0200 (Mon, 11 Aug 2008) New Revision: 4812 Modified: branches/STABLE-BRANCH-1-4/ChangeLog branches/STABLE-BRANCH-1-4/configure.ac branches/STABLE-BRANCH-1-4/g10/ChangeLog branches/STABLE-BRANCH-1-4/g10/keygen.c Log: Fix bug #947 (expire time overflow) Modified: branches/STABLE-BRANCH-1-4/ChangeLog =================================================================== --- branches/STABLE-BRANCH-1-4/ChangeLog 2008-08-11 08:08:08 UTC (rev 4811) +++ branches/STABLE-BRANCH-1-4/ChangeLog 2008-08-11 08:19:48 UTC (rev 4812) @@ -1,3 +1,7 @@ +2008-08-11 Werner Koch + + * configure.ac: Check for size of time_t. + 2008-04-01 Werner Koch * configure.ac (AC_INIT): Fix quoting. Modified: branches/STABLE-BRANCH-1-4/g10/ChangeLog =================================================================== --- branches/STABLE-BRANCH-1-4/g10/ChangeLog 2008-08-11 08:08:08 UTC (rev 4811) +++ branches/STABLE-BRANCH-1-4/g10/ChangeLog 2008-08-11 08:19:48 UTC (rev 4812) @@ -1,3 +1,8 @@ +2008-08-11 Werner Koch + + * keygen.c (ask_expire_interval): Check for time overflow of an + u32. Fixes bug #947. Use SIZEOF_TIME_T for the 2039--2106 check. + 2008-08-01 Werner Koch * tdbio.c (open_db) [!EROFS]: Move closing parens out of the Modified: branches/STABLE-BRANCH-1-4/configure.ac =================================================================== --- branches/STABLE-BRANCH-1-4/configure.ac 2008-08-11 08:08:08 UTC (rev 4811) +++ branches/STABLE-BRANCH-1-4/configure.ac 2008-08-11 08:19:48 UTC (rev 4812) @@ -949,6 +949,19 @@ AC_CHECK_SIZEOF(unsigned int) AC_CHECK_SIZEOF(unsigned long) AC_CHECK_SIZEOF(unsigned long long) +AC_CHECK_SIZEOF(time_t,,[[ +#include +#if TIME_WITH_SYS_TIME +# include +# include +#else +# if HAVE_SYS_TIME_H +# include +# else +# include +# endif +#endif +]]) # Ensure that we have UINT64_C before we bother to check for uint64_t AC_CHECK_HEADERS([inttypes.h]) Modified: branches/STABLE-BRANCH-1-4/g10/keygen.c =================================================================== --- branches/STABLE-BRANCH-1-4/g10/keygen.c 2008-08-11 08:08:08 UTC (rev 4811) +++ branches/STABLE-BRANCH-1-4/g10/keygen.c 2008-08-11 08:19:48 UTC (rev 4812) @@ -1697,12 +1697,18 @@ ? _("Key expires at %s\n") : _("Signature expires at %s\n"), asctimestamp((ulong)(timestamp + interval) ) ); - /* FIXME: This check yields warning on alhas: Write a - configure check and to this check here only for 32 bit - machines */ - if( (time_t)((ulong)(timestamp+interval)) < 0 ) - tty_printf(_("Your system can't display dates beyond 2038.\n" - "However, it will be correctly handled up to 2106.\n")); +#if SIZEOF_TIME_T <= 4 + if ((time_t)((ulong)(timestamp+interval)) < 0 ) + tty_printf (_("Your system can't display dates beyond 2038.\n" + "However, it will be correctly handled up to" + " 2106.\n")); + else +#endif /*SIZEOF_TIME_T*/ + if ( (time_t)((unsigned long)(timestamp+interval)) < timestamp ) + { + tty_printf (_("invalid value\n")); + continue; + } } if( cpr_enabled() || cpr_get_answer_is_yes("keygen.valid.okay", From cvs at cvs.gnupg.org Mon Aug 11 19:23:47 2008 From: cvs at cvs.gnupg.org (svn author marcus) Date: Mon, 11 Aug 2008 19:23:47 +0200 Subject: [svn] gpgme - r1330 - trunk/gpgme Message-ID: Author: marcus Date: 2008-08-11 19:23:45 +0200 (Mon, 11 Aug 2008) New Revision: 1330 Modified: trunk/gpgme/ChangeLog trunk/gpgme/gpgme.c trunk/gpgme/gpgme.h trunk/gpgme/ops.h trunk/gpgme/rungpg.c trunk/gpgme/wait-global.c trunk/gpgme/wait-private.c trunk/gpgme/wait-user.c Log: 2008-08-11 Marcus Brinkmann * rungpg.c (gpg_cancel): Remove cmd fd before status fd. * gpgme.c (_gpgme_cancel_with_err): New function. (gpgme_cancel): Reimplement in terms of _gpgme_cancel_with_err. * wait-private.c (_gpgme_wait_on_condition): Use _gpgme_cancel_with_err. * wait-user.c (_gpgme_user_io_cb_handler): Likewise. * wait-global.c (_gpgme_wait_global_event_cb, gpgme_wait): Likewise. Modified: trunk/gpgme/ChangeLog =================================================================== --- trunk/gpgme/ChangeLog 2008-08-08 17:53:22 UTC (rev 1329) +++ trunk/gpgme/ChangeLog 2008-08-11 17:23:45 UTC (rev 1330) @@ -1,3 +1,13 @@ +2008-08-11 Marcus Brinkmann + + * rungpg.c (gpg_cancel): Remove cmd fd before status fd. + * gpgme.c (_gpgme_cancel_with_err): New function. + (gpgme_cancel): Reimplement in terms of _gpgme_cancel_with_err. + * wait-private.c (_gpgme_wait_on_condition): Use + _gpgme_cancel_with_err. + * wait-user.c (_gpgme_user_io_cb_handler): Likewise. + * wait-global.c (_gpgme_wait_global_event_cb, gpgme_wait): Likewise. + 2008-08-08 Marcus Brinkmann * rungpg.c (command_handler): Remove I/O callback on error, too. Modified: trunk/gpgme/gpgme.c =================================================================== --- trunk/gpgme/gpgme.c 2008-08-08 17:53:22 UTC (rev 1329) +++ trunk/gpgme/gpgme.c 2008-08-11 17:23:45 UTC (rev 1330) @@ -106,24 +106,31 @@ } -/* Cancel a pending asynchronous operation. */ gpgme_error_t -gpgme_cancel (gpgme_ctx_t ctx) +_gpgme_cancel_with_err (gpgme_ctx_t ctx, gpg_error_t ctx_err) { gpgme_error_t err; - TRACE_BEG (DEBUG_CTX, "gpgme_cancel", ctx); + TRACE_BEG1 (DEBUG_CTX, "_gpgme_cancel_with_err", ctx, "ctx_err=%i", + ctx_err); err = _gpgme_engine_cancel (ctx->engine); if (err) return TRACE_ERR (err); - err = gpg_error (GPG_ERR_CANCELED); - _gpgme_engine_io_event (ctx->engine, GPGME_EVENT_DONE, &err); + _gpgme_engine_io_event (ctx->engine, GPGME_EVENT_DONE, &ctx_err); return TRACE_ERR (0); } +/* Cancel a pending asynchronous operation. */ +gpgme_error_t +gpgme_cancel (gpgme_ctx_t ctx) +{ + return _gpgme_cancel_with_err (ctx, gpg_error (GPG_ERR_CANCELED)); +} + + /* Cancel a pending operation asynchronously. */ gpgme_error_t gpgme_cancel_async (gpgme_ctx_t ctx) Modified: trunk/gpgme/gpgme.h =================================================================== --- trunk/gpgme/gpgme.h 2008-08-08 17:53:22 UTC (rev 1329) +++ trunk/gpgme/gpgme.h 2008-08-11 17:23:45 UTC (rev 1330) @@ -72,7 +72,7 @@ AM_PATH_GPGME macro) check that this header matches the installed library. Warning: Do not edit the next line. configure will do that for you! */ -#define GPGME_VERSION "1.1.7-svn1326" +#define GPGME_VERSION "1.1.7-svn1329" Modified: trunk/gpgme/ops.h =================================================================== --- trunk/gpgme/ops.h 2008-08-08 17:53:22 UTC (rev 1329) +++ trunk/gpgme/ops.h 2008-08-11 17:23:45 UTC (rev 1330) @@ -27,6 +27,8 @@ /* From gpgme.c. */ +gpgme_error_t _gpgme_cancel_with_err (gpgme_ctx_t ctx, gpg_error_t ctx_err); + void _gpgme_release_result (gpgme_ctx_t ctx); Modified: trunk/gpgme/rungpg.c =================================================================== --- trunk/gpgme/rungpg.c 2008-08-08 17:53:22 UTC (rev 1329) +++ trunk/gpgme/rungpg.c 2008-08-11 17:23:45 UTC (rev 1330) @@ -340,6 +340,17 @@ if (!gpg) return gpg_error (GPG_ERR_INV_VALUE); + /* If gpg may be waiting for a cmd, close the cmd fd first. On + Windows, close operations block on the reader/writer thread. */ + if (gpg->cmd.used) + { + if (gpg->cmd.fd != -1) + _gpgme_io_close (gpg->cmd.fd); + else if (gpg->fd_data_map + && gpg->fd_data_map[gpg->cmd.idx].fd != -1) + _gpgme_io_close (gpg->fd_data_map[gpg->cmd.idx].fd); + } + if (gpg->status.fd[0] != -1) _gpgme_io_close (gpg->status.fd[0]); if (gpg->status.fd[1] != -1) @@ -353,8 +364,6 @@ free_fd_data_map (gpg->fd_data_map); gpg->fd_data_map = NULL; } - if (gpg->cmd.fd != -1) - _gpgme_io_close (gpg->cmd.fd); return 0; } Modified: trunk/gpgme/wait-global.c =================================================================== --- trunk/gpgme/wait-global.c 2008-08-08 17:53:22 UTC (rev 1329) +++ trunk/gpgme/wait-global.c 2008-08-11 17:23:45 UTC (rev 1330) @@ -200,16 +200,9 @@ gpgme_error_t err = ctx_active (ctx); if (err) - { - /* An error occured. Close all fds in this context, and - send the error in a done event. */ - unsigned int idx; - - for (idx = 0; idx <= ctx->fdt.size; idx++) - if (ctx->fdt.fds[idx].fd != -1) - _gpgme_io_close (ctx->fdt.fds[idx].fd); - _gpgme_engine_io_event (ctx->engine, GPGME_EVENT_DONE, &err); - } + /* An error occured. Close all fds in this context, and + send the error in a done event. */ + _gpgme_cancel_with_err (ctx, &err); } break; @@ -321,13 +314,7 @@ { /* An error occured. Close all fds in this context, and signal it. */ - unsigned int idx; - - for (idx = 0; idx < ictx->fdt.size; idx++) - if (ictx->fdt.fds[idx].fd != -1) - _gpgme_io_close (ictx->fdt.fds[idx].fd); - _gpgme_engine_io_event (ictx->engine, GPGME_EVENT_DONE, - &err); + _gpgme_cancel_with_err (ictx, err); /* Break out of the loop, and retry the select() from scratch, because now all fds should be Modified: trunk/gpgme/wait-private.c =================================================================== --- trunk/gpgme/wait-private.c 2008-08-08 17:53:22 UTC (rev 1329) +++ trunk/gpgme/wait-private.c 2008-08-11 17:23:45 UTC (rev 1330) @@ -89,10 +89,7 @@ unsigned int idx; err = gpg_error_from_errno (errno); - for (idx = 0; idx < ctx->fdt.size; idx++) - if (ctx->fdt.fds[idx].fd != -1) - _gpgme_io_close (ctx->fdt.fds[idx].fd); - _gpgme_engine_io_event (ctx->engine, GPGME_EVENT_DONE, &err); + _gpgme_cancel_with_err (ctx, err); return err; } @@ -116,12 +113,8 @@ { /* An error occured. Close all fds in this context, and signal it. */ - unsigned int idx; - - for (idx = 0; idx < ctx->fdt.size; idx++) - if (ctx->fdt.fds[idx].fd != -1) - _gpgme_io_close (ctx->fdt.fds[idx].fd); - _gpgme_engine_io_event (ctx->engine, GPGME_EVENT_DONE, &err); + _gpgme_cancel_with_err (ctx, err); + return err; } } Modified: trunk/gpgme/wait-user.c =================================================================== --- trunk/gpgme/wait-user.c 2008-08-08 17:53:22 UTC (rev 1329) +++ trunk/gpgme/wait-user.c 2008-08-11 17:23:45 UTC (rev 1330) @@ -55,14 +55,7 @@ if (! err) err = _gpgme_run_io_cb (&ctx->fdt.fds[tag->idx], 0); if (err) - { - unsigned int idx; - - for (idx = 0; idx < ctx->fdt.size; idx++) - if (ctx->fdt.fds[idx].fd != -1) - _gpgme_io_close (ctx->fdt.fds[idx].fd); - _gpgme_engine_io_event (ctx->engine, GPGME_EVENT_DONE, &err); - } + _gpgme_cancel_with_err (ctx, err); else { unsigned int i; From cvs at cvs.gnupg.org Wed Aug 13 17:41:50 2008 From: cvs at cvs.gnupg.org (svn author wk) Date: Wed, 13 Aug 2008 17:41:50 +0200 Subject: [svn] GnuPG - r4813 - in trunk: doc g10 scd sm Message-ID: Author: wk Date: 2008-08-13 17:41:48 +0200 (Wed, 13 Aug 2008) New Revision: 4813 Modified: trunk/doc/DETAILS trunk/g10/ChangeLog trunk/scd/ChangeLog trunk/sm/ChangeLog trunk/sm/keylist.c Log: Print a 'f' for validated non-root certificates in gpgsm colon style listing. Doc fixes. Modified: trunk/g10/ChangeLog =================================================================== --- trunk/g10/ChangeLog 2008-08-11 08:19:48 UTC (rev 4812) +++ trunk/g10/ChangeLog 2008-08-13 15:41:48 UTC (rev 4813) @@ -1,3 +1,8 @@ +2008-08-11 Werner Koch + + * keygen.c (ask_expire_interval): Check for time overflow of an + u32. Fixes bug #947. + 2008-08-01 Werner Koch * tdbio.c (open_db) [!EROFS]: Move closing parens out of the Modified: trunk/scd/ChangeLog =================================================================== --- trunk/scd/ChangeLog 2008-08-11 08:19:48 UTC (rev 4812) +++ trunk/scd/ChangeLog 2008-08-13 15:41:48 UTC (rev 4813) @@ -4,7 +4,7 @@ (reset_rapdu_reader, open_rapdu_reader): Allow ATRs of up to 33 bytes. Provide maximum size of ATR buffer using DIM. Such long ATR are never seen in reality but the PC/SC library of MAC OS X is - just too buggy. Reported by Ludovic Rousseau. Fixes bug #948. + just too buggy. Reported by Ludovic Rousseau. Fixes bug #948. 2008-07-30 Werner Koch Modified: trunk/sm/ChangeLog =================================================================== --- trunk/sm/ChangeLog 2008-08-11 08:19:48 UTC (rev 4812) +++ trunk/sm/ChangeLog 2008-08-13 15:41:48 UTC (rev 4813) @@ -1,3 +1,7 @@ +2008-08-13 Werner Koch + + * keylist.c (list_cert_colon): Print 'f' for validated certs. + 2008-08-08 Marcus Brinkmann * gpgsm.h (struct server_control_s): Remove member dirmngr_seen. Modified: trunk/doc/DETAILS =================================================================== --- trunk/doc/DETAILS 2008-08-11 08:19:48 UTC (rev 4812) +++ trunk/doc/DETAILS 2008-08-13 15:41:48 UTC (rev 4813) @@ -57,8 +57,12 @@ f = The key is fully trusted u = The key is ultimately trusted. This often means that the secret key is available, but any key may - be marked as ultimately trusted. + be marked as ultimately trusted. + For X.509 certificates an 'u' is used for a trusted root + certificates (i.e. for the truct anchor) and and 'f' for + all other validated certificates. + 3. Field: length of key in bits. 4. Field: Algorithm: 1 = RSA Modified: trunk/sm/keylist.c =================================================================== --- trunk/sm/keylist.c 2008-08-11 08:19:48 UTC (rev 4812) +++ trunk/sm/keylist.c 2008-08-13 15:41:48 UTC (rev 4813) @@ -415,6 +415,8 @@ *truststring = 'e'; else if (valerr) *truststring = 'i'; + else if (ctrl->with_validation && !is_root) + *truststring = 'f'; } /* If we have no truststring yet (i.e. the certificate might be From cvs at cvs.gnupg.org Mon Aug 18 13:08:05 2008 From: cvs at cvs.gnupg.org (svn author wk) Date: Mon, 18 Aug 2008 13:08:05 +0200 Subject: [svn] GnuPG - r4814 - trunk/scd Message-ID: Author: wk Date: 2008-08-18 13:08:04 +0200 (Mon, 18 Aug 2008) New Revision: 4814 Modified: trunk/scd/ChangeLog trunk/scd/app-openpgp.c Log: Fix new test for v2 cards. Modified: trunk/scd/ChangeLog =================================================================== --- trunk/scd/ChangeLog 2008-08-13 15:41:48 UTC (rev 4813) +++ trunk/scd/ChangeLog 2008-08-18 11:08:04 UTC (rev 4814) @@ -1,3 +1,7 @@ +2008-08-18 Werner Koch + + * app-openpgp.c (do_setattr): Fix test for v2 cards. + 2008-08-11 Werner Koch * apdu.c (reset_pcsc_reader, open_pcsc_reader) Modified: trunk/scd/app-openpgp.c =================================================================== --- trunk/scd/app-openpgp.c 2008-08-13 15:41:48 UTC (rev 4813) +++ trunk/scd/app-openpgp.c 2008-08-18 11:08:04 UTC (rev 4814) @@ -1657,8 +1657,8 @@ ; if (!table[idx].name) return gpg_error (GPG_ERR_INV_NAME); - if (!table[idx].need_v2) - return gpg_error (GPG_ERR_NOT_SUPPORTED); + if (table[idx].need_v2) + return gpg_error (GPG_ERR_NOT_SUPPORTED); /* Not yet supported. */ switch (table[idx].need_chv) { From cvs at cvs.gnupg.org Tue Aug 19 17:55:53 2008 From: cvs at cvs.gnupg.org (svn author wk) Date: Tue, 19 Aug 2008 17:55:53 +0200 Subject: [svn] gcry - r1295 - in trunk: . cipher doc random src tests Message-ID: Author: wk Date: 2008-08-19 17:55:46 +0200 (Tue, 19 Aug 2008) New Revision: 1295 Added: trunk/random/random-csprng.c trunk/random/random-fips.c trunk/random/random.c trunk/src/cipher-proto.h trunk/src/hmac256.c trunk/src/hmac256.h Removed: trunk/BUGS trunk/random/random.c Modified: trunk/ChangeLog trunk/Makefile.am trunk/NEWS trunk/cipher/ChangeLog trunk/cipher/Makefile.am trunk/cipher/ac.c trunk/cipher/cipher.c trunk/cipher/des.c trunk/cipher/dsa.c trunk/cipher/ecc.c trunk/cipher/md.c trunk/cipher/pubkey.c trunk/cipher/rijndael.c trunk/cipher/rsa.c trunk/cipher/sha1.c trunk/cipher/sha256.c trunk/cipher/sha512.c trunk/configure.ac trunk/doc/ChangeLog trunk/doc/Makefile.am trunk/doc/gcrypt.texi trunk/random/ChangeLog trunk/random/Makefile.am trunk/random/rand-internal.h trunk/random/random.h trunk/src/ChangeLog trunk/src/Makefile.am trunk/src/ath.c trunk/src/ath.h trunk/src/cipher.h trunk/src/g10lib.h trunk/src/gcrypt-module.h trunk/src/gcrypt.h.in trunk/src/global.c trunk/src/libgcrypt.def trunk/src/libgcrypt.vers trunk/src/misc.c trunk/src/module.c trunk/src/visibility.c trunk/src/visibility.h trunk/tests/ChangeLog trunk/tests/basic.c trunk/tests/benchmark.c trunk/tests/register.c Log: A whole bunch of changes to eventually support FIPS restricted mode. Also some documentation improvements and other minor enhancements. See the ChangeLogs. Stay tuned. [The diff below has been truncated] Modified: trunk/ChangeLog =================================================================== --- trunk/ChangeLog 2008-08-04 13:16:45 UTC (rev 1294) +++ trunk/ChangeLog 2008-08-19 15:55:46 UTC (rev 1295) @@ -1,3 +1,11 @@ +2008-08-18 Werner Koch + + * Makefile.am (EXTRA_DIST): Remove the unused BUGS file. + +2008-08-15 Werner Koch + + * configure.ac (AH_BOTTOM): Define GCRY_GPG_ERR_NOT_OPERATIONAL. + 2008-07-05 Werner Koch * random/: New. Modified: trunk/cipher/ChangeLog =================================================================== --- trunk/cipher/ChangeLog 2008-08-04 13:16:45 UTC (rev 1294) +++ trunk/cipher/ChangeLog 2008-08-19 15:55:46 UTC (rev 1295) @@ -1,3 +1,96 @@ +2008-08-19 Werner Koch + + * pubkey.c (sexp_elements_extract_ecc) [!USE_ECC]: Do not allow + allow "curve" parameter. + +2008-08-15 Werner Koch + + * pubkey.c (_gcry_pk_selftest): New. + * dsa.c (selftests_dsa, run_selftests): New. + * rsa.c (selftests_rsa, run_selftests): New. + * ecc.c (selftests_ecdsa, run_selftests): New. + + * md.c (_gcry_md_selftest): New. + * sha1.c (run_selftests, selftests_sha1): New. + * sha256.c (selftests_sha224, selftests_sha256, run_selftests): New. + * sha512.c (selftests_sha384, selftests_sha512, run_selftests): New. + + * des.c (selftest): Remove static variable form selftest. + (des_setkey): No on-the-fly self test in fips mode. + (tripledes_set3keys): Ditto. + + * cipher.c (_gcry_cipher_setkey, _gcry_cipher_setiv): + + * dsa.c (generate): Bail out in fips mode if NBITS is less than 1024. + * rsa.c (generate): Return an error code if the the requested size + is less than 1024 and we are in fpis mode. + (_gcry_rsa_generate): Take care of that error code. + + * ecc.c (generate_curve): In fips mode enable only NIST curves. + + * cipher.c (_gcry_cipher_selftest): New. + + * sha512.c (_gcry_digest_extraspec_sha384) + (_gcry_digest_extraspec_sha512): New. + * sha256.c (_gcry_digest_extraspec_sha224) + (_gcry_digest_extraspec_sha256): New. + * sha1.c (_gcry_digest_extraspec_sha1): New. + * ecc.c (_gcry_pubkey_extraspec_ecdsa): New. + * dsa.c (_gcry_pubkey_extraspec_dsa): New. + * rsa.c (_gcry_pubkey_extraspec_rsa): New. + * rijndael.c (_gcry_cipher_extraspec_aes) + (_gcry_cipher_extraspec_aes192, _gcry_cipher_extraspec_aes256): New. + * des.c (_gcry_cipher_extraspec_tripledes): New. + + * cipher.c (gcry_cipher_register): Rename to _gcry_cipher_register. + Add arg EXTRASPEC. + (dummy_extra_spec): New. + (cipher_table_entry): Add extraspec field. + * md.c (_gcry_md_register): Rename to _gcry_md_register. Add + arg EXTRASPEC. + (dummy_extra_spec): New. + (digest_table_entry): Add extraspec field. + * pubkey.c (gcry_pk_register): Rename to _gcry_pk_register. Add + arg EXTRASPEC. + (dummy_extra_spec): New. + (pubkey_table_entry): Add extraspec field. + + * ac.c: Let most public functions return GPG_ERR_UNSUPPORTED in + fips mode. + + * pubkey.c (pubkey_table_entry): Add field FIPS_ALLOWED and mark + appropriate algorithms. + (dummy_generate, dummy_check_secret_key, dummy_encrypt) + (dummy_decrypt, dummy_sign, dummy_verify, dummy_get_nbits): Signal + a fips error when used. + (gcry_pk_register): In fips mode do not allow to register new + algorithms. + + * md.c (digest_table): Add field FIPS_ALLOWED and mark appropriate + algorithms. + (md_register_default): In fips mode register only fips algorithms. + (gcry_md_register): In fips mode do not allow to register new + algorithms. + (gcry_md_get): Signal a fips error if called. + (gcry_md_hash_buffer): Do not allow rmd160 when not in fips mode. + (md_start_debug): Disable in fips_mode. + + * md.c (gcry_md_register_default): Rename to .. + (md_register_default): .. this. + (md_digest): Remove this commented fucntion. + * pubkey.c (gcry_pk_register_default): Rename to .. + (pk_register_default): .. this. + + * cipher.c (cipher_table_entry): Add field FIPS_ALLOWED. + (gcry_cipher_register_default): Register only fips approved + algorithms. + (gcry_cipher_register): Do not allow to register new ciphers. + (cipher_setiv): Signal fips error. + + * cipher (gcry_cipher_register_default): Rename to .. + (cipher_register_default): .. this. + (REGISTER_DEFAULT_CIPHERS): Adjust for that change. + 2008-07-05 Werner Koch * random-daemon.c, random.h, rndhw.c, rndunix.c, rand-internal.h Modified: trunk/doc/ChangeLog =================================================================== --- trunk/doc/ChangeLog 2008-08-04 13:16:45 UTC (rev 1294) +++ trunk/doc/ChangeLog 2008-08-19 15:55:46 UTC (rev 1295) @@ -1,3 +1,21 @@ +2008-08-18 Werner Koch + + * gcrypt.texi (Top): Remove the detailmenu. + (Public Key Cryptographi (II)): Move into a section of the PK + interface description. + (Hashing): Move after the encryption chapters. + +2008-08-15 Werner Koch + + * gcrypt.texi (Controlling the library): Remove + GCRYCTL_DUMP_CONFIG because it is not implemented. + (Initializing the library): Describe initialization steps with + regard to secure memory. + + * gcrypt.texi (Working with cipher handles): Adjust for + implementation changes of gcry_cipher_setkey, gcry_cipher_setiv and + gcry_cipher_setctr. + 2008-01-04 Werner Koch * gcrypt.texi (Controlling the library): Add remark that the Modified: trunk/random/ChangeLog =================================================================== --- trunk/random/ChangeLog 2008-08-04 13:16:45 UTC (rev 1294) +++ trunk/random/ChangeLog 2008-08-19 15:55:46 UTC (rev 1295) @@ -1,3 +1,34 @@ +2008-08-15 Werner Koch + + * random-fips.c: New. + + * random-csprng.c (process-cb, progress_cb_data): Move to + random.c. + (_gcry_register_random_progress, _gcry_random_progress): Ditto. + (_gcry_random_initialize): Rename to _gcry_rngcsprng_initialize. + (_gcry_random_dump_stats): Rename to _gcry_rngcsprng_dump_stats. + (_gcry_secure_random_alloc): Rename to + _gcry_rngcsprng_secure_alloc. + (_gcry_enable_quick_random_gen): Rename to + _gcry_rngcsprng_enable_quick_gen. + (_gcry_set_random_daemon_socket): Rename to + _gcry_rngcsprng_set_daemon_socket. + (_gcry_use_random_daemon): Rename to _gcry_rngcsprng_use_daemon. + (_gcry_random_is_faked): Rename to _gcry_rngcsprng_is_faked. + (gcry_random_add_bytes): Rename to _gcry_rngcsprng_add_bytes. + (gcry_random_bytes): Remove + (gcry_random_bytes_secure): Remove. + (gcry_randomize): Rename to _gcry_rngcsprng_randomize. + (_gcry_set_random_seed_file): Rename to + _gcry_rngcsprng_set_seed_file. + (_gcry_update_random_seed_file): Rename to + _gcry_rngcsprng_update_seed_file. + (_gcry_fast_random_poll): Rename to _gcry_rngcsprng_fast_poll. + (gcry_create_nonce): Rename to _gcry_rngcsprng_create_nonce. + + * random.c: Factor all code out to random-csprng.c and implement + wrapper functions. + 2008-07-05 Werner Koch * random-daemon.c, random.h, rndhw.c, rndunix.c, rand-internal.h * Modified: trunk/src/ChangeLog =================================================================== --- trunk/src/ChangeLog 2008-08-04 13:16:45 UTC (rev 1294) +++ trunk/src/ChangeLog 2008-08-19 15:55:46 UTC (rev 1295) @@ -1,3 +1,62 @@ +2008-08-15 Werner Koch + + * gcrypt.h.in (gcry_cipher_setkey): Replace macro by function. + (gcry_cipher_setiv): Ditto. + (gcry_cipher_setctr): Ditto. + * visibility.c (gcry_cipher_setkey, gcry_cipher_setiv) + (gcry_cipher_setctr): New. + * visibility.h (gcry_cipher_setkey, gcry_cipher_setiv) + (gcry_cipher_setctr): New. + * libgcrypt.vers (gcry_cipher_setkey, gcry_cipher_setiv) + (gcry_cipher_setctr): New. + * libgcrypt.def (gcry_cipher_setkey, gcry_cipher_setiv) + (gcry_cipher_setctr): New. + + * hmac256.h, hmac256.c: New. + * Makefile.am (hmac256_SOURCES): New. + * Makefile.am (bin_PROGRAMS): Add hmac256. + + * gcrypt.h.in (struct gcry_thread_cbs): Change type of OPTION to + unsigned int. Although this is a type change it does not make a + difference. + * ath.c (ath_install): Take the version of the option field in + account. + + * visibility.c (gcry_pk_encrypt, gcry_pk_decrypt, gcry_pk_sign) + (gcry_pk_verify, gcry_pk_testkey, gcry_pk_genkey) + (gcry_pk_get_nbits, gcry_pk_get_keygrip) + (gcry_md_open, gcry_md_copy, gcry_md_enable) + (gcry_md_write, md_final, gcry_md_ctl, gcry_md_setkey) + (gcry_md_hash_buffer, gcry_md_get_algo, gcry_md_info) + (gcry_md_is_enabled) + (gcry_cipher_open, gcry_cipher_encrypt) + (gcry_cipher_decrypt, gcry_cipher_ctl) + (gcry_cipher_algo_info): Check whether the library is operational. + + * cipher-proto.h: New. + * cipher.h: Include cipher-proto.h. + * visibility.h: Remove duplicate macro definitions. Remove + gcry_cipher_register, gcry_md_register, gcry_pk_register macros. + * visibility.c: Include cipher-proto.h. + (gcry_cipher_register): Pass dummy extra args to the internal + register function. + (gcry_md_register, gcry_pk_register): Ditto. + * g10lib.h (struct gcry_module): Add field EXTRASPEC. + * module.c (_gcry_module_add): Add arg EXTRASPEC. Changed all + callers to pass NULL. + + * fips.c: New. + * gcrypt.h.in (GCRYCTL_FIPS_MODE_P): New. + * global.c (global_init): Call fips initialization. + (_gcry_vcontrol): Add GCRYCTL_FIPS_MODE_P code. + (print_config): Add config item fips-mode. + (gcry_set_allocation_handler): Do not allow the use of custom + allocation handlers. + (gcry_set_outofcore_handler): Ditto. + (_gcry_get_debug_flag): Do not return any debug flags in fips mode. + * misc.c (_gcry_logv): Signal fips error on BUG or FATAL. + (_gcry_fatal_error): Ditto. + 2008-07-05 Werner Koch * Makefile.am: Include librandom.la. Modified: trunk/tests/ChangeLog =================================================================== --- trunk/tests/ChangeLog 2008-08-04 13:16:45 UTC (rev 1294) +++ trunk/tests/ChangeLog 2008-08-19 15:55:46 UTC (rev 1295) @@ -1,3 +1,17 @@ +2008-08-18 Werner Koch + + * basic.c (main): Add option --fips. + +2008-08-15 Werner Koch + + * register.c (main): Check for fips mode. + (check_run): Take care of fips mode. + + * basic.c (check_cbc_mac_cipher, check_ciphers, check_digests) + (check_hmac, check_pubkey): Do not test unavalaible algorithms in + fips mode. + (main): Check for fips mode. + 2008-04-22 Werner Koch * basic.c (check_one_cipher): Also check in-place encryption. Modified: trunk/Makefile.am =================================================================== --- trunk/Makefile.am 2008-08-04 13:16:45 UTC (rev 1294) +++ trunk/Makefile.am 2008-08-19 15:55:46 UTC (rev 1295) @@ -24,7 +24,7 @@ DIST_SUBDIRS = m4 mpi cipher random src doc tests SUBDIRS = mpi cipher random src doc tests -EXTRA_DIST = BUGS autogen.sh README.SVN +EXTRA_DIST = autogen.sh README.SVN DISTCLEANFILES = Modified: trunk/NEWS =================================================================== --- trunk/NEWS 2008-08-04 13:16:45 UTC (rev 1294) +++ trunk/NEWS 2008-08-19 15:55:46 UTC (rev 1295) @@ -1,7 +1,26 @@ Noteworthy changes in version 1.4.2 ------------------------------------------------ + * The library may now be switched into a FIPS mode. + * More runtime selftests. + + * A few macros have been replaced by functions for better type + checking. + + * The thread initialiation structure now carries version information. + + * Interface changes relative to the 1.3.0 release: + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + GCRYCTL_OPERATIONAL_P NEW. + GCRYCTL_FIPS_MODE_P NEW. + GCRYCTL_FORCE_FIPS_MODE NEW. + gcry_cipher_setkey NEW: Replaces macro. + gcry_cipher_setiv NEW: Replaces macro. + gcry_cipher_setctr NEW: Replaces macro. + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + Noteworthy changes in version 1.4.1 (2008-04-25) ------------------------------------------------ Modified: trunk/cipher/Makefile.am =================================================================== --- trunk/cipher/Makefile.am 2008-08-04 13:16:45 UTC (rev 1294) +++ trunk/cipher/Makefile.am 2008-08-19 15:55:46 UTC (rev 1295) @@ -36,6 +36,7 @@ libcipher_la_SOURCES = \ cipher.c pubkey.c ac.c md.c \ +hmac-tests.c \ bithelp.h \ primegen.c \ rmd.h @@ -65,6 +66,7 @@ rfc2268.c \ camellia.c camellia.h camellia-glue.c + # We need to lower the optimization for this module. tiger.o: $(srcdir)/tiger.c `echo $(COMPILE) -c $(srcdir)/tiger.c | sed -e 's/-O[2-9s]*/-O1/g' ` Modified: trunk/cipher/ac.c =================================================================== --- trunk/cipher/ac.c 2008-08-04 13:16:45 UTC (rev 1294) +++ trunk/cipher/ac.c 2008-08-19 15:55:46 UTC (rev 1295) @@ -127,6 +127,9 @@ gcry_ac_data_t data_new; gcry_error_t err; + if (fips_mode ()) + return gpg_error (GPG_ERR_NOT_SUPPORTED); + data_new = gcry_malloc (sizeof (*data_new)); if (! data_new) { @@ -240,6 +243,9 @@ gcry_ac_data_t data_new; gcry_error_t err; + if (fips_mode ()) + return gpg_error (GPG_ERR_NOT_SUPPORTED); + /* Allocate data set. */ data_new = gcry_malloc (sizeof (*data_new)); if (! data_new) @@ -290,6 +296,9 @@ name_cp = NULL; mpi_cp = NULL; + if (fips_mode ()) + return gpg_error (GPG_ERR_NOT_SUPPORTED); + if (flags & ~(GCRY_AC_FLAG_DEALLOC | GCRY_AC_FLAG_COPY)) { err = gcry_error (GPG_ERR_INV_ARG); @@ -370,6 +379,9 @@ gcry_error_t err; unsigned int i; + if (fips_mode ()) + return gpg_error (GPG_ERR_NOT_SUPPORTED); + if (flags & ~(GCRY_AC_FLAG_COPY)) { err = gcry_error (GPG_ERR_INV_ARG); @@ -421,6 +433,9 @@ name_cp = NULL; mpi_cp = NULL; + if (fips_mode ()) + return gpg_error (GPG_ERR_NOT_SUPPORTED); + if (flags & ~(GCRY_AC_FLAG_COPY)) { err = gcry_error (GPG_ERR_INV_ARG); @@ -496,6 +511,9 @@ arg_list = NULL; err = 0; + if (fips_mode ()) + return gpg_error (GPG_ERR_NOT_SUPPORTED); + /* Calculate size of S-expression representation. */ i = 0; @@ -626,6 +644,9 @@ mpi = NULL; err = 0; + if (fips_mode ()) + return gpg_error (GPG_ERR_NOT_SUPPORTED); + /* Process S-expression/identifiers. */ if (identifiers) @@ -795,6 +816,9 @@ if (! data) return; + if (fips_mode ()) + return; + mpi_buffer = NULL; data_n = _gcry_ac_data_length (data); @@ -859,6 +883,9 @@ { memset (ac_io, 0, sizeof (*ac_io)); + if (fips_mode ()) + return; + assert ((mode == GCRY_AC_IO_READABLE) || (mode == GCRY_AC_IO_WRITABLE)); assert ((type == GCRY_AC_IO_STRING) || (type == GCRY_AC_IO_STRING)); @@ -1362,6 +1389,9 @@ *handle = NULL; module = NULL; + if (fips_mode ()) + return gpg_error (GPG_ERR_NOT_SUPPORTED); + /* Get name. */ algorithm_name = _gcry_pk_aliased_algo_name (algorithm); if (! algorithm_name) @@ -1431,6 +1461,9 @@ (void)handle; + if (fips_mode ()) + return gpg_error (GPG_ERR_NOT_SUPPORTED); + /* Allocate. */ key_new = gcry_malloc (sizeof (*key_new)); if (! key_new) @@ -1488,6 +1521,9 @@ (void)misc_data; + if (fips_mode ()) + return gpg_error (GPG_ERR_NOT_SUPPORTED); + key_data_secret = NULL; key_data_public = NULL; key_secret = NULL; @@ -1652,6 +1688,9 @@ { gcry_ac_key_t key; + if (fips_mode ()) + return NULL; + switch (which) { case GCRY_AC_KEY_SECRET: @@ -1710,6 +1749,8 @@ gcry_ac_data_t _gcry_ac_key_data_get (gcry_ac_key_t key) { + if (fips_mode ()) + return NULL; return key->data; } @@ -1720,6 +1761,9 @@ gcry_sexp_t key_sexp; gcry_error_t err; + if (fips_mode ()) + return gpg_error (GPG_ERR_NOT_SUPPORTED); + key_sexp = NULL; err = ac_data_construct (ac_key_identifiers[key->type], 0, 0, handle->algorithm_name, key->data, &key_sexp); @@ -1744,6 +1788,9 @@ gcry_error_t err; unsigned int n; + if (fips_mode ()) + return gpg_error (GPG_ERR_NOT_SUPPORTED); + key_sexp = NULL; err = ac_data_construct (ac_key_identifiers[key->type], @@ -1777,6 +1824,9 @@ gcry_error_t err; unsigned char *ret; + if (fips_mode ()) + return gpg_error (GPG_ERR_NOT_SUPPORTED); + key_sexp = NULL; err = ac_data_construct (ac_key_identifiers[key->type], 0, 0, handle->algorithm_name, key->data, &key_sexp); @@ -1823,6 +1873,9 @@ gcry_sexp_t sexp_key; gcry_error_t err; + if (fips_mode ()) + return gpg_error (GPG_ERR_NOT_SUPPORTED); + data_encrypted_new = NULL; sexp_request = NULL; sexp_reply = NULL; @@ -1897,6 +1950,9 @@ gcry_sexp_t sexp_key; gcry_error_t err; + if (fips_mode ()) + return gpg_error (GPG_ERR_NOT_SUPPORTED); + sexp_request = NULL; sexp_reply = NULL; sexp_value = NULL; @@ -1969,6 +2025,9 @@ gcry_sexp_t sexp_key; gcry_error_t err; + if (fips_mode ()) + return gpg_error (GPG_ERR_NOT_SUPPORTED); + data_signed = NULL; data_value = NULL; sexp_request = NULL; @@ -2039,6 +2098,9 @@ gcry_sexp_t sexp_key; gcry_error_t err; + if (fips_mode ()) + return gpg_error (GPG_ERR_NOT_SUPPORTED); + sexp_signature = NULL; data_value = NULL; sexp_data = NULL; @@ -2509,6 +2571,9 @@ gcry_ac_io_t *ac_io_read, gcry_ac_io_t *ac_io_write) { + if (fips_mode ()) + return gpg_error (GPG_ERR_NOT_SUPPORTED); + return ac_data_dencode (method, DATA_ENCODE, flags, options, ac_io_read, ac_io_write); } @@ -2522,6 +2587,9 @@ gcry_ac_io_t *ac_io_read, gcry_ac_io_t *ac_io_write) { + if (fips_mode ()) + return gpg_error (GPG_ERR_NOT_SUPPORTED); + return ac_data_dencode (method, DATA_DECODE, flags, options, ac_io_read, ac_io_write); } @@ -2537,6 +2605,9 @@ gcry_mpi_t m; gcry_mpi_t d; + if (fips_mode ()) + return; + base = gcry_mpi_new (0); gcry_mpi_set_ui (base, 256); @@ -2575,6 +2646,9 @@ gcry_error_t err; unsigned int nbits; + if (fips_mode ()) + return gpg_error (GPG_ERR_NOT_SUPPORTED); + nbits = gcry_mpi_get_nbits (mpi); buffer_n = (nbits + 7) / 8; buffer = gcry_malloc (buffer_n); @@ -2604,6 +2678,9 @@ gcry_mpi_t x; gcry_mpi_t a; + if (fips_mode ()) + return; + a = gcry_mpi_new (0); gcry_mpi_set_ui (a, 1); x = gcry_mpi_new (0); @@ -2822,6 +2899,9 @@ (void)flags; + if (fips_mode ()) + return gpg_error (GPG_ERR_NOT_SUPPORTED); + data_encrypted = NULL; mpi_encrypted = NULL; mpi_plain = NULL; @@ -2913,6 +2993,9 @@ (void)flags; + if (fips_mode ()) + return gpg_error (GPG_ERR_NOT_SUPPORTED); + data_encrypted = NULL; mpi_encrypted = NULL; mpi_decrypted = NULL; @@ -3024,6 +3107,9 @@ (void)flags; + if (fips_mode ()) + return gpg_error (GPG_ERR_NOT_SUPPORTED); + data_signed = NULL; mpi_signed = NULL; opts_em = NULL; @@ -3116,6 +3202,9 @@ (void)flags; + if (fips_mode ()) + return gpg_error (GPG_ERR_NOT_SUPPORTED); + mpi_signature = NULL; elements_sig = NULL; data_signed = NULL; @@ -3206,5 +3295,8 @@ gcry_err_code_t _gcry_ac_init (void) { + if (fips_mode ()) + return GPG_ERR_NOT_SUPPORTED; + return 0; } Modified: trunk/cipher/cipher.c =================================================================== --- trunk/cipher/cipher.c 2008-08-04 13:16:45 UTC (rev 1294) +++ trunk/cipher/cipher.c 2008-08-19 15:55:46 UTC (rev 1295) @@ -1,6 +1,6 @@ /* cipher.c - cipher dispatcher * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 - * 2005, 2007 Free Software Foundation, Inc. + * 2005, 2007, 2008 Free Software Foundation, Inc. * * This file is part of Libgcrypt. * @@ -38,51 +38,76 @@ #define NEED_16BYTE_ALIGNED_CONTEXT 1 #endif +/* A dummy extraspec so that we do not need to tests the extraspec + field from the module specification against NULL and instead + directly test the respective fields of extraspecs. */ +static cipher_extra_spec_t dummy_extra_spec; + /* This is the list of the default ciphers, which are included in libgcrypt. */ static struct cipher_table_entry { gcry_cipher_spec_t *cipher; + cipher_extra_spec_t *extraspec; unsigned int algorithm; + int fips_allowed; } cipher_table[] = { #if USE_BLOWFISH - { &_gcry_cipher_spec_blowfish, GCRY_CIPHER_BLOWFISH }, + { &_gcry_cipher_spec_blowfish, + &dummy_extra_spec, GCRY_CIPHER_BLOWFISH }, #endif #if USE_DES - { &_gcry_cipher_spec_des, GCRY_CIPHER_DES }, - { &_gcry_cipher_spec_tripledes, GCRY_CIPHER_3DES }, + { &_gcry_cipher_spec_des, + &dummy_extra_spec, GCRY_CIPHER_DES }, + { &_gcry_cipher_spec_tripledes, + &_gcry_cipher_extraspec_tripledes, GCRY_CIPHER_3DES, 1 }, #endif #if USE_ARCFOUR - { &_gcry_cipher_spec_arcfour, GCRY_CIPHER_ARCFOUR }, + { &_gcry_cipher_spec_arcfour, + &dummy_extra_spec, GCRY_CIPHER_ARCFOUR }, #endif #if USE_CAST5 - { &_gcry_cipher_spec_cast5, GCRY_CIPHER_CAST5 }, + { &_gcry_cipher_spec_cast5, + &dummy_extra_spec, GCRY_CIPHER_CAST5 }, #endif #if USE_AES - { &_gcry_cipher_spec_aes, GCRY_CIPHER_AES}, - { &_gcry_cipher_spec_aes192, GCRY_CIPHER_AES192}, - { &_gcry_cipher_spec_aes256, GCRY_CIPHER_AES256}, + { &_gcry_cipher_spec_aes, + &_gcry_cipher_extraspec_aes, GCRY_CIPHER_AES, 1 }, + { &_gcry_cipher_spec_aes192, + &_gcry_cipher_extraspec_aes192, GCRY_CIPHER_AES192, 1 }, + { &_gcry_cipher_spec_aes256, + &_gcry_cipher_extraspec_aes256, GCRY_CIPHER_AES256, 1 }, #endif #if USE_TWOFISH - { &_gcry_cipher_spec_twofish, GCRY_CIPHER_TWOFISH }, - { &_gcry_cipher_spec_twofish128, GCRY_CIPHER_TWOFISH128 }, + { &_gcry_cipher_spec_twofish, + &dummy_extra_spec, GCRY_CIPHER_TWOFISH }, + { &_gcry_cipher_spec_twofish128, + &dummy_extra_spec, GCRY_CIPHER_TWOFISH128 }, #endif #if USE_SERPENT - { &_gcry_cipher_spec_serpent128, GCRY_CIPHER_SERPENT128 }, - { &_gcry_cipher_spec_serpent192, GCRY_CIPHER_SERPENT192 }, - { &_gcry_cipher_spec_serpent256, GCRY_CIPHER_SERPENT256 }, + { &_gcry_cipher_spec_serpent128, + &dummy_extra_spec, GCRY_CIPHER_SERPENT128 }, + { &_gcry_cipher_spec_serpent192, + &dummy_extra_spec, GCRY_CIPHER_SERPENT192 }, + { &_gcry_cipher_spec_serpent256, + &dummy_extra_spec, GCRY_CIPHER_SERPENT256 }, #endif #if USE_RFC2268 - { &_gcry_cipher_spec_rfc2268_40, GCRY_CIPHER_RFC2268_40 }, + { &_gcry_cipher_spec_rfc2268_40, + &dummy_extra_spec, GCRY_CIPHER_RFC2268_40 }, #endif #if USE_SEED - { &_gcry_cipher_spec_seed, GCRY_CIPHER_SEED }, + { &_gcry_cipher_spec_seed, + &dummy_extra_spec, GCRY_CIPHER_SEED }, #endif #if USE_CAMELLIA - { &_gcry_cipher_spec_camellia128, GCRY_CIPHER_CAMELLIA128 }, - { &_gcry_cipher_spec_camellia192, GCRY_CIPHER_CAMELLIA192 }, - { &_gcry_cipher_spec_camellia256, GCRY_CIPHER_CAMELLIA256 }, + { &_gcry_cipher_spec_camellia128, + &dummy_extra_spec, GCRY_CIPHER_CAMELLIA128 }, + { &_gcry_cipher_spec_camellia192, + &dummy_extra_spec, GCRY_CIPHER_CAMELLIA192 }, + { &_gcry_cipher_spec_camellia256, + &dummy_extra_spec, GCRY_CIPHER_CAMELLIA256 }, #endif { NULL } }; @@ -104,7 +129,7 @@ ath_mutex_lock (&ciphers_registered_lock); \ if (! default_ciphers_registered) \ { \ - gcry_cipher_register_default (); \ + cipher_register_default (); \ default_ciphers_registered = 1; \ } \ ath_mutex_unlock (&ciphers_registered_lock); \ @@ -251,7 +276,7 @@ CIPHER_TABLE. Note, that this function gets only used by the macro REGISTER_DEFAULT_CIPHERS which protects it using a mutex. */ static void From cvs at cvs.gnupg.org Tue Aug 19 18:22:32 2008 From: cvs at cvs.gnupg.org (svn author wk) Date: Tue, 19 Aug 2008 18:22:32 +0200 Subject: [svn] gcry - r1296 - trunk/cipher Message-ID: Author: wk Date: 2008-08-19 18:22:32 +0200 (Tue, 19 Aug 2008) New Revision: 1296 Added: trunk/cipher/hmac-tests.c Log: Add file From cvs at cvs.gnupg.org Tue Aug 19 18:23:42 2008 From: cvs at cvs.gnupg.org (svn author wk) Date: Tue, 19 Aug 2008 18:23:42 +0200 Subject: [svn] gcry - r1297 - trunk/src Message-ID: Author: wk Date: 2008-08-19 18:23:42 +0200 (Tue, 19 Aug 2008) New Revision: 1297 Added: trunk/src/fips.c Log: Another forgotten file. From cvs at cvs.gnupg.org Tue Aug 19 18:25:31 2008 From: cvs at cvs.gnupg.org (svn author wk) Date: Tue, 19 Aug 2008 18:25:31 +0200 Subject: [svn] gcry - r1298 - trunk/doc Message-ID: Author: wk Date: 2008-08-19 18:25:30 +0200 (Tue, 19 Aug 2008) New Revision: 1298 Added: trunk/doc/libgcrypt-modules.fig Log: Aehmm, one more. From cvs at cvs.gnupg.org Tue Aug 19 18:59:17 2008 From: cvs at cvs.gnupg.org (svn author wk) Date: Tue, 19 Aug 2008 18:59:17 +0200 Subject: [svn] gcry - r1299 - in trunk: . doc mpi src Message-ID: Author: wk Date: 2008-08-19 18:59:15 +0200 (Tue, 19 Aug 2008) New Revision: 1299 Modified: trunk/ChangeLog trunk/NEWS trunk/README trunk/TODO trunk/configure.ac trunk/doc/gcrypt.texi trunk/mpi/ChangeLog trunk/mpi/mpi-bit.c trunk/src/ChangeLog trunk/src/gcrypt.h.in trunk/src/libgcrypt.def trunk/src/libgcrypt.vers trunk/src/mpi.h trunk/src/visibility.c trunk/src/visibility.h Log: Adding gcry_mpi_lshift. Preparing a release candidate. Modified: trunk/ChangeLog =================================================================== --- trunk/ChangeLog 2008-08-19 16:25:30 UTC (rev 1298) +++ trunk/ChangeLog 2008-08-19 16:59:15 UTC (rev 1299) @@ -1,3 +1,9 @@ +2008-08-19 Werner Koch + + Release 1.4.2rc1. + + * configure.ac: Bump LT version to C16/A5/R0. + 2008-08-18 Werner Koch * Makefile.am (EXTRA_DIST): Remove the unused BUGS file. Modified: trunk/mpi/ChangeLog =================================================================== --- trunk/mpi/ChangeLog 2008-08-19 16:25:30 UTC (rev 1298) +++ trunk/mpi/ChangeLog 2008-08-19 16:59:15 UTC (rev 1299) @@ -1,3 +1,7 @@ +2008-08-19 Werner Koch + + * mpi-bit.c (gcry_mpi_lshift): New. + 2007-10-31 Werner Koch * mpi-mod.c (gcry_mpi_mod): Remove Modified: trunk/src/ChangeLog =================================================================== --- trunk/src/ChangeLog 2008-08-19 16:25:30 UTC (rev 1298) +++ trunk/src/ChangeLog 2008-08-19 16:59:15 UTC (rev 1299) @@ -1,3 +1,8 @@ +2008-08-19 Werner Koch + + * visibility.c, visibility.h (gcry_mpi_lshift): New. + * libgcrypt.vers, libgcrypt.def, gcrypt.h.in: Ditto. + 2008-08-15 Werner Koch * gcrypt.h.in (gcry_cipher_setkey): Replace macro by function. @@ -1899,7 +1904,7 @@ Copyright (C) 1998,1999,2000,2001,2002,2003 - 2004, 2005 Free Software Foundation, Inc. + 2004, 2005, 2008 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 Modified: trunk/NEWS =================================================================== --- trunk/NEWS 2008-08-19 16:25:30 UTC (rev 1298) +++ trunk/NEWS 2008-08-19 16:59:15 UTC (rev 1299) @@ -1,15 +1,20 @@ -Noteworthy changes in version 1.4.2 +Noteworthy changes in version 1.4.2 (unreleased) ------------------------------------------------ - * The library may now be switched into a FIPS mode. + * The library may now be switched into a FIPS mode. Note that this + mode is not yet fully working in 1.4.2rc1. * More runtime selftests. * A few macros have been replaced by functions for better type checking. - * The thread initialiation structure now carries version information. + * The thread initialization structure now carries version + information. + * The long missing gcry_mpi_lshift function has been added. Note + that it is not yet working in 1.4.2rc1. + * Interface changes relative to the 1.3.0 release: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ GCRYCTL_OPERATIONAL_P NEW. @@ -18,6 +23,7 @@ gcry_cipher_setkey NEW: Replaces macro. gcry_cipher_setiv NEW: Replaces macro. gcry_cipher_setctr NEW: Replaces macro. + gcry_mpi_lshift NEW. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Modified: trunk/README =================================================================== --- trunk/README 2008-08-19 16:25:30 UTC (rev 1298) +++ trunk/README 2008-08-19 16:59:15 UTC (rev 1299) @@ -1,6 +1,8 @@ libgcrypt - The GNU crypto library ------------------------------------ - Version 1.4.1 + Version 1.4.2rc1 + + *** Warning: RELEASE CANDIDATE *** Copyright 2000, 2002, 2003, 2004, 2007, 2008 Free Software Foundation, Inc. Modified: trunk/TODO =================================================================== --- trunk/TODO 2008-08-19 16:25:30 UTC (rev 1298) +++ trunk/TODO 2008-08-19 16:59:15 UTC (rev 1299) @@ -84,8 +84,6 @@ * mpi_print does not use secure memory for internal variables. -* gcry_mpi_lshift is missing - * Add OAEP * gcryptrnd.c @@ -110,4 +108,5 @@ We have some code to allow using libgcrypt from C++, so we also should have a test case. -* Use aliases for symbol instead of the wrappers in visibility.c. +* gcry_mpi_lshift needs actual code. + Modified: trunk/configure.ac =================================================================== --- trunk/configure.ac 2008-08-19 16:25:30 UTC (rev 1298) +++ trunk/configure.ac 2008-08-19 16:59:15 UTC (rev 1299) @@ -26,8 +26,8 @@ # Remember to change the version number immediately *after* a release. # Set my_issvn to "yes" for non-released code. Remember to run an # "svn up" and "autogen.sh" right before creating a distribution. -m4_define([my_version], [1.4.2]) -m4_define([my_issvn], [yes]) +m4_define([my_version], [1.4.2rc1]) +m4_define([my_issvn], [no]) m4_define([svn_revision], m4_esyscmd([echo -n $( (svn info 2>/dev/null \ || echo 'Revision: 0')|sed -n '/^Revision:/ {s/[^0-9]//gp;q;}')])) @@ -38,9 +38,9 @@ # (Interfaces removed: CURRENT++, AGE=0, REVISION=0) # (Interfaces added: CURRENT++, AGE++, REVISION=0) # (No interfaces changed: REVISION++) -LIBGCRYPT_LT_CURRENT=15 -LIBGCRYPT_LT_AGE=4 -LIBGCRYPT_LT_REVISION=4 +LIBGCRYPT_LT_CURRENT=16 +LIBGCRYPT_LT_AGE=5 +LIBGCRYPT_LT_REVISION=0 # If the API is changed in an incompatible way: increment the next counter. Modified: trunk/doc/gcrypt.texi =================================================================== --- trunk/doc/gcrypt.texi 2008-08-19 16:25:30 UTC (rev 1298) +++ trunk/doc/gcrypt.texi 2008-08-19 16:59:15 UTC (rev 1299) @@ -67,7 +67,7 @@ * Handler Functions:: Working with handler functions. * Symmetric cryptography:: How to use symmetric cryptography. * Public Key cryptography:: How to use public key cryptography. -* Hashing:: How to use hashing. +* Hashing:: How to use hash and MAC algorithms. * Random Numbers:: How to work with random numbers. * S-expressions:: How to manage S-expressions. * MPI library:: How to work with multi-precision-integers. @@ -102,6 +102,7 @@ @c ********************************************************** @node Introduction @chapter Introduction + Libgcrypt is a library providing cryptographic building blocks. @menu @@ -3200,12 +3201,11 @@ @node Hashing @chapter Hashing -Libgcrypt provides an easy and consistent to use interface -for hashing. Hashing is buffered and several hash algorithms can be -updated at once. It is possible to calculate a MAC using the same -routines. The programming model follows an open/process/close -paradigm and is in that similar to other building blocks provided by -Libgcrypt. +Libgcrypt provides an easy and consistent to use interface for hashing. +Hashing is buffered and several hash algorithms can be updated at once. +It is possible to compute a MAC using the same routines. The +programming model follows an open/process/close paradigm and is in that +similar to other building blocks provided by Libgcrypt. For convenience reasons, a few cyclic redundancy check value operations are also supported. Modified: trunk/mpi/mpi-bit.c =================================================================== --- trunk/mpi/mpi-bit.c 2008-08-19 16:25:30 UTC (rev 1298) +++ trunk/mpi/mpi-bit.c 2008-08-19 16:59:15 UTC (rev 1299) @@ -297,6 +297,16 @@ } +/* + * Shift A by N bits to the left. + */ +void +gcry_mpi_lshift ( gcry_mpi_t x, gcry_mpi_t a, unsigned int n ) +{ + BUG (); /* Not yet implemented in 1.4.2rc1 but will be soon. */ +} + + /**************** * Shift A by COUNT limbs to the right * This is used only within the MPI library Modified: trunk/src/gcrypt.h.in =================================================================== --- trunk/src/gcrypt.h.in 2008-08-19 16:25:30 UTC (rev 1298) +++ trunk/src/gcrypt.h.in 2008-08-19 16:59:15 UTC (rev 1299) @@ -708,6 +708,9 @@ /* Shift the value of A by N bits to the right and store the result in X. */ void gcry_mpi_rshift (gcry_mpi_t x, gcry_mpi_t a, unsigned int n); +/* Shift the value of A by N bits to the left and store the result in X. */ +void gcry_mpi_lshift (gcry_mpi_t x, gcry_mpi_t a, unsigned int n); + /* Store NBITS of the value P points to in A and mark A as an opaque value. WARNING: Never use an opaque MPI for anything thing else then gcry_mpi_release, gcry_mpi_get_opaque. */ @@ -773,6 +776,7 @@ #define mpi_clear_bit(a,b) gcry_mpi_clear_bit ((a),(b)) #define mpi_clear_highbit(a,b) gcry_mpi_clear_highbit ((a),(b)) #define mpi_rshift(a,b,c) gcry_mpi_rshift ((a),(b),(c)) +#define mpi_lshift(a,b,c) gcry_mpi_lshift ((a),(b),(c)) #define mpi_set_opaque(a,b,c) gcry_mpi_set_opaque( (a), (b), (c) ) #define mpi_get_opaque(a,b) gcry_mpi_get_opaque( (a), (b) ) Modified: trunk/src/libgcrypt.def =================================================================== --- trunk/src/libgcrypt.def 2008-08-19 16:25:30 UTC (rev 1298) +++ trunk/src/libgcrypt.def 2008-08-19 16:59:15 UTC (rev 1299) @@ -230,6 +230,8 @@ gcry_cipher_setkey @188 gcry_cipher_setiv @189 gcry_cipher_setctr @190 + + gcry_mpi_lshift @191 + - Modified: trunk/src/libgcrypt.vers =================================================================== --- trunk/src/libgcrypt.vers 2008-08-19 16:25:30 UTC (rev 1298) +++ trunk/src/libgcrypt.vers 2008-08-19 16:59:15 UTC (rev 1299) @@ -100,6 +100,7 @@ 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; local: *; Modified: trunk/src/mpi.h =================================================================== --- trunk/src/mpi.h 2008-08-19 16:25:30 UTC (rev 1298) +++ trunk/src/mpi.h 2008-08-19 16:59:15 UTC (rev 1299) @@ -219,6 +219,7 @@ #define mpi_clear_bit(a,b) gcry_mpi_clear_bit ((a),(b)) #define mpi_clear_highbit(a,b) gcry_mpi_clear_highbit ((a),(b)) #define mpi_rshift(a,b,c) gcry_mpi_rshift ((a),(b),(c)) +#define mpi_lshift(a,b,c) gcry_mpi_lshift ((a),(b),(c)) void _gcry_mpi_normalize( gcry_mpi_t a ); Modified: trunk/src/visibility.c =================================================================== --- trunk/src/visibility.c 2008-08-19 16:25:30 UTC (rev 1298) +++ trunk/src/visibility.c 2008-08-19 16:59:15 UTC (rev 1299) @@ -457,6 +457,12 @@ _gcry_mpi_rshift (x, a, n); } +void +gcry_mpi_lshift (gcry_mpi_t x, gcry_mpi_t a, unsigned int n) +{ + _gcry_mpi_lshift (x, a, n); +} + gcry_mpi_t gcry_mpi_set_opaque (gcry_mpi_t a, void *p, unsigned int nbits) { Modified: trunk/src/visibility.h =================================================================== --- trunk/src/visibility.h 2008-08-19 16:25:30 UTC (rev 1298) +++ trunk/src/visibility.h 2008-08-19 16:59:15 UTC (rev 1299) @@ -214,6 +214,7 @@ #define gcry_mpi_randomize _gcry_mpi_randomize #define gcry_mpi_release _gcry_mpi_release #define gcry_mpi_rshift _gcry_mpi_rshift +#define gcry_mpi_lshift _gcry_mpi_lshift #define gcry_mpi_scan _gcry_mpi_scan #define gcry_mpi_set _gcry_mpi_set #define gcry_mpi_set_bit _gcry_mpi_set_bit @@ -468,6 +469,7 @@ #undef gcry_mpi_randomize #undef gcry_mpi_release #undef gcry_mpi_rshift +#undef gcry_mpi_lshift #undef gcry_mpi_scan #undef gcry_mpi_set #undef gcry_mpi_set_bit @@ -679,6 +681,7 @@ MARK_VISIBLE (gcry_mpi_randomize) MARK_VISIBLE (gcry_mpi_release) MARK_VISIBLE (gcry_mpi_rshift) +MARK_VISIBLE (gcry_mpi_lshift) MARK_VISIBLE (gcry_mpi_scan) MARK_VISIBLE (gcry_mpi_set) MARK_VISIBLE (gcry_mpi_set_bit) From cvs at cvs.gnupg.org Tue Aug 19 19:33:07 2008 From: cvs at cvs.gnupg.org (svn author wk) Date: Tue, 19 Aug 2008 19:33:07 +0200 Subject: [svn] gcry - r1300 - tags Message-ID: Author: wk Date: 2008-08-19 19:33:06 +0200 (Tue, 19 Aug 2008) New Revision: 1300 Added: tags/libgcrypt-1.4.2rc1/ Log: A tag in the evening. From cvs at cvs.gnupg.org Tue Aug 19 21:36:05 2008 From: cvs at cvs.gnupg.org (svn author wk) Date: Tue, 19 Aug 2008 21:36:05 +0200 Subject: [svn] GnuPG - r4815 - branches/STABLE-BRANCH-1-4/util Message-ID: Author: wk Date: 2008-08-19 21:36:04 +0200 (Tue, 19 Aug 2008) New Revision: 4815 Modified: branches/STABLE-BRANCH-1-4/util/ChangeLog branches/STABLE-BRANCH-1-4/util/iobuf.c Log: Fix possible NULL argument to printf Modified: branches/STABLE-BRANCH-1-4/util/ChangeLog =================================================================== --- branches/STABLE-BRANCH-1-4/util/ChangeLog 2008-08-18 11:08:04 UTC (rev 4814) +++ branches/STABLE-BRANCH-1-4/util/ChangeLog 2008-08-19 19:36:04 UTC (rev 4815) @@ -1,3 +1,9 @@ +2008-08-19 Werner Koch + + * iobuf.c: Avoid passing a NULL (iobuf_t)->desc to the log + function. Should in general never be NULL, but well. Reported by + M. Heneka. + 2008-03-06 David Shaw * argparse.c (default_strusage): Update copyright date. Modified: branches/STABLE-BRANCH-1-4/util/iobuf.c =================================================================== --- branches/STABLE-BRANCH-1-4/util/iobuf.c 2008-08-18 11:08:04 UTC (rev 4814) +++ branches/STABLE-BRANCH-1-4/util/iobuf.c 2008-08-19 19:36:04 UTC (rev 4815) @@ -1,6 +1,6 @@ /* iobuf.c - file handling * Copyright (C) 1998, 1999, 2000, 2001, 2003, - * 2004 Free Software Foundation, Inc. + * 2004, 2008 Free Software Foundation, Inc. * * This file is part of GnuPG. * @@ -883,7 +883,7 @@ (byte*)&desc, &dummy_len ); log_debug("iobuf chain: %d.%d `%s' filter_eof=%d start=%d len=%d\n", - a->no, a->subno, desc, a->filter_eof, + a->no, a->subno, desc?desc:"?", a->filter_eof, (int)a->d.start, (int)a->d.len ); } } @@ -938,7 +938,8 @@ log_error("iobuf_flush failed on close: %s\n", g10_errstr(rc)); if( DBG_IOBUF ) - log_debug("iobuf-%d.%d: close `%s'\n", a->no, a->subno, a->desc ); + log_debug("iobuf-%d.%d: close `%s'\n", a->no, a->subno, + a->desc?a->desc:"?"); if( a->filter && (rc = a->filter(a->filter_ov, IOBUFCTRL_FREE, a->chain, NULL, &dummy_len)) ) log_error("IOBUFCTRL_FREE failed on close: %s\n", g10_errstr(rc) ); @@ -1199,7 +1200,8 @@ file_filter( fcx, IOBUFCTRL_DESC, NULL, (byte*)&a->desc, &len ); file_filter( fcx, IOBUFCTRL_INIT, NULL, NULL, &len ); if( DBG_IOBUF ) - log_debug("iobuf-%d.%d: create `%s'\n", a->no, a->subno, a->desc ); + log_debug("iobuf-%d.%d: create `%s'\n", a->no, a->subno, + a->desc?a->desc:"?" ); return a; } @@ -1232,7 +1234,8 @@ file_filter( fcx, IOBUFCTRL_DESC, NULL, (byte*)&a->desc, &len ); file_filter( fcx, IOBUFCTRL_INIT, NULL, NULL, &len ); if( DBG_IOBUF ) - log_debug("iobuf-%d.%d: append `%s'\n", a->no, a->subno, a->desc ); + log_debug("iobuf-%d.%d: append `%s'\n", a->no, a->subno, + a->desc?a->desc:"?" ); return a; } @@ -1260,7 +1263,8 @@ file_filter( fcx, IOBUFCTRL_DESC, NULL, (byte*)&a->desc, &len ); file_filter( fcx, IOBUFCTRL_INIT, NULL, NULL, &len ); if( DBG_IOBUF ) - log_debug("iobuf-%d.%d: openrw `%s'\n", a->no, a->subno, a->desc ); + log_debug("iobuf-%d.%d: openrw `%s'\n", a->no, a->subno, + a->desc?a->desc:"?"); return a; } @@ -1272,7 +1276,8 @@ if ( cmd == 1 ) { /* keep system filepointer/descriptor open */ if( DBG_IOBUF ) log_debug("iobuf-%d.%d: ioctl `%s' keep=%d\n", - a? a->no:-1, a?a->subno:-1, a?a->desc:"?", intval ); + a? a->no:-1, a?a->subno:-1, + a&&a->desc?a->desc:"?", intval ); for( ; a; a = a->chain ) if( !a->chain && a->filter == file_filter ) { file_filter_ctx_t *b = a->filter_ov; @@ -1301,7 +1306,8 @@ else if ( cmd == 3 ) { /* disallow/allow caching */ if( DBG_IOBUF ) log_debug("iobuf-%d.%d: ioctl `%s' no_cache=%d\n", - a? a->no:-1, a?a->subno:-1, a?a->desc:"?", intval ); + a? a->no:-1, a?a->subno:-1, + a&&a->desc?a->desc:"?", intval ); for( ; a; a = a->chain ) if( !a->chain && a->filter == file_filter ) { file_filter_ctx_t *b = a->filter_ov; @@ -1393,7 +1399,8 @@ f( ov, IOBUFCTRL_DESC, NULL, (byte*)&a->desc, &dummy_len ); if( DBG_IOBUF ) { - log_debug("iobuf-%d.%d: push `%s'\n", a->no, a->subno, a->desc ); + log_debug("iobuf-%d.%d: push `%s'\n", a->no, a->subno, + a->desc?a->desc:"?" ); print_chain( a ); } @@ -1419,7 +1426,8 @@ BUG(); if( DBG_IOBUF ) - log_debug("iobuf-%d.%d: pop `%s'\n", a->no, a->subno, a->desc ); + log_debug("iobuf-%d.%d: pop `%s'\n", a->no, a->subno, + a->desc?a->desc:"?" ); if( !a->filter ) { /* this is simple */ b = a->chain; assert(b); @@ -1497,7 +1505,7 @@ IOBUF b = a->chain; if( DBG_IOBUF ) log_debug("iobuf-%d.%d: pop `%s' in underflow\n", - a->no, a->subno, a->desc ); + a->no, a->subno, a->desc?a->desc:"?" ); xfree(a->d.buf); xfree(a->real_fname); memcpy(a, b, sizeof *a); @@ -1562,8 +1570,8 @@ if( !len && a->chain ) { IOBUF b = a->chain; if( DBG_IOBUF ) - log_debug("iobuf-%d.%d: pop `%s' in underflow (!len)\n", - a->no, a->subno, a->desc ); + log_debug("iobuf-%d.%d: pop in underflow (!len)\n", + a->no, a->subno); xfree(a->d.buf); xfree(a->real_fname); memcpy(a,b, sizeof *a); From cvs at cvs.gnupg.org Tue Aug 19 21:36:43 2008 From: cvs at cvs.gnupg.org (svn author wk) Date: Tue, 19 Aug 2008 21:36:43 +0200 Subject: [svn] GnuPG - r4816 - trunk/common Message-ID: Author: wk Date: 2008-08-19 21:36:42 +0200 (Tue, 19 Aug 2008) New Revision: 4816 Modified: trunk/common/ChangeLog trunk/common/iobuf.c Log: Avoid passing NULL to printf while debugging. Modified: trunk/common/ChangeLog =================================================================== --- trunk/common/ChangeLog 2008-08-19 19:36:04 UTC (rev 4815) +++ trunk/common/ChangeLog 2008-08-19 19:36:42 UTC (rev 4816) @@ -1,3 +1,9 @@ +2008-08-19 Werner Koch + + * iobuf.c: Avoid passing a NULL (iobuf_t)->desc to the log + function. Should in general never be NULL, but well. Reported by + M. Heneka. + 2008-06-26 Werner Koch * estream.c (es_write_sanitized): Loose check for control Modified: trunk/common/iobuf.c =================================================================== --- trunk/common/iobuf.c 2008-08-19 19:36:04 UTC (rev 4815) +++ trunk/common/iobuf.c 2008-08-19 19:36:42 UTC (rev 4816) @@ -1,6 +1,6 @@ /* iobuf.c - File Handling for OpenPGP. * Copyright (C) 1998, 1999, 2000, 2001, 2003, 2004, 2006, - * 2007 Free Software Foundation, Inc. + * 2007, 2008 Free Software Foundation, Inc. * * This file is part of GnuPG. * @@ -78,7 +78,7 @@ we are using the low-evel backend. fp_or_fd_t - Is the type we use for the backend stream or fiel descriptor. + Is the type we use for the backend stream or file descriptor. INVALID_FP, FILEP_OR_FD_FOR_STDIN, FILEP_OR_FD_FOR_STDOUT Are macros defined depending on the used backend. @@ -1012,7 +1012,7 @@ (byte *) & desc, &dummy_len); log_debug ("iobuf chain: %d.%d `%s' filter_eof=%d start=%d len=%d\n", - a->no, a->subno, desc, a->filter_eof, + a->no, a->subno, desc?desc:"?", a->filter_eof, (int) a->d.start, (int) a->d.len); } } @@ -1069,7 +1069,8 @@ log_error ("iobuf_flush failed on close: %s\n", gpg_strerror (rc)); if (DBG_IOBUF) - log_debug ("iobuf-%d.%d: close `%s'\n", a->no, a->subno, a->desc); + log_debug ("iobuf-%d.%d: close `%s'\n", a->no, a->subno, + a->desc?a->desc:"?"); if (a->filter && (rc = a->filter (a->filter_ov, IOBUFCTRL_FREE, a->chain, NULL, &dummy_len))) log_error ("IOBUFCTRL_FREE failed on close: %s\n", gpg_strerror (rc)); @@ -1336,7 +1337,8 @@ file_filter (fcx, IOBUFCTRL_DESC, NULL, (byte *) & a->desc, &len); file_filter (fcx, IOBUFCTRL_INIT, NULL, NULL, &len); if (DBG_IOBUF) - log_debug ("iobuf-%d.%d: create `%s'\n", a->no, a->subno, a->desc); + log_debug ("iobuf-%d.%d: create `%s'\n", a->no, a->subno, + a->desc?a->desc:"?"); return a; } @@ -1369,7 +1371,8 @@ file_filter (fcx, IOBUFCTRL_DESC, NULL, (byte *) & a->desc, &len); file_filter (fcx, IOBUFCTRL_INIT, NULL, NULL, &len); if (DBG_IOBUF) - log_debug ("iobuf-%d.%d: append `%s'\n", a->no, a->subno, a->desc); + log_debug ("iobuf-%d.%d: append `%s'\n", a->no, a->subno, + a->desc?a->desc:"?"); return a; } @@ -1397,7 +1400,8 @@ file_filter (fcx, IOBUFCTRL_DESC, NULL, (byte *) & a->desc, &len); file_filter (fcx, IOBUFCTRL_INIT, NULL, NULL, &len); if (DBG_IOBUF) - log_debug ("iobuf-%d.%d: openrw `%s'\n", a->no, a->subno, a->desc); + log_debug ("iobuf-%d.%d: openrw `%s'\n", a->no, a->subno, + a->desc?a->desc:"?"); return a; } @@ -1410,7 +1414,8 @@ { /* keep system filepointer/descriptor open */ if (DBG_IOBUF) log_debug ("iobuf-%d.%d: ioctl `%s' keep=%d\n", - a ? a->no : -1, a ? a->subno : -1, a ? a->desc : "?", + a ? a->no : -1, a ? a->subno : -1, + a && a->desc ? a->desc : "?", intval); for (; a; a = a->chain) if (!a->chain && a->filter == file_filter) @@ -1445,7 +1450,8 @@ { /* disallow/allow caching */ if (DBG_IOBUF) log_debug ("iobuf-%d.%d: ioctl `%s' no_cache=%d\n", - a ? a->no : -1, a ? a->subno : -1, a ? a->desc : "?", + a ? a->no : -1, a ? a->subno : -1, + a && a->desc? a->desc : "?", intval); for (; a; a = a->chain) if (!a->chain && a->filter == file_filter) @@ -1546,7 +1552,8 @@ if (DBG_IOBUF) { - log_debug ("iobuf-%d.%d: push `%s'\n", a->no, a->subno, a->desc); + log_debug ("iobuf-%d.%d: push `%s'\n", a->no, a->subno, + a->desc?a->desc:"?"); print_chain (a); } @@ -1573,7 +1580,8 @@ BUG (); if (DBG_IOBUF) - log_debug ("iobuf-%d.%d: pop `%s'\n", a->no, a->subno, a->desc); + log_debug ("iobuf-%d.%d: pop `%s'\n", a->no, a->subno, + a->desc?a->desc:"?"); if (!a->filter) { /* this is simple */ b = a->chain; @@ -1660,7 +1668,7 @@ iobuf_t b = a->chain; if (DBG_IOBUF) log_debug ("iobuf-%d.%d: pop `%s' in underflow\n", - a->no, a->subno, a->desc); + a->no, a->subno, a->desc?a->desc:"?"); xfree (a->d.buf); xfree (a->real_fname); memcpy (a, b, sizeof *a); @@ -1733,8 +1741,8 @@ { iobuf_t b = a->chain; if (DBG_IOBUF) - log_debug ("iobuf-%d.%d: pop `%s' in underflow (!len)\n", - a->no, a->subno, a->desc); + log_debug ("iobuf-%d.%d: pop in underflow (!len)\n", + a->no, a->subno); xfree (a->d.buf); xfree (a->real_fname); memcpy (a, b, sizeof *a); From cvs at cvs.gnupg.org Wed Aug 20 16:10:12 2008 From: cvs at cvs.gnupg.org (svn author wk) Date: Wed, 20 Aug 2008 16:10:12 +0200 Subject: [svn] gcry - r1301 - in trunk: . doc mpi src tests Message-ID: Author: wk Date: 2008-08-20 16:10:11 +0200 (Wed, 20 Aug 2008) New Revision: 1301 Modified: trunk/NEWS trunk/configure.ac trunk/doc/gcrypt.texi trunk/mpi/ChangeLog trunk/mpi/mpi-bit.c trunk/src/gcrypt.h.in trunk/tests/ChangeLog trunk/tests/t-mpi-bit.c Log: Implemented gcry_mpi_lshift. Reordered some code in mpi-bit.c Modified: trunk/mpi/ChangeLog =================================================================== --- trunk/mpi/ChangeLog 2008-08-19 17:33:06 UTC (rev 1300) +++ trunk/mpi/ChangeLog 2008-08-20 14:10:11 UTC (rev 1301) @@ -1,3 +1,7 @@ +2008-08-20 Werner Koch + + * mpi-bit.c (gcry_mpi_lshift): Actually implement. + 2008-08-19 Werner Koch * mpi-bit.c (gcry_mpi_lshift): New. Modified: trunk/tests/ChangeLog =================================================================== --- trunk/tests/ChangeLog 2008-08-19 17:33:06 UTC (rev 1300) +++ trunk/tests/ChangeLog 2008-08-20 14:10:11 UTC (rev 1301) @@ -1,3 +1,9 @@ +2008-08-20 Werner Koch + + * t-mpi-bit.c (test_lshift): New. + (mpi2bitstr_nlz, lshiftbitstring): New. + (main): Run test. + 2008-08-18 Werner Koch * basic.c (main): Add option --fips. Modified: trunk/NEWS =================================================================== --- trunk/NEWS 2008-08-19 17:33:06 UTC (rev 1300) +++ trunk/NEWS 2008-08-20 14:10:11 UTC (rev 1301) @@ -12,8 +12,7 @@ * The thread initialization structure now carries version information. - * The long missing gcry_mpi_lshift function has been added. Note - that it is not yet working in 1.4.2rc1. + * The long missing gcry_mpi_lshift function has been added. * Interface changes relative to the 1.3.0 release: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Modified: trunk/configure.ac =================================================================== --- trunk/configure.ac 2008-08-19 17:33:06 UTC (rev 1300) +++ trunk/configure.ac 2008-08-20 14:10:11 UTC (rev 1301) @@ -26,8 +26,8 @@ # Remember to change the version number immediately *after* a release. # Set my_issvn to "yes" for non-released code. Remember to run an # "svn up" and "autogen.sh" right before creating a distribution. -m4_define([my_version], [1.4.2rc1]) -m4_define([my_issvn], [no]) +m4_define([my_version], [1.4.2]) +m4_define([my_issvn], [yes]) m4_define([svn_revision], m4_esyscmd([echo -n $( (svn info 2>/dev/null \ || echo 'Revision: 0')|sed -n '/^Revision:/ {s/[^0-9]//gp;q;}')])) Modified: trunk/doc/gcrypt.texi =================================================================== --- trunk/doc/gcrypt.texi 2008-08-19 17:33:06 UTC (rev 1300) +++ trunk/doc/gcrypt.texi 2008-08-20 14:10:11 UTC (rev 1301) @@ -3700,8 +3700,9 @@ @table @code @item GCRY_WEAK_RANDOM -This should not anymore be used. It has recently been changed to an -alias of GCRY_STRONG_RANDOM. Use @code{gcry_create_nonce} instead. +For all functions, except for @code{gcry_mpi_randomize}, this level maps +to GCRY_STRONG_RANDOM. IF you do not want this, consider using + at code{gcry_create_nonce}. @item GCRY_STRONG_RANDOM Use this level for e.g. session keys and similar purposes. @item GCRY_VERY_STRONG_RANDOM @@ -4368,7 +4369,9 @@ Set the multi-precision-integers @var{w} to a random value of @var{nbits}, using random data quality of level @var{level}. In case @var{nbits} is not a multiple of a byte, @var{nbits} is rounded up to -the next byte boundary. +the next byte boundary. When using a @var{level} of + at code{GCRY_WEAK_RANDOM} this function makes use of + at code{gcry_create_nonce}. @end deftypefun @c ********************************************************** Modified: trunk/mpi/mpi-bit.c =================================================================== --- trunk/mpi/mpi-bit.c 2008-08-19 17:33:06 UTC (rev 1300) +++ trunk/mpi/mpi-bit.c 2008-08-20 14:10:11 UTC (rev 1301) @@ -188,6 +188,29 @@ } +/**************** + * Shift A by COUNT limbs to the right + * This is used only within the MPI library + */ +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; + + 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; +} + + /* * Shift A by N bits to the right. */ @@ -277,23 +300,23 @@ * This is used only within the MPI library */ void -_gcry_mpi_lshift_limbs( gcry_mpi_t a, unsigned int count ) +_gcry_mpi_lshift_limbs (gcry_mpi_t a, unsigned int count) { - mpi_ptr_t ap; - int n = a->nlimbs; - int i; + mpi_ptr_t ap; + int n = a->nlimbs; + int i; - if( !count || !n ) - return; + if (!count || !n) + return; - RESIZE_IF_NEEDED( a, n+count ); + RESIZE_IF_NEEDED (a, n+count); - ap = a->d; - for( i = n-1; i >= 0; i-- ) - ap[i+count] = ap[i]; - for(i=0; i < count; i++ ) - ap[i] = 0; - a->nlimbs += count; + ap = a->d; + for (i = n-1; i >= 0; i--) + ap[i+count] = ap[i]; + for (i=0; i < count; i++ ) + ap[i] = 0; + a->nlimbs += count; } @@ -303,28 +326,41 @@ void gcry_mpi_lshift ( gcry_mpi_t x, gcry_mpi_t a, unsigned int n ) { - BUG (); /* Not yet implemented in 1.4.2rc1 but will be soon. */ -} + unsigned int nlimbs = (n/BITS_PER_MPI_LIMB); + unsigned int nbits = (n%BITS_PER_MPI_LIMB); + if (x == a && !n) + return; /* In-place shift with an amount of zero. */ -/**************** - * Shift A by COUNT limbs to the right - * This is used only within the MPI library - */ -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; + if ( x != a ) + { + /* Copy A to X. */ + unsigned int alimbs = a->nlimbs; + int asign = a->sign; + mpi_ptr_t xp, ap; - if( count >= n ) { - a->nlimbs = 0; - return; + RESIZE_IF_NEEDED (x, alimbs+nlimbs+1); + xp = x->d; + ap = a->d; + MPN_COPY (xp, ap, alimbs); + x->nlimbs = alimbs; + x->flags = a->flags; + x->sign = asign; } - for( i = 0; i < n - count; i++ ) - ap[i] = ap[i+count]; - ap[i] = 0; - a->nlimbs -= count; + if (nlimbs && !nbits) + { + /* Shift a full number of limbs. */ + _gcry_mpi_lshift_limbs (x, nlimbs); + } + else if (n) + { + /* We use a very dump approach: Shift left by the number of + limbs plus one and than fix it up by an rshift. */ + _gcry_mpi_lshift_limbs (x, nlimbs+1); + gcry_mpi_rshift (x, x, BITS_PER_MPI_LIMB - nbits); + } + + MPN_NORMALIZE (x->d, x->nlimbs); } + Modified: trunk/src/gcrypt.h.in =================================================================== --- trunk/src/gcrypt.h.in 2008-08-19 17:33:06 UTC (rev 1300) +++ trunk/src/gcrypt.h.in 2008-08-20 14:10:11 UTC (rev 1301) @@ -1612,8 +1612,8 @@ /* The possible values for the random quality. The rule of thumb is to use STRONG for session keys and VERY_STRONG for key material. - WEAK is currently an alias for STRONG and should not be used - anymore - use gcry_create_nonce instead. */ + WEAK is usually an alias for STRONG and should not be used anymore + (except with gcry_mpi_randomize); use gcry_create_nonce instead. */ typedef enum gcry_random_level { GCRY_WEAK_RANDOM = 0, @@ -1652,7 +1652,8 @@ /* Set the big integer W to a random value of NBITS using a random - generator with quality LEVEL. */ + generator with quality LEVEL. Note that using a level of + GCRY_WEAK_RANDOM here, uses gcry_create_nonce internally. */ void gcry_mpi_randomize (gcry_mpi_t w, unsigned int nbits, enum gcry_random_level level); Modified: trunk/tests/t-mpi-bit.c =================================================================== --- trunk/tests/t-mpi-bit.c 2008-08-19 17:33:06 UTC (rev 1300) +++ trunk/tests/t-mpi-bit.c 2008-08-20 14:10:11 UTC (rev 1301) @@ -100,6 +100,24 @@ return buf; } +/* Allocate a bit string consisting of '0' and '1' from the MPI A. Do + not return any leading zero bits. Caller needs to xfree the + result. */ +static char * +mpi2bitstr_nlz (gcry_mpi_t a) +{ + char *p, *buf; + size_t length = gcry_mpi_get_nbits (a); + + buf = p = xmalloc (length + 1); + while (length-- > 1) + *p++ = gcry_mpi_test_bit (a, length) ? '1':'0'; + *p++ = gcry_mpi_test_bit (a, 0) ? '1':'0'; + *p = 0; + + return buf; +} + /* Shift a bit string to the right. */ static void rshiftbitstring (char *string, size_t n) @@ -113,7 +131,29 @@ memset (string, '0', n); } +/* Shift a bit string to the left. Caller needs to free the result. */ +static char * +lshiftbitstring (const char *string, size_t n) +{ + size_t len = strlen (string); + char *result; + if (len+n+1 < len) + die ("internal overflow\n"); + /* Allocate enough space. */ + result = xmalloc (len+n+1); + for (; *string == '0' && string[1]; string++, len--) + ; + memcpy (result, string, len); + if (*string == '0' && !string[1]) + n = 0; /* Avoid extra nulls for an only 0 string. */ + else + memset (result+len, '0', n); + result[len+n] = 0; + return result; +} + + /* This is to check a bug reported by bpgcrypt at itaparica.org on 2006-07-31 against libgcrypt 1.2.2. */ static void @@ -141,7 +181,6 @@ fail ("failed to clear a bit\n"); result = mpi2bitstr (a, 70); assert (strlen (result) == 70); - show ("r=%s\n", result); for (i=0; result[i]; i++) if ( result[i] != '0' ) break; @@ -210,7 +249,77 @@ gcry_mpi_release (a); } +/* Check that the left shifting. */ +static void +test_lshift (int pass) +{ + static int size_list[] = {1, 31, 32, 63, 64, 65, 70, 0}; + int size_idx; + gcry_mpi_t a, b; + char *tmpstr, *result, *result2; + int i; + wherestr = "test_lshift"; + show ("checking that lshift works as expected (pass %d)\n", pass); + + for (size_idx=0; size_list[size_idx]; size_idx++) + { + a = gcry_mpi_new (0); + b = gcry_mpi_new (0); + + /* gcry_mpi_randomize rounds up to full bytes, thus we need to + use gcry_mpi_clear_highbit to fix that. */ + gcry_mpi_randomize (a, size_list[size_idx], GCRY_WEAK_RANDOM); + gcry_mpi_clear_highbit (a, size_list[size_idx]); + + for (i=0; i < 75; i++) + { + gcry_mpi_lshift (b, a, i); + + result = mpi2bitstr_nlz (b); + tmpstr = mpi2bitstr_nlz (a); + result2 = lshiftbitstring (tmpstr, i); + xfree (tmpstr); + if (strcmp (result, result2)) + { + show ("got =%s\n", result); + show ("want=%s\n", result2); + fail ("lshift by %d failed\n", i); + } + xfree (result); + xfree (result2); + } + + /* Again. This time using in-place operation. */ + gcry_mpi_randomize (a, size_list[size_idx], GCRY_WEAK_RANDOM); + gcry_mpi_clear_highbit (a, size_list[size_idx]); + + for (i=0; i < 75; i++) + { + gcry_mpi_release (b); + b = gcry_mpi_copy (a); + gcry_mpi_lshift (b, b, i); + + result = mpi2bitstr_nlz (b); + tmpstr = mpi2bitstr_nlz (a); + result2 = lshiftbitstring (tmpstr, i); + xfree (tmpstr); + if (strcmp (result, result2)) + { + show ("got =%s\n", result); + show ("want=%s\n", result2); + fail ("in-place lshift by %d failed\n", i); + } + xfree (result2); + xfree (result); + } + + gcry_mpi_release (b); + gcry_mpi_release (a); + } +} + + int main (int argc, char **argv) { @@ -226,15 +335,19 @@ die ("version mismatch\n"); gcry_control (GCRYCTL_DISABLE_SECMEM, 0); - gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0); + gcry_control (GCRYCTL_ENABLE_QUICK_RANDOM, 0); if (debug) gcry_control (GCRYCTL_SET_DEBUG_FLAGS, 1u, 0); - gcry_control (GCRYCTL_ENABLE_QUICK_RANDOM, 0); + gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0); + one_bit_only (0); one_bit_only (1); for (i=0; i < 5; i++) test_rshift (i); /* Run several times due to random initializations. */ + + for (i=0; i < 5; i++) + test_lshift (i); /* Run several times due to random initializations. */ show ("All tests completed. Errors: %d\n", error_count); return error_count ? 1 : 0; From cvs at cvs.gnupg.org Wed Aug 20 19:59:45 2008 From: cvs at cvs.gnupg.org (svn author wk) Date: Wed, 20 Aug 2008 19:59:45 +0200 Subject: [svn] gcry - r1302 - in trunk: cipher mpi random src Message-ID: Author: wk Date: 2008-08-20 19:59:42 +0200 (Wed, 20 Aug 2008) New Revision: 1302 Modified: trunk/cipher/ac.c trunk/cipher/dsa.c trunk/cipher/ecc.c trunk/cipher/md.c trunk/cipher/primegen.c trunk/cipher/pubkey.c trunk/cipher/rijndael.c trunk/cipher/whirlpool.c trunk/mpi/ec.c trunk/mpi/mpi-bit.c trunk/mpi/mpi-mod.c trunk/mpi/mpi-mpow.c trunk/mpi/mpi-pow.c trunk/mpi/mpicoder.c trunk/mpi/mpiutil.c trunk/random/random-csprng.c trunk/random/random.c trunk/random/rndhw.c trunk/random/rndw32.c trunk/src/ChangeLog trunk/src/ath.c trunk/src/fips.c trunk/src/g10lib.h trunk/src/global.c trunk/src/misc.c Log: Replace assert calls by a new gcry_assert at most places. [The diff below has been truncated] Modified: trunk/src/ChangeLog =================================================================== --- trunk/src/ChangeLog 2008-08-20 14:10:11 UTC (rev 1301) +++ trunk/src/ChangeLog 2008-08-20 17:59:42 UTC (rev 1302) @@ -1,3 +1,10 @@ +2008-08-20 Werner Koch + + * g10lib.h (gcry_assert): New. use this at almost all places + where we used a plain assert. + * misc.c (_gcry_assert_failed): New. + (_gcry_bug): Also use func variant for ISO-C99. + 2008-08-19 Werner Koch * visibility.c, visibility.h (gcry_mpi_lshift): New. Modified: trunk/cipher/ac.c =================================================================== --- trunk/cipher/ac.c 2008-08-20 14:10:11 UTC (rev 1301) +++ trunk/cipher/ac.c 2008-08-20 17:59:42 UTC (rev 1302) @@ -24,7 +24,6 @@ #include #include #include -#include #include "g10lib.h" #include "cipher.h" @@ -886,8 +885,8 @@ if (fips_mode ()) return; - assert ((mode == GCRY_AC_IO_READABLE) || (mode == GCRY_AC_IO_WRITABLE)); - assert ((type == GCRY_AC_IO_STRING) || (type == GCRY_AC_IO_STRING)); + gcry_assert ((mode == GCRY_AC_IO_READABLE) || (mode == GCRY_AC_IO_WRITABLE)); + gcry_assert ((type == GCRY_AC_IO_STRING) || (type == GCRY_AC_IO_STRING)); ac_io->mode = mode; ac_io->type = type; @@ -947,7 +946,7 @@ { gcry_error_t err; - assert (ac_io->mode == GCRY_AC_IO_WRITABLE); + gcry_assert (ac_io->mode == GCRY_AC_IO_WRITABLE); err = 0; switch (ac_io->type) @@ -1007,7 +1006,7 @@ { gcry_error_t err; - assert (ac_io->mode == GCRY_AC_IO_READABLE); + gcry_assert (ac_io->mode == GCRY_AC_IO_READABLE); err = 0; switch (ac_io->type) Modified: trunk/cipher/dsa.c =================================================================== --- trunk/cipher/dsa.c 2008-08-20 14:10:11 UTC (rev 1301) +++ trunk/cipher/dsa.c 2008-08-20 17:59:42 UTC (rev 1302) @@ -23,7 +23,6 @@ #include #include #include -#include #include "g10lib.h" #include "mpi.h" @@ -237,7 +236,7 @@ * is the secret part. */ if( DBG_CIPHER ) log_debug("choosing a random x "); - assert( qbits >= 160 ); + gcry_assert( qbits >= 160 ); x = mpi_alloc_secure( mpi_get_nlimbs(q) ); mpi_sub_ui( h, q, 1 ); /* put q-1 into h */ rndbuf = NULL; Modified: trunk/cipher/ecc.c =================================================================== --- trunk/cipher/ecc.c 2008-08-20 14:10:11 UTC (rev 1301) +++ trunk/cipher/ecc.c 2008-08-20 17:59:42 UTC (rev 1302) @@ -54,7 +54,6 @@ #include #include #include -#include #include "g10lib.h" #include "mpi.h" Modified: trunk/cipher/md.c =================================================================== --- trunk/cipher/md.c 2008-08-20 14:10:11 UTC (rev 1301) +++ trunk/cipher/md.c 2008-08-20 17:59:42 UTC (rev 1302) @@ -23,7 +23,6 @@ #include #include #include -#include #include "g10lib.h" #include "cipher.h" @@ -627,10 +626,10 @@ { bhd->ctx = b = (struct gcry_md_context *) ((char *) bhd + n); /* No need to copy the buffer due to the write above. */ - assert (ahd->bufsize == (n - sizeof (struct gcry_md_handle) + 1)); + gcry_assert (ahd->bufsize == (n - sizeof (struct gcry_md_handle) + 1)); bhd->bufsize = ahd->bufsize; bhd->bufpos = 0; - assert (! ahd->bufpos); + gcry_assert (! ahd->bufpos); memcpy (b, a, sizeof *a); b->list = NULL; b->debug = NULL; @@ -843,7 +842,7 @@ gcry_md_hash_buffer ( algo, helpkey, key, keylen ); key = helpkey; keylen = md_digest_length( algo ); - assert ( keylen <= 64 ); + gcry_assert ( keylen <= 64 ); } memset ( hd->ctx->macpads, 0, 2*(hd->ctx->macpads_Bsize) ); Modified: trunk/cipher/primegen.c =================================================================== --- trunk/cipher/primegen.c 2008-08-20 14:10:11 UTC (rev 1301) +++ trunk/cipher/primegen.c 2008-08-20 17:59:42 UTC (rev 1302) @@ -24,7 +24,6 @@ #include #include #include -#include #include #include "g10lib.h" @@ -208,7 +207,7 @@ { gcry_mpi_t prime = item->prime; item->prime = NULL; - assert (nbits == mpi_get_nbits (prime)); + gcry_assert (nbits == mpi_get_nbits (prime)); return prime; } return NULL; @@ -950,7 +949,7 @@ mpi_set_highbit( x, nbits-2 ); mpi_clear_bit( x, nbits-2 ); } - assert ( mpi_cmp( x, nminus1 ) < 0 && mpi_cmp_ui( x, 1 ) > 0 ); + gcry_assert (mpi_cmp (x, nminus1) < 0 && mpi_cmp_ui (x, 1) > 0); } gcry_mpi_powm ( y, x, q, n); if ( mpi_cmp_ui(y, 1) && mpi_cmp( y, nminus1 ) ) Modified: trunk/cipher/pubkey.c =================================================================== --- trunk/cipher/pubkey.c 2008-08-20 14:10:11 UTC (rev 1301) +++ trunk/cipher/pubkey.c 2008-08-20 17:59:42 UTC (rev 1302) @@ -23,7 +23,6 @@ #include #include #include -#include #include "g10lib.h" #include "mpi.h" @@ -860,7 +859,7 @@ /* Clear the array for easir error cleanup. */ for (name = element_names, idx = 0; *name; name++, idx++) elements[idx] = NULL; - assert (idx >= 6); /* We know that ECC has at least 6 elements. */ + gcry_assert (idx >= 6); /* We know that ECC has at least 6 elements. */ /* Init the array with the available curve parameters. */ for (name = element_names, idx = 0; *name && !err; name++, idx++) @@ -1391,7 +1390,7 @@ frame[n++] = 0; frame[n++] = 2; /* block type */ i = nframe - 3 - valuelen; - assert (i > 0); + gcry_assert (i > 0); p = gcry_random_bytes_secure (i, GCRY_STRONG_RANDOM); /* Replace zero bytes by new values. */ for (;;) @@ -1426,7 +1425,7 @@ frame[n++] = 0; memcpy (frame+n, value, valuelen); n += valuelen; - assert (n == nframe); + gcry_assert (n == nframe); /* FIXME, error checking? */ gcry_mpi_scan (ret_mpi, GCRYMPI_FMT_USG, frame, n, &nframe); @@ -1527,7 +1526,7 @@ frame[n++] = 0; frame[n++] = 1; /* block type */ i = nframe - valuelen - asnlen - 3 ; - assert (i > 1); + gcry_assert (i > 1); memset (frame+n, 0xff, i ); n += i; frame[n++] = 0; @@ -1535,7 +1534,7 @@ n += asnlen; memcpy (frame+n, value, valuelen ); n += valuelen; - assert (n == nframe); + gcry_assert (n == nframe); /* Convert it into an MPI. FIXME: error checking? */ gcry_mpi_scan (ret_mpi, GCRYMPI_FMT_USG, frame, n, &nframe); @@ -1599,7 +1598,7 @@ if (rc) goto leave; - assert (module); + gcry_assert (module); pubkey = (gcry_pk_spec_t *) module->spec; /* If aliases for the algorithm name exists, take the first one @@ -1838,7 +1837,7 @@ if (rc) goto leave; - assert (module); + gcry_assert (module); pubkey = (gcry_pk_spec_t *) module->spec; algo_name = pubkey->aliases? *pubkey->aliases : NULL; if (!algo_name || !*algo_name) @@ -2291,7 +2290,7 @@ p = stpcpy (p, "))"); } strcpy (p, ")"); - assert (p - string < needed); + gcry_assert (p - string < needed); while (nelem < DIM (mpis)) mpis[nelem++] = NULL; @@ -2315,9 +2314,9 @@ free (arg_list); if (rc) BUG (); - assert (DIM (mpis) == 30); /* Reminder to make sure that the - array gets increased if new - parameters are added. */ + gcry_assert (DIM (mpis) == 30); /* Reminder to make sure that + the array gets increased if + new parameters are added. */ } gcry_free (string); } Modified: trunk/cipher/rijndael.c =================================================================== --- trunk/cipher/rijndael.c 2008-08-20 14:10:11 UTC (rev 1301) +++ trunk/cipher/rijndael.c 2008-08-20 17:59:42 UTC (rev 1302) @@ -41,7 +41,6 @@ #include #include #include /* for memcmp() */ -#include #include "types.h" /* for byte and u32 typedefs */ #include "g10lib.h" @@ -995,8 +994,8 @@ return a; \ } while (0) - assert (sizeof tv[0].data[0].input == sizeof scratch); - assert (sizeof tv[0].data[0].output == sizeof scratch); + gcry_assert (sizeof tv[0].data[0].input == sizeof scratch); + gcry_assert (sizeof tv[0].data[0].output == sizeof scratch); for (tvi=0; tvi < DIM (tv); tvi++) if (tv[tvi].mode == requested_mode) Modified: trunk/cipher/whirlpool.c =================================================================== --- trunk/cipher/whirlpool.c 2008-08-20 14:10:11 UTC (rev 1301) +++ trunk/cipher/whirlpool.c 2008-08-20 17:59:42 UTC (rev 1302) @@ -33,7 +33,6 @@ #include #include #include -#include #include "types.h" #include "g10lib.h" @@ -1350,7 +1349,7 @@ buffer_size >>= 8; carry >>= 8; } - assert (! (buffer_size || carry)); + gcry_assert (! (buffer_size || carry)); } static void Modified: trunk/mpi/ec.c =================================================================== --- trunk/mpi/ec.c 2008-08-20 14:10:11 UTC (rev 1301) +++ trunk/mpi/ec.c 2008-08-20 17:59:42 UTC (rev 1302) @@ -22,7 +22,6 @@ #include #include #include -#include #include "mpi-internal.h" #include "longlong.h" Modified: trunk/mpi/mpi-bit.c =================================================================== --- trunk/mpi/mpi-bit.c 2008-08-20 14:10:11 UTC (rev 1301) +++ trunk/mpi/mpi-bit.c 2008-08-20 17:59:42 UTC (rev 1302) @@ -21,7 +21,6 @@ #include #include #include -#include #include "mpi-internal.h" #include "longlong.h" Modified: trunk/mpi/mpi-mod.c =================================================================== --- trunk/mpi/mpi-mod.c 2008-08-20 14:10:11 UTC (rev 1301) +++ trunk/mpi/mpi-mod.c 2008-08-20 17:59:42 UTC (rev 1302) @@ -23,7 +23,6 @@ #include #include #include -#include #include "mpi-internal.h" #include "longlong.h" Modified: trunk/mpi/mpi-mpow.c =================================================================== --- trunk/mpi/mpi-mpow.c 2008-08-20 14:10:11 UTC (rev 1301) +++ trunk/mpi/mpi-mpow.c 2008-08-20 17:59:42 UTC (rev 1302) @@ -21,10 +21,10 @@ #include #include #include + #include "mpi-internal.h" #include "longlong.h" #include "g10lib.h" -#include /* Barrett is slower than the classical way. It can be tweaked by @@ -77,7 +77,7 @@ for(k=0; basearray[k]; k++ ) ; - assert(k); + gcry_assert(k); for(t=0, i=0; (tmp=exparray[i]); i++ ) { /*log_mpidump("exp: ", tmp );*/ j = mpi_get_nbits(tmp); @@ -85,9 +85,9 @@ t = j; } /*log_mpidump("mod: ", m );*/ - assert(i==k); - assert(t); - assert( k < 10 ); + gcry_assert (i==k); + gcry_assert (t); + gcry_assert (k < 10); G = gcry_xcalloc( (1<= 0 && idx < (1<= 0 && idx < (1< #include #include + #include "mpi-internal.h" #include "longlong.h" -#include /**************** @@ -133,7 +133,7 @@ else { /* Make BASE, EXPO and MOD not overlap with RES. */ if( rp == bp ) { /* RES and BASE are identical. Allocate temp. space for BASE. */ - assert( !bp_marker ); + gcry_assert (!bp_marker); bp_nlimbs = bsec? bsize:0; bp = bp_marker = mpi_alloc_limb_space( bsize, bsec ); MPN_COPY(bp, rp, bsize); @@ -146,7 +146,7 @@ } if( rp == mp ) { /* RES and MOD are identical. Allocate temporary space for MOD.*/ - assert( !mp_marker ); + gcry_assert (!mp_marker); mp_nlimbs = msec?msize:0; mp = mp_marker = mpi_alloc_limb_space( msize, msec ); MPN_COPY(mp, rp, msize); Modified: trunk/mpi/mpicoder.c =================================================================== --- trunk/mpi/mpicoder.c 2008-08-20 14:10:11 UTC (rev 1301) +++ trunk/mpi/mpicoder.c 2008-08-20 17:59:42 UTC (rev 1302) @@ -23,7 +23,6 @@ #include #include #include -#include #include "mpi-internal.h" #include "g10lib.h" @@ -123,9 +122,9 @@ } else c1 = *str++; - assert(c1); + gcry_assert (c1); c2 = *str++; - assert(c2); + gcry_assert (c2); if( c1 >= '0' && c1 <= '9' ) c = c1 - '0'; else if( c1 >= 'a' && c1 <= 'f' ) @@ -328,7 +327,7 @@ a->d[i++] = alimb; } a->nlimbs = i; - assert( i == nlimbs ); + gcry_assert (i == nlimbs); } Modified: trunk/mpi/mpiutil.c =================================================================== --- trunk/mpi/mpiutil.c 2008-08-20 14:10:11 UTC (rev 1301) +++ trunk/mpi/mpiutil.c 2008-08-20 17:59:42 UTC (rev 1302) @@ -22,7 +22,6 @@ #include #include #include -#include #include "g10lib.h" #include "mpi-internal.h" @@ -196,7 +195,7 @@ ap = a->d; if (!a->nlimbs) { - assert(!ap); + gcry_assert (!ap); return; } bp = mpi_alloc_limb_space (a->nlimbs, 1); Modified: trunk/random/random-csprng.c =================================================================== --- trunk/random/random-csprng.c 2008-08-20 14:10:11 UTC (rev 1301) +++ trunk/random/random-csprng.c 2008-08-20 17:59:42 UTC (rev 1302) @@ -29,7 +29,6 @@ #include #include #include -#include #include #include #include @@ -278,9 +277,9 @@ /* Make sure that we are still using the values we have traditionally used for the random levels. */ - assert ( GCRY_WEAK_RANDOM == 0 - && GCRY_STRONG_RANDOM == 1 - && GCRY_VERY_STRONG_RANDOM == 2); + gcry_assert (GCRY_WEAK_RANDOM == 0 + && GCRY_STRONG_RANDOM == 1 + && GCRY_VERY_STRONG_RANDOM == 2); } } @@ -603,7 +602,7 @@ #error must have a digest length of 20 for ripe-md-160 #endif - assert (pool_is_locked); + gcry_assert (pool_is_locked); _gcry_rmd160_init( &md ); /* Loop over the pool. */ @@ -728,7 +727,7 @@ unsigned char buffer[POOLSIZE]; From cvs at cvs.gnupg.org Thu Aug 21 20:34:25 2008 From: cvs at cvs.gnupg.org (svn author wk) Date: Thu, 21 Aug 2008 20:34:25 +0200 Subject: [svn] gcry - r1303 - in trunk: . cipher random src Message-ID: Author: wk Date: 2008-08-21 20:34:24 +0200 (Thu, 21 Aug 2008) New Revision: 1303 Modified: trunk/TODO trunk/cipher/ChangeLog trunk/cipher/primegen.c trunk/random/ChangeLog trunk/random/random-fips.c trunk/random/random.c trunk/src/ChangeLog trunk/src/fips.c trunk/src/g10lib.h trunk/src/misc.c Log: Finished the X9.31 RNG implementations. [The diff below has been truncated] Modified: trunk/cipher/ChangeLog =================================================================== --- trunk/cipher/ChangeLog 2008-08-20 17:59:42 UTC (rev 1302) +++ trunk/cipher/ChangeLog 2008-08-21 18:34:24 UTC (rev 1303) @@ -1,3 +1,9 @@ +2008-08-21 Werner Koch + + * primegen.c (_gcry_generate_secret_prime) + (_gcry_generate_public_prime): Use a constant macro for the random + level. + 2008-08-19 Werner Koch * pubkey.c (sexp_elements_extract_ecc) [!USE_ECC]: Do not allow Modified: trunk/random/ChangeLog =================================================================== --- trunk/random/ChangeLog 2008-08-20 17:59:42 UTC (rev 1302) +++ trunk/random/ChangeLog 2008-08-21 18:34:24 UTC (rev 1303) @@ -1,3 +1,7 @@ +2008-08-21 Werner Koch + + * random-fips.c: Finish implementation. + 2008-08-15 Werner Koch * random-fips.c: New. Modified: trunk/src/ChangeLog =================================================================== --- trunk/src/ChangeLog 2008-08-20 17:59:42 UTC (rev 1302) +++ trunk/src/ChangeLog 2008-08-21 18:34:24 UTC (rev 1303) @@ -1,3 +1,7 @@ +2008-08-21 Werner Koch + + * misc.c (_gcry_log_printhex): New. + 2008-08-20 Werner Koch * g10lib.h (gcry_assert): New. use this at almost all places Modified: trunk/TODO =================================================================== --- trunk/TODO 2008-08-20 17:59:42 UTC (rev 1302) +++ trunk/TODO 2008-08-21 18:34:24 UTC (rev 1303) @@ -108,5 +108,4 @@ We have some code to allow using libgcrypt from C++, so we also should have a test case. -* gcry_mpi_lshift needs actual code. - +* The prime generator always uses very-strong-random. Modified: trunk/cipher/primegen.c =================================================================== --- trunk/cipher/primegen.c 2008-08-20 17:59:42 UTC (rev 1302) +++ trunk/cipher/primegen.c 2008-08-21 18:34:24 UTC (rev 1303) @@ -245,7 +245,8 @@ { gcry_mpi_t prime; - prime = gen_prime( nbits, 1, 2, extra_check, extra_check_arg); + prime = gen_prime (nbits, 1, GCRY_VERY_STRONG_RANDOM, + extra_check, extra_check_arg); progress('\n'); return prime; } @@ -257,7 +258,8 @@ { gcry_mpi_t prime; - prime = gen_prime( nbits, 0, 2, extra_check, extra_check_arg ); + prime = gen_prime (nbits, 0, GCRY_VERY_STRONG_RANDOM, + extra_check, extra_check_arg ); progress('\n'); return prime; } Modified: trunk/random/random-fips.c =================================================================== --- trunk/random/random-fips.c 2008-08-20 17:59:42 UTC (rev 1302) +++ trunk/random/random-fips.c 2008-08-21 18:34:24 UTC (rev 1303) @@ -18,7 +18,11 @@ */ /* - FIXME: Explain + The core of this deterministic random number generator is + implemented according to the document "NIST-Recommended Random + Number Generator Based on ANSI X9.31 Appendix A.2.4 Using the 3-Key + Triple DES and AES Algorithms" (2005-01-31) and uses the AES + variant. */ @@ -26,21 +30,578 @@ #include #include #include -#include #include +#include +#include +#ifdef HAVE_GETTIMEOFDAY +#include +#endif #include "g10lib.h" #include "random.h" #include "rand-internal.h" #include "ath.h" +/* This is the lock we use to serialize access to this RNG. The extra + integer variable is only used to check the locking state; that is, + it is not meant to be thread-safe but merely as a failsafe feature + to assert proper locking. */ +static ath_mutex_t fips_rng_lock = ATH_MUTEX_INITIALIZER; +static int fips_rng_is_locked; +/* The required size for the temporary buffer of the x931_aes_driver + function and the buffer itself which will be allocated in secure + memory. This needs to be global variable for proper initialization + and to allow shutting down the RNG without leaking memory. May + only be used while holding the FIPS_RNG_LOCK. + This variable is also used to avoid duplicate initialization. */ +#define TEMPVALUE_FOR_X931_AES_DRIVER_SIZE 48 +static unsigned char *tempvalue_for_x931_aes_driver; + + +/* The length of the key we use: 16 bytes (128 bit) for AES128. */ +#define X931_AES_KEYLEN 16 +/* A global buffer used to communicate between the x931_generate_key + and x931_generate_seed functions and the entropy_collect_cb + function. It may only be used by these functions. */ +static unsigned char *entropy_collect_buffer; /* Buffer. */ +static size_t entropy_collect_buffer_len; /* Used length. */ +static size_t entropy_collect_buffer_size; /* Allocated length. */ + + +/* This random context type is used to track properties of one random + generator. Thee context are usually allocated in secure memory so + that the seed value is well protected. There are a couble of guard + fields to help detecting applications accidently overwriting parts + of the memory. */ +struct rng_context +{ + unsigned char guard_0[1]; + + /* The handle of the cipher used by the RNG. If this one is not + NULL a cipher handle along with a random key has been + established. */ + gcry_cipher_hd_t cipher_hd; + + /* If this flag is true, this context requires strong entropy; + i.e. from /dev/random. */ + int need_strong_entropy:1; + + /* If this flag is true, the SEED_V buffer below carries a valid + seed. */ + int is_seeded:1; + + /* The very first block generated is used to compare the result + against the last result. This flag indicates that such a block + is available. */ + int compare_value_valid:1; + + unsigned char guard_1[1]; + + /* The buffer containing the seed value V. */ + unsigned char seed_V[16]; + + unsigned char guard_2[1]; + + /* The last result from the x931_aes fucntion. Only valid if + compare_value_valid is set. */ + unsigned char compare_value[16]; + + unsigned char guard_3[1]; + + /* We need to keep track of the process which did the initialization + so that we can detect a fork. The volatile modifier is required + so that the compiler does not optimize it away in case the getpid + function is badly attributed. */ + pid_t key_init_pid; + pid_t seed_init_pid; +}; +typedef struct rng_context *rng_context_t; + + +/* The random context used for the nonce generator. May only be used + while holding the FIPS_RNG_LOCK. */ +static rng_context_t nonce_context; +/* The random context used for the standard random generator. May + only be used while holding the FIPS_RNG_LOCK. */ +static rng_context_t std_rng_context; +/* The random context used for the very strong random generator. May + only be used while holding the FIPS_RNG_LOCK. */ +static rng_context_t strong_rng_context; + + + -/* --- Functions --- */ +/* --- Functions --- */ +/* Basic initialization is required to initialize mutexes and + do a few checks on the implementation. */ +static void +basic_initialization (void) +{ + static int initialized; + int my_errno; + if (!initialized) + return; + initialized = 1; + + my_errno = ath_mutex_init (&fips_rng_lock); + if (my_errno) + log_fatal ("failed to create the RNG lock: %s\n", strerror (my_errno)); + fips_rng_is_locked = 0; + + /* Make sure that we are still using the values we have + traditionally used for the random levels. */ + gcry_assert (GCRY_WEAK_RANDOM == 0 + && GCRY_STRONG_RANDOM == 1 + && GCRY_VERY_STRONG_RANDOM == 2); + +} + + +/* Acquire the fips_rng_lock. */ +static void +lock_rng (void) +{ + int my_errno; + + my_errno = ath_mutex_lock (&fips_rng_lock); + if (my_errno) + log_fatal ("failed to acquire the RNG lock: %s\n", strerror (my_errno)); + fips_rng_is_locked = 1; +} + + +/* Release the fips_rng_lock. */ +static void +unlock_rng (void) +{ + int my_errno; + + fips_rng_is_locked = 0; + my_errno = ath_mutex_unlock (&fips_rng_lock); + if (my_errno) + log_fatal ("failed to release the RNG lock: %s\n", strerror (my_errno)); +} + +static void +setup_guards (rng_context_t rng_ctx) +{ + /* Set the guards to some arbitrary values. */ + rng_ctx->guard_0[0] = 17; + rng_ctx->guard_1[0] = 42; + rng_ctx->guard_2[0] = 137; + rng_ctx->guard_3[0] = 252; +} + +static void +check_guards (rng_context_t rng_ctx) +{ + if ( rng_ctx->guard_0[0] != 17 + || rng_ctx->guard_1[0] != 42 + || rng_ctx->guard_2[0] != 137 + || rng_ctx->guard_3[0] != 252 ) + log_fatal ("memory corruption detected in RNG context %p\n", rng_ctx); +} + + +/* Get the DT vector for use with the core PRNG function. Buffer + needs to be provided by the caller with a size of at least LENGTH + bytes. The 16 byte timestamp we construct is made up the real time + and three counters: + + Buffer: 00112233445566778899AABBCCDDEEFF + !--+---!!-+-!!+!!--+---!!--+---! + seconds ---------/ | | | | + microseconds -----------/ | | | + counter2 -------------------/ | | + counter1 ------------------------/ | + counter0 --------------------------------/ + + Counter 2 is just 12 bits wide and used to track fractions of + milliseconds whereas counters 1 and 0 are combined to a free + running 64 bit counter. */ +static void +x931_get_dt (unsigned char *buffer, size_t length) +{ + gcry_assert (length == 16); /* This length is required for use with AES. */ + gcry_assert (fips_rng_is_locked); + +#if HAVE_GETTIMEOFDAY + { + static u32 last_sec, last_usec; + static u32 counter1, counter0; + static u16 counter2; + + unsigned int usec; + struct timeval tv; + + if (!last_sec) + { + /* This is the very first time we are called: Set the counters + to an not so easy predictable value to avoid always + starting at 0. Not really needed but it doesn't harm. */ + counter1 = (u32)getpid (); + counter0 = (u32)getppid (); + } + + + if (gettimeofday (&tv, NULL)) + log_fatal ("gettimeofday() failed: %s\n", strerror (errno)); + + /* The microseconds part is always less than 1 millon (0x0f4240). + Thus we don't care about the MSB and in addition shift it to + the left by 4 bits. */ + usec = tv.tv_usec; + usec <<= 4; + /* If we got the same time as by the last invocation, bump up + counter2 and save the time for the next invocation. */ + if (tv.tv_sec == last_sec && usec == last_usec) + { + counter2++; + counter2 &= 0x0fff; + } + else + { + counter2 = 0; + last_sec = tv.tv_sec; + last_usec = usec; + } + /* Fill the buffer with the timestamp. */ + buffer[0] = ((tv.tv_sec >> 24) & 0xff); + buffer[1] = ((tv.tv_sec >> 16) & 0xff); + buffer[2] = ((tv.tv_sec >> 8) & 0xff); + buffer[3] = (tv.tv_sec & 0xff); + buffer[4] = ((usec >> 16) & 0xff); + buffer[5] = ((usec >> 8) & 0xff); + buffer[6] = ((usec & 0xf0) | ((counter2 >> 8) & 0x0f)); + buffer[7] = (counter2 & 0xff); + /* Add the free running counter. */ + buffer[8] = ((counter1 >> 24) & 0xff); + buffer[9] = ((counter1 >> 16) & 0xff); + buffer[10] = ((counter1 >> 8) & 0xff); + buffer[11] = ((counter1) & 0xff); + buffer[12] = ((counter0 >> 24) & 0xff); + buffer[13] = ((counter0 >> 16) & 0xff); + buffer[14] = ((counter0 >> 8) & 0xff); + buffer[15] = ((counter0) & 0xff); + /* Bump up that counter. */ + if (!++counter0) + ++counter1; + } +#else + log_fatal ("gettimeofday() not available on this system\n"); +#endif + + /* log_printhex ("x931_get_dt: ", buffer, 16); */ +} + + +/* XOR the buffers A and B which are each of LENGTH bytes and store + the result at R. R needs to be provided by the caller with a size + of at least LENGTH bytes. */ +static void +xor_buffer (unsigned char *r, + const unsigned char *a, const unsigned char *b, size_t length) +{ + for ( ; length; length--, a++, b++, r++) + *r = (*a ^ *b); +} + + +/* Encrypt LENGTH bytes of INPUT to OUTPUT using KEY. LENGTH + needs to be 16. */ +static void +encrypt_aes (gcry_cipher_hd_t key, + unsigned char *output, const unsigned char *input, size_t length) +{ + gpg_error_t err; + + gcry_assert (length == 16); + + err = gcry_cipher_encrypt (key, output, length, input, length); + if (err) + log_fatal ("AES encryption in RNG failed: %s\n", gcry_strerror (err)); +} + + +/* The core ANSI X9.31, Appendix A.2.4 function using AES. The caller + needs to pass a 16 byte buffer for the result and the 16 byte seed + value V. The caller also needs to pass an appropriate KEY and make + sure to pass a valid seed_V. The caller also needs to provide two + 16 bytes buffer for intermediate results, they may be reused by the + caller later. + + On return the result is stored at RESULT_R and the SEED_V is + updated. May only be used while holding the lock. */ +static void +x931_aes (unsigned char result_R[16], unsigned char seed_V[16], + gcry_cipher_hd_t key, + unsigned char intermediate_I[16], unsigned char temp_xor[16]) +{ + unsigned char datetime_DT[16]; + + /* Let ede*X(Y) represent the AES encryption of Y under the key *X. + + Let V be a 128-bit seed value which is also kept secret, and XOR + be the exclusive-or operator. Let DT be a date/time vector which + is updated on each iteration. I is a intermediate value. + + I = ede*K(DT) */ + x931_get_dt (datetime_DT, 16); + encrypt_aes (key, intermediate_I, datetime_DT, 16); + + /* R = ede*K(I XOR V) */ + xor_buffer (temp_xor, intermediate_I, seed_V, 16); + encrypt_aes (key, result_R, temp_xor, 16); + + /* V = ede*K(R XOR I). */ + xor_buffer (temp_xor, result_R, intermediate_I, 16); + encrypt_aes (key, seed_V, temp_xor, 16); + + /* Zero out temporary values. */ + wipememory (intermediate_I, 16); + wipememory (temp_xor, 16); +} + + +/* The high level driver to x931_aes. This one does the required + tests and calls the core function until the entire buffer has been + filled. OUTPUT is a caller provided buffer of LENGTH bytes to + receive the random, RNG_CTX is the context of the RNG. The context + must be properly initialized. Returns 0 on success. */ +static int +x931_aes_driver (unsigned char *output, size_t length, rng_context_t rng_ctx) +{ + unsigned char *intermediate_I, *temp_buffer, *result_buffer; + size_t nbytes; + + gcry_assert (fips_rng_is_locked); + gcry_assert (rng_ctx->cipher_hd); + gcry_assert (rng_ctx->is_seeded); + + gcry_assert (tempvalue_for_x931_aes_driver); + gcry_assert (TEMPVALUE_FOR_X931_AES_DRIVER_SIZE == 48); + intermediate_I = tempvalue_for_x931_aes_driver; + temp_buffer = tempvalue_for_x931_aes_driver + 16; + result_buffer = tempvalue_for_x931_aes_driver + 32; + + while (length) + { + /* Due to the design of the RNG, we always receive 16 bytes (128 + bit) of random even if we require less. The extra bytes + returned are not used. Intheory we could save them for the + next invocation, but that would make the control flow harder + to read. */ + nbytes = length < 16? length : 16; + x931_aes (result_buffer, rng_ctx->seed_V, rng_ctx->cipher_hd, + intermediate_I, temp_buffer); + + /* Do a basic check on the output to avoid a stuck generator. */ + if (!rng_ctx->compare_value_valid) + { + /* First time used, only save the result. */ + memcpy (rng_ctx->compare_value, result_buffer, 16); + rng_ctx->compare_value_valid = 1; + continue; + } + if (!memcmp (rng_ctx->compare_value, result_buffer, 16)) + { + /* Ooops, we received the same 128 bit block - that should + in theory never happen. The FIPS requirement says that + we need to put ourself into the error state in such + case. */ + fips_signal_error ("duplicate 128 bit block returned by RNG"); + return -1; + } + memcpy (rng_ctx->compare_value, result_buffer, 16); + + /* Append to outbut. */ + memcpy (output, result_buffer, nbytes); + wipememory (result_buffer, 16); + output += nbytes; + length -= nbytes; + } + + return 0; +} + + +/* Callback for x931_generate_key. Note that this callback uses the + global ENTROPY_COLLECT_BUFFER which has been setup by + x931_generate_key. ORIGIN is not used but required due to the + emtropy gathering module. */ +static void +entropy_collect_cb (const void *buffer, size_t length, + enum random_origins origin) +{ + const unsigned char *p = buffer; + + (void)origin; + + gcry_assert (fips_rng_is_locked); + gcry_assert (entropy_collect_buffer); + + while (length--) + { + gcry_assert (entropy_collect_buffer_len < entropy_collect_buffer_size); + entropy_collect_buffer[entropy_collect_buffer_len++] ^= *p++; + } +} + +/* Generate a key for use with x931_aes. The function returns a + handle to the cipher context readily prepared for ECB encryption. + If VERY_STRONG is true the key is read from /dev/random, otherwise + from /dev/urandom. On error NULL is returned. */ +static gcry_cipher_hd_t +x931_generate_key (int very_strong) +{ + gcry_cipher_hd_t hd; + gpg_error_t err; + + gcry_assert (fips_rng_is_locked); + + /* Allocate a cipher context. */ + err = gcry_cipher_open (&hd, GCRY_CIPHER_AES128, GCRY_CIPHER_MODE_ECB, + GCRY_CIPHER_SECURE); + if (err) + { + log_error ("error creating cipher context for RNG: %s\n", From cvs at cvs.gnupg.org Fri Aug 22 21:17:06 2008 From: cvs at cvs.gnupg.org (svn author wk) Date: Fri, 22 Aug 2008 21:17:06 +0200 Subject: [svn] gcry - r1304 - in trunk: . doc random src tests Message-ID: Author: wk Date: 2008-08-22 21:17:05 +0200 (Fri, 22 Aug 2008) New Revision: 1304 Modified: trunk/ChangeLog trunk/README trunk/configure.ac trunk/doc/gcrypt.texi trunk/random/ChangeLog trunk/random/rand-internal.h trunk/random/random-fips.c trunk/random/random.c trunk/random/random.h trunk/src/ChangeLog trunk/src/Makefile.am trunk/src/cipher-proto.h trunk/src/fips.c trunk/src/global.c trunk/src/hmac256.c trunk/src/hmac256.h trunk/tests/Makefile.am Log: Completed the RNG implementaion switching. Added framework for running RNG tests. Added an experimental option --enable-hmac-binary-check to configure. --This line, and those below, will be ignored-- M src/fips.c M src/cipher-proto.h M src/global.c M src/hmac256.c M src/ChangeLog M src/hmac256.h M src/Makefile.am M tests/Makefile.am M configure.ac M doc/gcrypt.texi M random/random-fips.c M random/random.c M random/rand-internal.h M random/random.h M random/ChangeLog M ChangeLog M README [The diff below has been truncated] Modified: trunk/ChangeLog =================================================================== --- trunk/ChangeLog 2008-08-21 18:34:24 UTC (rev 1303) +++ trunk/ChangeLog 2008-08-22 19:17:05 UTC (rev 1304) @@ -1,3 +1,8 @@ +2008-08-22 Werner Koch + + * configure.ac: Add option --enable-hmac-binary-check. + (DL_LIBS): Check whether -ldl is required. + 2008-08-19 Werner Koch Release 1.4.2rc1. Modified: trunk/random/ChangeLog =================================================================== --- trunk/random/ChangeLog 2008-08-21 18:34:24 UTC (rev 1303) +++ trunk/random/ChangeLog 2008-08-22 19:17:05 UTC (rev 1304) @@ -1,3 +1,11 @@ +2008-08-22 Werner Koch + + * random.c (_gcry_update_random_seed_file): Move operational check + to _gcry_vcontrol. + (_gcry_fast_random_poll): Ditto. + (_gcry_random_selftest): New. + * random-fips.c (_gcry_rngfips_selftest): New. + 2008-08-21 Werner Koch * random-fips.c: Finish implementation. Modified: trunk/src/ChangeLog =================================================================== --- trunk/src/ChangeLog 2008-08-21 18:34:24 UTC (rev 1303) +++ trunk/src/ChangeLog 2008-08-22 19:17:05 UTC (rev 1304) @@ -1,3 +1,14 @@ +2008-08-22 Werner Koch + + * hmac256.c (_gcry_hmac256_file): New. + (main): New option --binary. + * fips.c (check_binary_integrity): New. + (_gcry_fips_run_selftests): Run it. + + * global.c (_gcry_vcontrol) : + Check for fips operational state. + (_gcry_vcontrol) : Ditt. + 2008-08-21 Werner Koch * misc.c (_gcry_log_printhex): New. Modified: trunk/README =================================================================== --- trunk/README 2008-08-21 18:34:24 UTC (rev 1303) +++ trunk/README 2008-08-22 19:17:05 UTC (rev 1304) @@ -158,12 +158,18 @@ auto - Compile linux, egd and unix in and automagically select at runtime. + --enable-hmac-binary-check + Include support to check the binary at runtime + against a HMAC checksum. This works only in FIPS + mode and on systems providing the dladdr function. + --disable-padlock-support Disable support for the PadLock engine of VIA processors. The default is to use PadLock if available. Try this if you get problems with assembler code. + License Modified: trunk/configure.ac =================================================================== --- trunk/configure.ac 2008-08-21 18:34:24 UTC (rev 1303) +++ trunk/configure.ac 2008-08-22 19:17:05 UTC (rev 1304) @@ -449,7 +449,20 @@ [use_capabilities="$withval"],[use_capabilities=no]) AC_MSG_RESULT($use_capabilities) +# Implementation of the --enable-hmac-binary-check. +AC_MSG_CHECKING([whether a HMAC binary check is requested]) +AC_ARG_ENABLE(hmac-binary-check, + AC_HELP_STRING([--enable-hmac-binary-check], + [Enable library integrity check]), + [use_hmac_binary_check=$enableval], + [use_hmac_binary_check=no]) +AC_MSG_RESULT($use_hmac_binary_check) +if test "$use_hmac_binary_check" = yes ; then + AC_DEFINE(ENABLE_HMAC_BINARY_CHECK,1, + [Define to support an HMAC based integrity check]) +fi + # Implementation of the --disable-padlock-support switch. AC_MSG_CHECKING([whether padlock support is requested]) AC_ARG_ENABLE(padlock-support, @@ -692,7 +705,25 @@ GNUPG_CHECK_MLOCK + +# +# Check wether it is necessary to link against libdl. +# +DL_LIBS="" +if test "$use_hmac_binary_check" = yes ; then + _gcry_save_libs="$LIBS" + LIBS="" + AC_SEARCH_LIBS(dlopen, c dl,,,) + DL_LIBS=$LIBS + LIBS="$_gcry_save_libs" + LIBGCRYPT_CONFIG_LIBS="${LIBGCRYPT_CONFIG_LIBS} ${DL_LIBS}" +fi +AC_SUBST(DL_LIBS) + + +# # Check whether we can use Linux capabilities as requested. +# if test "$use_capabilities" = "yes" ; then use_capabilities=no AC_CHECK_HEADERS(sys/capability.h) Modified: trunk/doc/gcrypt.texi =================================================================== --- trunk/doc/gcrypt.texi 2008-08-21 18:34:24 UTC (rev 1303) +++ trunk/doc/gcrypt.texi 2008-08-22 19:17:05 UTC (rev 1304) @@ -4607,7 +4607,9 @@ @itemize - at item TBD + at item +It may only be used on systesm with a /dev/random device. Swicthing +into FIPS mode on other systems will fail at runtime. Modified: trunk/random/rand-internal.h =================================================================== --- trunk/random/rand-internal.h 2008-08-21 18:34:24 UTC (rev 1303) +++ trunk/random/rand-internal.h 2008-08-22 19:17:05 UTC (rev 1304) @@ -20,6 +20,7 @@ #ifndef G10_RAND_INTERNAL_H #define G10_RAND_INTERNAL_H +#include "../src/cipher-proto.h" /* Constants used to define the origin of random added to the pool. The code is sensitive to the order of the values. */ @@ -76,11 +77,13 @@ enum gcry_random_level level); void _gcry_rngfips_create_nonce (void *buffer, size_t length); +gcry_error_t _gcry_rngfips_selftest (selftest_report_func_t report); + /*-- rndlinux.c --*/ int _gcry_rndlinux_gather_random (void (*add) (const void *, size_t, enum random_origins), Modified: trunk/random/random-fips.c =================================================================== --- trunk/random/random-fips.c 2008-08-21 18:34:24 UTC (rev 1303) +++ trunk/random/random-fips.c 2008-08-22 19:17:05 UTC (rev 1304) @@ -602,6 +602,7 @@ } + /* Initialize this random subsystem. If FULL is false, this function merely calls the basic initialization of the module and does not do anything more. Doing this is not really required but when running @@ -639,9 +640,11 @@ } +/* Print some statistics about the RNG. */ void _gcry_rngfips_dump_stats (void) { + /* Not yet implemented. */ } @@ -656,11 +659,11 @@ /* Add BUFLEN bytes from BUF to the internal random pool. QUALITY should be in the range of 0..100 to indicate the goodness of the - entropy added, or -1 for goodness not known. */ + entropy added, or -1 for goodness not known. */ gcry_error_t _gcry_rngfips_add_bytes (const void *buf, size_t buflen, int quality) { - return 0; + return 0; /* Not implemented. */ } @@ -691,3 +694,18 @@ get_random (buffer, length, nonce_context); } + +/* Run the self-tests. */ +gcry_error_t +_gcry_rngfips_selftest (selftest_report_func_t report) +{ + gcry_err_code_t ec = 0; + char buffer[8]; + + /* Do a simple test using the public interface. */ + gcry_randomize (buffer, sizeof buffer, GCRY_STRONG_RANDOM); + + + return gpg_error (ec); +} + Modified: trunk/random/random.c =================================================================== --- trunk/random/random.c 2008-08-21 18:34:24 UTC (rev 1303) +++ trunk/random/random.c 2008-08-22 19:17:05 UTC (rev 1304) @@ -75,7 +75,7 @@ void _gcry_random_initialize (int full) { - if ( fips_mode() ) + if (fips_mode ()) _gcry_rngfips_initialize (full); else _gcry_rngcsprng_initialize (full); @@ -85,7 +85,7 @@ void _gcry_random_dump_stats (void) { - if ( fips_mode() ) + if (fips_mode ()) _gcry_rngfips_dump_stats (); else _gcry_rngcsprng_dump_stats (); @@ -98,9 +98,10 @@ void _gcry_secure_random_alloc (void) { - if ( fips_mode() ) - return; /* Not used; the fips rng is allows in secure mode. */ - _gcry_rngcsprng_secure_alloc (); + if (fips_mode ()) + ; /* Not used; the fips rng is allows in secure mode. */ + else + _gcry_rngcsprng_secure_alloc (); } @@ -109,18 +110,20 @@ void _gcry_enable_quick_random_gen (void) { - if ( fips_mode() ) - return; /* Not used. */ - _gcry_rngcsprng_enable_quick_gen (); + if (fips_mode ()) + ; /* Not used. */ + else + _gcry_rngcsprng_enable_quick_gen (); } void _gcry_set_random_daemon_socket (const char *socketname) { - if ( fips_mode() ) - return; /* Not used. */ - _gcry_rngcsprng_set_daemon_socket (socketname); + if (fips_mode ()) + ; /* Not used. */ + else + _gcry_rngcsprng_set_daemon_socket (socketname); } /* With ONOFF set to 1, enable the use of the daemon. With ONOFF set @@ -131,7 +134,8 @@ { if (fips_mode ()) return 0; /* Never enabled in fips mode. */ - return _gcry_rngcsprng_use_daemon (onoff); + else + return _gcry_rngcsprng_use_daemon (onoff); } @@ -141,8 +145,9 @@ _gcry_random_is_faked (void) { if (fips_mode ()) - return 0; /* Never faked in fips mode. */ - return _gcry_rngcsprng_is_faked (); + return _gcry_rngfips_is_faked (); + else + return _gcry_rngcsprng_is_faked (); } @@ -154,7 +159,8 @@ { if (fips_mode ()) return 0; /* No need for this in fips mode. */ - return _gcry_rngcsprng_add_bytes (buf, buflen, quality); + else + return _gcry_rngcsprng_add_bytes (buf, buflen, quality); } @@ -217,7 +223,10 @@ void _gcry_set_random_seed_file (const char *name) { - _gcry_rngcsprng_set_seed_file (name); + if (fips_mode ()) + ; /* No need for this in fips mode. */ + else + _gcry_rngcsprng_set_seed_file (name); } @@ -226,10 +235,10 @@ void _gcry_update_random_seed_file (void) { - if (!fips_is_operational ()) /* FIXME: This does no look correct. */ - return; - - _gcry_rngcsprng_update_seed_file (); + if (fips_mode ()) + ; /* No need for this in fips mode. */ + else + _gcry_rngcsprng_update_seed_file (); } @@ -244,10 +253,10 @@ void _gcry_fast_random_poll (void) { - if (!fips_is_operational ()) - return; - - _gcry_rngcsprng_fast_poll (); + if (fips_mode ()) + ; /* No need for this in fips mode. */ + else + _gcry_rngcsprng_fast_poll (); } @@ -256,6 +265,21 @@ void gcry_create_nonce (void *buffer, size_t length) { - _gcry_rngcsprng_create_nonce (buffer, length); + if (fips_mode ()) + _gcry_rngfips_create_nonce (buffer, length); + else + _gcry_rngcsprng_create_nonce (buffer, length); } + +/* Run the self-tests for the RNG. This is currently only implemented + for the FIPS generator. */ +gpg_error_t +_gcry_random_selftest (selftest_report_func_t report) +{ + if (fips_mode ()) + return _gcry_rngfips_selftest (report); + else + return gpg_error (GPG_ERR_NOT_SUPPORTED); +} + Modified: trunk/random/random.h =================================================================== --- trunk/random/random.h 2008-08-21 18:34:24 UTC (rev 1303) +++ trunk/random/random.h 2008-08-22 19:17:05 UTC (rev 1304) @@ -22,6 +22,7 @@ #include "types.h" +/*-- random.c --*/ void _gcry_register_random_progress (void (*cb)(void *,const char*,int,int,int), void *cb_data ); @@ -38,6 +39,7 @@ byte *_gcry_get_random_bits( size_t nbits, int level, int secure ); void _gcry_fast_random_poll( void ); + /*-- rndegd.c --*/ gpg_error_t _gcry_rndegd_set_socket_name (const char *name); Modified: trunk/src/Makefile.am =================================================================== --- trunk/src/Makefile.am 2008-08-21 18:34:24 UTC (rev 1303) +++ trunk/src/Makefile.am 2008-08-22 19:17:05 UTC (rev 1304) @@ -121,3 +121,12 @@ install-data-local: install-def-file uninstall-local: uninstall-def-file + +# FIXME: We ned to figure out how to gte the actual name (parsing +# libgcrypt.la?) and how to create the hmac file already at link time +# so that it can be used without first installing. +#install-exec-hook: +# ./hmac256 --binary "What am I, a doctor or a moonshuttle conductor?" \ +# $(DESTDIR)$(libdir)/libgcrypt.so.11.5.0 \ +# >$(DESTDIR)$(libdir)/libgcrypt.so.11.5.0.hmac + Modified: trunk/src/cipher-proto.h =================================================================== --- trunk/src/cipher-proto.h 2008-08-21 18:34:24 UTC (rev 1303) +++ trunk/src/cipher-proto.h 2008-08-22 19:17:05 UTC (rev 1304) @@ -79,5 +79,6 @@ gcry_error_t _gcry_pk_selftest (int algo, selftest_report_func_t report); gcry_error_t _gcry_hmac_selftest (int algo, selftest_report_func_t report); +gcry_error_t _gcry_random_selftest (selftest_report_func_t report); #endif /*G10_CIPHER_PROTO_H*/ Modified: trunk/src/fips.c =================================================================== --- trunk/src/fips.c 2008-08-21 18:34:24 UTC (rev 1303) +++ trunk/src/fips.c 2008-08-22 19:17:05 UTC (rev 1304) @@ -22,12 +22,14 @@ #include #include #include +#ifdef ENABLE_HMAC_BINARY_CHECK +# include +#endif -/* #include /\* FIXME: GNU only *\/ */ - #include "g10lib.h" #include "ath.h" #include "cipher-proto.h" +#include "hmac256.h" /* The states of the finite state machine used in fips mode. */ enum module_states @@ -417,17 +419,79 @@ } -/* Run self-tests for the random number generator. Return 0 on +/* Run self-tests for the random number generator. Returns 0 on success. */ static int run_random_selftests (void) { - char buffer[8]; + gpg_error_t err; - /* FIXME: For now we just try to get a few bytes. */ - gcry_randomize (buffer, sizeof buffer, GCRY_STRONG_RANDOM); + err = _gcry_random_selftest (reporter); + reporter ("random", 0, NULL, err? gpg_strerror (err):NULL); + + return !!err; +} +/* Run an integrity check on the binary. Returns 0 on success. */ +static int +check_binary_integrity (void) +{ +#ifdef ENABLE_HMAC_BINARY_CHECK + gpg_error_t err; + Dl_info info; + unsigned char digest[32]; + int dlen; + char *fname = NULL; + const char key[] = "What am I, a doctor or a moonshuttle conductor?"; + + if (!dladdr ("gcry_check_version", &info)) + err = gpg_error_from_syserror (); + else + { + dlen = _gcry_hmac256_file (digest, sizeof digest, info.dli_fname, + key, strlen (key)); + if (dlen < 0) + err = gpg_error_from_syserror (); + else if (dlen != 32) + err = gpg_error (GPG_ERR_INTERNAL); + else + { + FILE *fp; + + fname = gcry_malloc (strlen (info.dli_fname) + 5 + 1 ); + if (!fname) + err = gpg_error_from_syserror (); + else + { + strcpy (stpcpy (fname, info.dli_fname), ".hmac"); + fp = fopen (fname, "rb"); + if (!fp) + err = gpg_error_from_syserror (); + else + { + char buffer[33]; + int n; + + /* We expect a file of exactly 32 bytes. Consider + the self-test failed if this is not the case or + if it does not match the just computed HMAC. */ + if ((n=fread (buffer, 1, 33, fp)) != 32 + || memcmp (digest, buffer, 32) ) + err = gpg_error (GPG_ERR_SELFTEST_FAILED); + else + err = 0; + + fclose (fp); + } + } + } + } + reporter ("binary", 0, fname, err? gpg_strerror (err):NULL); + gcry_free (fname); + return !!err; +#else return 0; +#endif } @@ -439,15 +503,6 @@ fips_new_state (STATE_SELFTEST); -/* { */ -/* Dl_info info; */ From cvs at cvs.gnupg.org Mon Aug 25 13:15:51 2008 From: cvs at cvs.gnupg.org (svn author wk) Date: Mon, 25 Aug 2008 13:15:51 +0200 Subject: [svn] gcry - r1305 - trunk/random Message-ID: Author: wk Date: 2008-08-25 13:15:35 +0200 (Mon, 25 Aug 2008) New Revision: 1305 Modified: trunk/random/ChangeLog trunk/random/random-fips.c Log: Implement a KAT for the fips random module. Modified: trunk/random/ChangeLog =================================================================== --- trunk/random/ChangeLog 2008-08-22 19:17:05 UTC (rev 1304) +++ trunk/random/ChangeLog 2008-08-25 11:15:35 UTC (rev 1305) @@ -1,3 +1,11 @@ +2008-08-25 Werner Koch + + * random-fips.c (x931_aes): Take datetime_GT from an arg. + (x931_aes_driver): Call x931_get_dt here. + (x931_get_dt): Implement the KAT hack. + (x931_generate_seed): Copy the seed value to the provided buffer. + (selftest_kat): New. + 2008-08-22 Werner Koch * random.c (_gcry_update_random_seed_file): Move operational check Modified: trunk/random/random-fips.c =================================================================== --- trunk/random/random-fips.c 2008-08-22 19:17:05 UTC (rev 1304) +++ trunk/random/random-fips.c 2008-08-25 11:15:35 UTC (rev 1305) @@ -21,10 +21,8 @@ The core of this deterministic random number generator is implemented according to the document "NIST-Recommended Random Number Generator Based on ANSI X9.31 Appendix A.2.4 Using the 3-Key - Triple DES and AES Algorithms" (2005-01-31) and uses the AES - variant. - - + Triple DES and AES Algorithms" (2005-01-31). This implementaion + uses the AES variant. */ #include @@ -111,12 +109,22 @@ unsigned char guard_3[1]; + /* To implement a KAT we need to provide a know DT value. To + accomplish this the x931_get_dt function checks whether this + field is not NULL and then uses the 16 bytes at this address for + the DT value. However the last byte is will be replaced by the + value of field TEST_DT_COUNTER which will be incremented with + each invocation of x931_get_dt. We use a pointer and not a buffer + because there is no need to put this value into secure memory. */ + const unsigned char *test_dt_ptr; + unsigned char test_dt_counter; + /* We need to keep track of the process which did the initialization so that we can detect a fork. The volatile modifier is required so that the compiler does not optimize it away in case the getpid function is badly attributed. */ - pid_t key_init_pid; - pid_t seed_init_pid; + pid_t key_init_pid; + pid_t seed_init_pid; }; typedef struct rng_context *rng_context_t; @@ -210,8 +218,8 @@ /* Get the DT vector for use with the core PRNG function. Buffer needs to be provided by the caller with a size of at least LENGTH - bytes. The 16 byte timestamp we construct is made up the real time - and three counters: + bytes. RNG_CTX needs to be passed to allow for a KAT. The 16 byte + timestamp we construct is made up the real time and three counters: Buffer: 00112233445566778899AABBCCDDEEFF !--+---!!-+-!!+!!--+---!!--+---! @@ -225,11 +233,25 @@ milliseconds whereas counters 1 and 0 are combined to a free running 64 bit counter. */ static void -x931_get_dt (unsigned char *buffer, size_t length) +x931_get_dt (unsigned char *buffer, size_t length, rng_context_t rng_ctx) { gcry_assert (length == 16); /* This length is required for use with AES. */ gcry_assert (fips_rng_is_locked); + /* If the random context indicates that a test DT should be used, + take the DT value from the context. For safety reasons we do + this only if the context is not one of the regular contexts. */ + if (rng_ctx->test_dt_ptr + && rng_ctx != nonce_context + && rng_ctx != std_rng_context + && rng_ctx != strong_rng_context) + { + memcpy (buffer, rng_ctx->test_dt_ptr, 15); + buffer[15] = rng_ctx->test_dt_counter++; + return; + } + + #if HAVE_GETTIMEOFDAY { static u32 last_sec, last_usec; @@ -329,21 +351,20 @@ /* The core ANSI X9.31, Appendix A.2.4 function using AES. The caller - needs to pass a 16 byte buffer for the result and the 16 byte seed - value V. The caller also needs to pass an appropriate KEY and make - sure to pass a valid seed_V. The caller also needs to provide two - 16 bytes buffer for intermediate results, they may be reused by the - caller later. + needs to pass a 16 byte buffer for the result, the 16 byte + datetime_DT value and the 16 byte seed value V. The caller also + needs to pass an appropriate KEY and make sure to pass a valid + seed_V. The caller also needs to provide two 16 bytes buffer for + intermediate results, they may be reused by the caller later. On return the result is stored at RESULT_R and the SEED_V is updated. May only be used while holding the lock. */ static void -x931_aes (unsigned char result_R[16], unsigned char seed_V[16], +x931_aes (unsigned char result_R[16], + unsigned char datetime_DT[16], unsigned char seed_V[16], gcry_cipher_hd_t key, unsigned char intermediate_I[16], unsigned char temp_xor[16]) { - unsigned char datetime_DT[16]; - /* Let ede*X(Y) represent the AES encryption of Y under the key *X. Let V be a 128-bit seed value which is also kept secret, and XOR @@ -351,7 +372,6 @@ is updated on each iteration. I is a intermediate value. I = ede*K(DT) */ - x931_get_dt (datetime_DT, 16); encrypt_aes (key, intermediate_I, datetime_DT, 16); /* R = ede*K(I XOR V) */ @@ -376,6 +396,7 @@ static int x931_aes_driver (unsigned char *output, size_t length, rng_context_t rng_ctx) { + unsigned char datetime_DT[16]; unsigned char *intermediate_I, *temp_buffer, *result_buffer; size_t nbytes; @@ -397,7 +418,10 @@ next invocation, but that would make the control flow harder to read. */ nbytes = length < 16? length : 16; - x931_aes (result_buffer, rng_ctx->seed_V, rng_ctx->cipher_hd, + + x931_get_dt (datetime_DT, 16, rng_ctx); + x931_aes (result_buffer, + datetime_DT, rng_ctx->seed_V, rng_ctx->cipher_hd, intermediate_I, temp_buffer); /* Do a basic check on the output to avoid a stuck generator. */ @@ -541,6 +565,8 @@ #else log_fatal ("/dev/random support is not compiled in\n"); #endif + memcpy (seed_buffer, entropy_collect_buffer, X931_AES_KEYLEN); + wipememory (entropy_collect_buffer, X931_AES_KEYLEN); gcry_free (entropy_collect_buffer); entropy_collect_buffer = NULL; } @@ -635,7 +661,16 @@ strong_rng_context->need_strong_entropy = 1; setup_guards (strong_rng_context); } - + else + { + /* Already initialized. Do some sanity checks. */ + gcry_assert (!nonce_context->test_dt_ptr); + gcry_assert (!std_rng_context->test_dt_ptr); + gcry_assert (!strong_rng_context->test_dt_ptr); + check_guards (nonce_context); + check_guards (std_rng_context); + check_guards (strong_rng_context); + } unlock_rng (); } @@ -695,16 +730,161 @@ } +/* Run a Know-Answer-Test using a dedicated test context. Note that + we can't use the samples from the NISR RNGVS document because they + don't take the requirement to throw away the first block and use + that for duplicate check in account. Thus we made up our own test + vectors. */ +static gcry_err_code_t +selftest_kat (selftest_report_func_t report) +{ + static struct + { + const unsigned char key[16]; + const unsigned char dt[16]; + const unsigned char v[16]; + const unsigned char r[3][16]; + } tv[] = + { + { { 0xb9, 0xca, 0x7f, 0xd6, 0xa0, 0xf5, 0xd3, 0x42, + 0x19, 0x6d, 0x84, 0x91, 0x76, 0x1c, 0x3b, 0xbe }, + { 0x48, 0xb2, 0x82, 0x98, 0x68, 0xc2, 0x80, 0x00, + 0x00, 0x00, 0x28, 0x18, 0x00, 0x00, 0x25, 0x00 }, + { 0x52, 0x17, 0x8d, 0x29, 0xa2, 0xd5, 0x84, 0x12, + 0x9d, 0x89, 0x9a, 0x45, 0x82, 0x02, 0xf7, 0x77 }, + { { 0x42, 0x9c, 0x08, 0x3d, 0x82, 0xf4, 0x8a, 0x40, + 0x66, 0xb5, 0x49, 0x27, 0xab, 0x42, 0xc7, 0xc3 }, + { 0x0e, 0xb7, 0x61, 0x3c, 0xfe, 0xb0, 0xbe, 0x73, + 0xf7, 0x6e, 0x6d, 0x6f, 0x1d, 0xa3, 0x14, 0xfa }, + { 0xbb, 0x4b, 0xc1, 0x0e, 0xc5, 0xfb, 0xcd, 0x46, + 0xbe, 0x28, 0x61, 0xe7, 0x03, 0x2b, 0x37, 0x7d } } }, + { { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, + { { 0xf7, 0x95, 0xbd, 0x4a, 0x52, 0xe2, 0x9e, 0xd7, + 0x13, 0xd3, 0x13, 0xfa, 0x20, 0xe9, 0x8d, 0xbc }, + { 0xc8, 0xd1, 0xe5, 0x11, 0x59, 0x52, 0xf7, 0xfa, + 0x37, 0x38, 0xb4, 0xc5, 0xce, 0xb2, 0xb0, 0x9a }, + { 0x0d, 0x9c, 0xc5, 0x0d, 0x16, 0xe1, 0xbc, 0xed, + 0xcf, 0x60, 0x62, 0x09, 0x9d, 0x20, 0x83, 0x7e } } }, + { { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, + 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f }, + { 0x80, 0x00, 0x81, 0x01, 0x82, 0x02, 0x83, 0x03, + 0xa0, 0x20, 0xa1, 0x21, 0xa2, 0x22, 0xa3, 0x23 }, + { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }, + { { 0x96, 0xed, 0xcc, 0xc3, 0xdd, 0x04, 0x7f, 0x75, + 0x63, 0x19, 0x37, 0x6f, 0x15, 0x22, 0x57, 0x56 }, + { 0x7a, 0x14, 0x76, 0x77, 0x95, 0x17, 0x7e, 0xc8, + 0x92, 0xe8, 0xdd, 0x15, 0xcb, 0x1f, 0xbc, 0xb1 }, + { 0x25, 0x3e, 0x2e, 0xa2, 0x41, 0x1b, 0xdd, 0xf5, + 0x21, 0x48, 0x41, 0x71, 0xb3, 0x8d, 0x2f, 0x4c } } } + }; + int tvidx, ridx; + rng_context_t test_ctx; + gpg_error_t err; + const char *errtxt = NULL; + unsigned char result[16]; + + gcry_assert (tempvalue_for_x931_aes_driver); + + test_ctx = gcry_xcalloc (1, sizeof *test_ctx); + setup_guards (test_ctx); + + lock_rng (); + + for (tvidx=0; tvidx < DIM (tv); tvidx++) + { + /* Setup the key. */ + err = gcry_cipher_open (&test_ctx->cipher_hd, + GCRY_CIPHER_AES128, GCRY_CIPHER_MODE_ECB, + GCRY_CIPHER_SECURE); + if (err) + { + errtxt = "error creating cipher context for RNG"; + goto leave; + } + + err = gcry_cipher_setkey (test_ctx->cipher_hd, tv[tvidx].key, 16); + if (err) + { + errtxt = "error setting key for RNG"; + goto leave; + } + test_ctx->key_init_pid = getpid (); + + /* Setup the seed. */ + memcpy (test_ctx->seed_V, tv[tvidx].v, 16); + test_ctx->is_seeded = 1; + test_ctx->seed_init_pid = getpid (); + + /* Setup a DT value. */ + test_ctx->test_dt_ptr = tv[tvidx].dt; + test_ctx->test_dt_counter = tv[tvidx].dt[15]; + + /* Get ant compare the first three results. */ + for (ridx=0; ridx < 3; ridx++) + { + /* Compute the next value. */ + if (x931_aes_driver (result, 16, test_ctx)) + { + errtxt = "X9.31 RNG core function failed"; + goto leave; + } + + /* Compare it to the known value. */ + if (memcmp (result, tv[tvidx].r[ridx], 16)) + { + /* log_printhex ("x931_aes got: ", result, 16); */ + /* log_printhex ("x931_aes exp: ", tv[tvidx].r[ridx], 16); */ + errtxt = "RNG output does not match known value"; + goto leave; + } + } + + /* This test is actual pretty pointless because we use a local test + context. */ + if (test_ctx->key_init_pid != getpid () + || test_ctx->seed_init_pid != getpid ()) + { + errtxt = "fork detection failed"; + goto leave; + } + + gcry_cipher_close (test_ctx->cipher_hd); + test_ctx->cipher_hd = NULL; + test_ctx->is_seeded = 0; + check_guards (test_ctx); + } + + leave: + unlock_rng (); + gcry_cipher_close (test_ctx->cipher_hd); + check_guards (test_ctx); + gcry_free (test_ctx); + if (report && errtxt) + report ("random", 0, "KAT", errtxt); + return errtxt? GPG_ERR_SELFTEST_FAILED : 0; +} + + /* Run the self-tests. */ gcry_error_t _gcry_rngfips_selftest (selftest_report_func_t report) { - gcry_err_code_t ec = 0; + gcry_err_code_t ec; char buffer[8]; - /* Do a simple test using the public interface. */ + /* Do a simple test using the public interface. This will also + enforce full intialization of the RNG. We need to be fully + initialized due to the global requirement of the + tempvalue_for_x931_aes_driver stuff. */ gcry_randomize (buffer, sizeof buffer, GCRY_STRONG_RANDOM); + ec = selftest_kat (report); return gpg_error (ec); } From cvs at cvs.gnupg.org Tue Aug 26 13:14:01 2008 From: cvs at cvs.gnupg.org (svn author wk) Date: Tue, 26 Aug 2008 13:14:01 +0200 Subject: [svn] gcry - r1306 - in trunk: . cipher doc src tests Message-ID: Author: wk Date: 2008-08-26 13:13:57 +0200 (Tue, 26 Aug 2008) New Revision: 1306 Modified: trunk/NEWS trunk/TODO trunk/cipher/ChangeLog trunk/cipher/primegen.c trunk/cipher/pubkey.c trunk/cipher/rsa.c trunk/doc/gcrypt.texi trunk/src/ChangeLog trunk/src/cipher-proto.h trunk/src/cipher.h trunk/src/fips.c trunk/src/g10lib.h trunk/src/global.c trunk/tests/ChangeLog trunk/tests/basic.c trunk/tests/benchmark.c Log: Implemented transient-key flag as requested by the GNUNet folks. Documentation cleanups. Removed FIPS logging unless in double verbose state. [The diff below has been truncated] Modified: trunk/cipher/ChangeLog =================================================================== --- trunk/cipher/ChangeLog 2008-08-25 11:15:35 UTC (rev 1305) +++ trunk/cipher/ChangeLog 2008-08-26 11:13:57 UTC (rev 1306) @@ -1,3 +1,17 @@ +2008-08-26 Werner Koch + + * pubkey.c (pubkey_generate): Add arg KEYGEN_FLAGS. + (gcry_pk_genkey): Implement new parameter "transient-key" and + pass it as flags to pubkey_generate. + (pubkey_generate): Make use of an ext_generate function. + * rsa.c (generate): Add new arg transient_key and pass appropriate + args to the prime generator. + (_gcry_rsa_generate): Factor all code out to ... + (rsa_generate): .. new func with extra arg KEYGEN_FLAGS. + (_gcry_pubkey_extraspec_ecdsa): Setup rsa_generate. + * primegen.c (_gcry_generate_secret_prime) + (_gcry_generate_public_prime): Add new arg RANDOM_LEVEL. + 2008-08-21 Werner Koch * primegen.c (_gcry_generate_secret_prime) Modified: trunk/src/ChangeLog =================================================================== --- trunk/src/ChangeLog 2008-08-25 11:15:35 UTC (rev 1305) +++ trunk/src/ChangeLog 2008-08-26 11:13:57 UTC (rev 1306) @@ -1,3 +1,13 @@ +2008-08-26 Werner Koch + + * fips.c (fips_new_state): Print state transitions only at + verbosity level of 2. + (reporter): Likewise. + + * cipher-proto.h (pk_ext_generate_t): New. + (pk_extra_spec): Add member ext_generate. + * cipher.h (PUBKEY_FLAG_TRANSIENT_KEY): New. + 2008-08-22 Werner Koch * hmac256.c (_gcry_hmac256_file): New. Modified: trunk/tests/ChangeLog =================================================================== --- trunk/tests/ChangeLog 2008-08-25 11:15:35 UTC (rev 1305) +++ trunk/tests/ChangeLog 2008-08-26 11:13:57 UTC (rev 1306) @@ -1,3 +1,10 @@ +2008-08-26 Werner Koch + + * basic.c (get_keys_new): Use transient-key flag. + * benchmark.c (main): First check options then do the libgcrypt + initialization. + (rsa_bench): Use transient-key flag if not in fips mode. + 2008-08-20 Werner Koch * t-mpi-bit.c (test_lshift): New. Modified: trunk/NEWS =================================================================== --- trunk/NEWS 2008-08-25 11:15:35 UTC (rev 1305) +++ trunk/NEWS 2008-08-26 11:13:57 UTC (rev 1306) @@ -1,8 +1,7 @@ Noteworthy changes in version 1.4.2 (unreleased) ------------------------------------------------ - * The library may now be switched into a FIPS mode. Note that this - mode is not yet fully working in 1.4.2rc1. + * The library may now be switched into a FIPS mode. * More runtime selftests. @@ -14,6 +13,8 @@ * The long missing gcry_mpi_lshift function has been added. + * RSA key generation now supports a "transient-key" flag. + * Interface changes relative to the 1.3.0 release: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ GCRYCTL_OPERATIONAL_P NEW. Modified: trunk/TODO =================================================================== --- trunk/TODO 2008-08-25 11:15:35 UTC (rev 1305) +++ trunk/TODO 2008-08-26 11:13:57 UTC (rev 1306) @@ -66,16 +66,6 @@ collectros need to run that bunch of Unix utilities we don't waste their precious results. -* Add transient flag to RSA key generation - For short living keys it makes sense to allow generation using a PRNG. - We could implement it this way: - - (genkey - (rsa - (nbits 4:1024) - (transient-key))) - - * Out of memory handler for secure memory should do proper logging There is no shortage of standard memory, so logging is most likely Modified: trunk/cipher/primegen.c =================================================================== --- trunk/cipher/primegen.c 2008-08-25 11:15:35 UTC (rev 1305) +++ trunk/cipher/primegen.c 2008-08-26 11:13:57 UTC (rev 1306) @@ -240,26 +240,29 @@ */ gcry_mpi_t _gcry_generate_secret_prime (unsigned int nbits, + gcry_random_level_t random_level, int (*extra_check)(void*, gcry_mpi_t), void *extra_check_arg) { gcry_mpi_t prime; - prime = gen_prime (nbits, 1, GCRY_VERY_STRONG_RANDOM, - extra_check, extra_check_arg); + prime = gen_prime (nbits, 1, random_level, extra_check, extra_check_arg); progress('\n'); return prime; } + +/* Generate a prime number which may be public, i.e. not allocated in + secure memory. */ gcry_mpi_t -_gcry_generate_public_prime( unsigned int nbits, +_gcry_generate_public_prime (unsigned int nbits, + gcry_random_level_t random_level, int (*extra_check)(void*, gcry_mpi_t), void *extra_check_arg) { gcry_mpi_t prime; - prime = gen_prime (nbits, 0, GCRY_VERY_STRONG_RANDOM, - extra_check, extra_check_arg ); + prime = gen_prime (nbits, 0, random_level, extra_check, extra_check_arg); progress('\n'); return prime; } @@ -730,7 +733,8 @@ } - +/* Generate a prime used for discrete logarithm algorithms; i.e. this + prime will be public and no strong random is required. */ gcry_mpi_t _gcry_generate_elg_prime (int mode, unsigned pbits, unsigned qbits, gcry_mpi_t g, gcry_mpi_t **ret_factors) @@ -745,6 +749,7 @@ return prime; } + static gcry_mpi_t gen_prime (unsigned int nbits, int secret, int randomlevel, int (*extra_check)(void *, gcry_mpi_t), void *extra_check_arg) Modified: trunk/cipher/pubkey.c =================================================================== --- trunk/cipher/pubkey.c 2008-08-25 11:15:35 UTC (rev 1305) +++ trunk/cipher/pubkey.c 2008-08-26 11:13:57 UTC (rev 1306) @@ -29,6 +29,7 @@ #include "cipher.h" #include "ath.h" + static gcry_err_code_t pubkey_decrypt (int algo, gcry_mpi_t *result, gcry_mpi_t *data, gcry_mpi_t *skey, int flags); @@ -530,18 +531,18 @@ /* Generate a new public key with algorithm ALGORITHM of size NBITS and return it at SKEY. The use of the arguments QBITS, USE_E, - XVALUE and CURVE+_NAME depend onthe ALGORITHM. RETFACTOR is used + XVALUE and CURVE_NAME depend on the ALGORITHM. RETFACTOR is used by some algorithms to return certain additional information which - are in general not required. + are in general not required. - The function returns ther error code number or 0 on success. */ + The function returns the error code number or 0 on success. */ static gcry_err_code_t pubkey_generate (int algorithm, unsigned int nbits, unsigned int qbits, unsigned long use_e, gcry_mpi_t xvalue, - const char *curve_name, + const char *curve_name, unsigned int keygen_flags, gcry_mpi_t *skey, gcry_mpi_t **retfactors) { - gcry_err_code_t err = GPG_ERR_PUBKEY_ALGO; + gcry_err_code_t ec = GPG_ERR_PUBKEY_ALGO; gcry_module_t pubkey; REGISTER_DEFAULT_PUBKEYS; @@ -550,36 +551,57 @@ pubkey = _gcry_module_lookup_id (pubkeys_registered, algorithm); if (pubkey) { - /* Hack to pass QBITS to the DSA generation. */ - if (qbits && pubkey->spec == &_gcry_pubkey_spec_dsa) + pk_extra_spec_t *extraspec = pubkey->extraspec; + + if (keygen_flags && (!extraspec || !extraspec->ext_generate)) { - err = _gcry_dsa_generate2 + /* A keygen flag has been given but the module does not + provide an ext_generate function. We don't want to + ignore such a condition as it might eventually be + security sensitive.. */ + ec = GPG_ERR_INV_FLAG; + } + else if (qbits && pubkey->spec == &_gcry_pubkey_spec_dsa) + { + /* Hack to pass QBITS to the DSA generation. fixme: We + should merge this into an ext_generate fucntion. */ + ec = _gcry_dsa_generate2 (algorithm, nbits, qbits, 0, skey, retfactors); } #ifdef USE_ELGAMAL else if (xvalue && pubkey->spec == &_gcry_pubkey_spec_elg) { - err = _gcry_elg_generate_using_x + /* Fixme: Merge this into an ext_generate fucntion. */ + ec = _gcry_elg_generate_using_x (algorithm, nbits, xvalue, skey, retfactors); } #endif /*USE_ELGAMAL*/ #ifdef USE_ECC else if (curve_name && pubkey->spec == &_gcry_pubkey_spec_ecdsa) { - err = _gcry_ecc_generate + /* Fixme: Merge this into an ext_generate fucntion. */ + ec = _gcry_ecc_generate (algorithm, nbits, curve_name, skey, retfactors); } #endif /*USE_ECC*/ + else if (extraspec && extraspec->ext_generate) + { + /* Use the extended generate function if available. */ + ec = extraspec->ext_generate (algorithm, nbits, use_e, + keygen_flags, + skey, retfactors); + } else { - err = ((gcry_pk_spec_t *) pubkey->spec)->generate + /* Use the standard generate function. */ + ec = ((gcry_pk_spec_t *) pubkey->spec)->generate (algorithm, nbits, use_e, skey, retfactors); } _gcry_module_release (pubkey); } ath_mutex_unlock (&pubkeys_registered_lock); - return err; + return ec; } static gcry_err_code_t @@ -2075,6 +2097,7 @@ unsigned int qbits; gcry_mpi_t xvalue = NULL; char *curve = NULL; + unsigned int keygen_flags = 0; skey[0] = NULL; *r_key = NULL; @@ -2182,7 +2205,7 @@ } } - /* Handle the optional "curve" parameter. */ + /* Parse the optional "curve" parameter. */ l2 = gcry_sexp_find_token (list, "curve", 0); if (l2) { @@ -2196,7 +2219,16 @@ l2 = NULL; } + /* Parse the optional "transient-key" flag. */ + l2 = gcry_sexp_find_token (list, "transient-key", 0); + if (l2) + { + keygen_flags |= PUBKEY_FLAG_TRANSIENT_KEY; + gcry_sexp_release (l2); + l2 = NULL; + } + /* Unless a curve name has been given, the "nbits" parameter is required. */ l2 = gcry_sexp_find_token (list, "nbits", 0); @@ -2227,7 +2259,7 @@ nbits = 0; rc = pubkey_generate (module->mod_id, nbits, qbits, use_e, xvalue, - curve, skey, &factors); + curve, keygen_flags, skey, &factors); if (rc) goto leave; @@ -2693,7 +2725,7 @@ _gcry_pk_selftest (int algo, selftest_report_func_t report) { gcry_module_t module = NULL; - cipher_extra_spec_t *extraspec = NULL; + pk_extra_spec_t *extraspec = NULL; gcry_err_code_t ec = 0; REGISTER_DEFAULT_PUBKEYS; Modified: trunk/cipher/rsa.c =================================================================== --- trunk/cipher/rsa.c 2008-08-25 11:15:35 UTC (rev 1305) +++ trunk/cipher/rsa.c 2008-08-26 11:13:57 UTC (rev 1306) @@ -54,7 +54,8 @@ static void test_keys (RSA_secret_key *sk, unsigned nbits); static gpg_err_code_t generate (RSA_secret_key *sk, - unsigned int nbits, unsigned long use_e); + unsigned int nbits, unsigned long use_e, + int transient_key); static int check_secret_key (RSA_secret_key *sk); static void public (gcry_mpi_t output, gcry_mpi_t input, RSA_public_key *skey); static void secret (gcry_mpi_t output, gcry_mpi_t input, RSA_secret_key *skey); @@ -109,10 +110,12 @@ * = 1 request the use of a "secure" exponent; this is required by some * specification to be 65537. * > 2 Try starting at this value until a working exponent is found. + * TRANSIENT_KEY: If true, generate the primes using the standard RNG. * Returns: 2 structures filled with all needed values */ static gpg_err_code_t -generate (RSA_secret_key *sk, unsigned int nbits, unsigned long use_e) +generate (RSA_secret_key *sk, unsigned int nbits, unsigned long use_e, + int transient_key) { gcry_mpi_t p, q; /* the two primes */ gcry_mpi_t d; /* the private key */ @@ -123,10 +126,19 @@ gcry_mpi_t phi; /* helper: (p-1)(q-1) */ gcry_mpi_t g; gcry_mpi_t f; + gcry_random_level_t random_level; - if ( nbits < 1024 && fips_mode ()) - return GPG_ERR_INV_VALUE; + if (fips_mode ()) + { + if (nbits < 1024) + return GPG_ERR_INV_VALUE; + if (transient_key) + return GPG_ERR_INV_VALUE; + } + /* The random quality depends on the transient_key flag. */ + random_level = transient_key ? GCRY_STRONG_RANDOM : GCRY_VERY_STRONG_RANDOM; + /* Make sure that nbits is even so that we generate p, q of equal size. */ if ( (nbits&1) ) nbits++; @@ -165,13 +177,15 @@ if (use_e) { /* Do an extra test to ensure that the given exponent is suitable. */ - p = _gcry_generate_secret_prime (nbits/2, check_exponent, e); - q = _gcry_generate_secret_prime (nbits/2, check_exponent, e); + p = _gcry_generate_secret_prime (nbits/2, random_level, + check_exponent, e); + q = _gcry_generate_secret_prime (nbits/2, random_level, + check_exponent, e); } else { /* We check the exponent later. */ - p = _gcry_generate_secret_prime (nbits/2, NULL, NULL); - q = _gcry_generate_secret_prime (nbits/2, NULL, NULL); + p = _gcry_generate_secret_prime (nbits/2, random_level, NULL, NULL); + q = _gcry_generate_secret_prime (nbits/2, random_level, NULL, NULL); } if (mpi_cmp (p, q) > 0 ) /* p shall be smaller than q (for calc of u)*/ mpi_swap(p,q); @@ -441,9 +455,10 @@ ************** interface ****************** *********************************************/ -gcry_err_code_t -_gcry_rsa_generate (int algo, unsigned int nbits, unsigned long use_e, - gcry_mpi_t *skey, gcry_mpi_t **retfactors) +static gcry_err_code_t +rsa_generate (int algo, unsigned int nbits, unsigned long use_e, + unsigned int keygen_flags, + gcry_mpi_t *skey, gcry_mpi_t **retfactors) { RSA_secret_key sk; gpg_err_code_t ec; @@ -451,7 +466,8 @@ (void)algo; - ec = generate (&sk, nbits, use_e); + ec = generate (&sk, nbits, use_e, + !!(keygen_flags & PUBKEY_FLAG_TRANSIENT_KEY) ); if (!ec) { skey[0] = sk.n; @@ -481,6 +497,14 @@ gcry_err_code_t +_gcry_rsa_generate (int algo, unsigned int nbits, unsigned long use_e, + gcry_mpi_t *skey, gcry_mpi_t **retfactors) +{ + return rsa_generate (algo, nbits, use_e, 0, skey, retfactors); +} + + +gcry_err_code_t _gcry_rsa_check_secret_key( int algo, gcry_mpi_t *skey ) { gcry_err_code_t err = GPG_ERR_NO_ERROR; @@ -736,6 +760,7 @@ }; pk_extra_spec_t _gcry_pubkey_extraspec_rsa = { - run_selftests + run_selftests, + rsa_generate }; Modified: trunk/doc/gcrypt.texi =================================================================== --- trunk/doc/gcrypt.texi 2008-08-25 11:15:35 UTC (rev 1305) +++ trunk/doc/gcrypt.texi 2008-08-26 11:13:57 UTC (rev 1306) @@ -539,16 +539,18 @@ @item If the applications requests FIPS mode using the control command - at code{GCRYCTL_FORCE_FIPS_MODE}. This may be done at any time. + at code{GCRYCTL_FORCE_FIPS_MODE}. This must be done prior to any +initialization (i.e. before @code{gcry_check_version}). @end itemize Note that once Libgcrypt has been put into FIPS mode, it is not possible to switch back to standard mode without terminating the process first. +If the log verbosity level of Libgcrypt has been set to at least 2, the +state transitions and the selftests are logged. - @c ********************************************************** @c ******************* General **************************** @c ********************************************************** @@ -689,7 +691,8 @@ all extra logging whereas positive numbers enable more verbose logging. The level may be changed at any time but be aware that no memory syncronization is done so the effect of this command might not -immediately show up in other threads. +immediately show up in other threads. This command may even be used +prioe to @code{gcry_check_version}. @item GCRYCTL_SET_DEBUG_FLAGS; Arguments: unsigned int flags Set the debug flag bits as given by the argument. Be aware that that no @@ -697,12 +700,14 @@ immediately show up in other threads. The debug flags are not considered part of the API and thus may change without notice. As of now bit 0 enables debugging of cipher functions and bit 1 debugging of -multi-precision-integers. +multi-precision-integers. This command may even be used prioe to + at code{gcry_check_version}. @item GCRYCTL_CLEAR_DEBUG_FLAGS; Arguments: unsigned int flags Set the debug flag bits as given by the argument. Be aware that that no memory syncronization is done so the effect of this command might not -immediately show up in other threads. +immediately show up in other threads. This command may even be used +prioe to @code{gcry_check_version}. @item GCRYCTL_DISABLE_INTERNAL_LOCKING; Arguments: none This command does nothing. It exists only for backward compatibility. @@ -758,12 +763,12 @@ before a gcry_version_check. @item GCRYCTL_FORCE_FIPS_MODE; Arguments: none -Running this command puts the library into FIPS mode. If the library -has already been initialized or is already in FIPS mode, a selftest is -triggered and thus the library will be put into operational state. This -command may even be used before a call to gcry_check_version and that is -actually the recommended way to let an application switch the library -into FIPS mode. +Running this command puts the library into FIPS mode. If the library is +already in FIPS mode, a selftest is triggered and thus the library will +be put into operational state. This command may be used before a call +to gcry_check_version and that is actually the recommended way to let an +application switch the library into FIPS mode. Note that Libgcrypt will +reject an attempt to switch to fips mode during or after the intialization. @end table @@ -1279,8 +1284,8 @@ @section Error handler The following functions may be used to register handler functions that -are called by Libgcrypt in case certain error conditions -occur. +are called by Libgcrypt in case certain error conditions occur. They +may and should be registered prior to calling @code{gcry_check_version}. @deftp {Data type} gcry_handler_no_mem_t This type is defined as: @code{void (*gcry_handler_no_mem_t) (void *, size_t, unsigned int)} @@ -1308,9 +1313,10 @@ @end deftp @deftypefun void gcry_set_log_handler (gcry_handler_log_t @var{func_log}, void *@var{cb_data}) -This function registers @var{func_log} as `logging handler', which -means that it will be called in case Libgcrypt wants to log -a message. +This function registers @var{func_log} as `logging handler', which means +that it will be called in case Libgcrypt wants to log a message. This +function may and should be used prior to calling + at code{gcry_check_version}. @end deftypefun @c ********************************************************** @@ -2621,6 +2627,13 @@ are allowed. When specifying Q all values of N in the range 512 to 15680 are valid as long as they are multiples of 8. + at item transient-key +This is only meaningful for RSA keys. This is a flag with no value. If +given the RSA key is created using a faster and a somewhat less secure +random number generator. This flag may be used for keys which are only +used for a short time and do not require full cryptograohic strength. + + @end table @c end table of parameters Modified: trunk/src/cipher-proto.h =================================================================== --- trunk/src/cipher-proto.h 2008-08-25 11:15:35 UTC (rev 1305) +++ trunk/src/cipher-proto.h 2008-08-26 11:13:57 UTC (rev 1306) @@ -39,6 +39,16 @@ (int algo, selftest_report_func_t report); +/* An extended type of the generate function. */ +typedef gcry_err_code_t (*pk_ext_generate_t) + (int algo, + unsigned int nbits, From cvs at cvs.gnupg.org Wed Aug 27 07:58:30 2008 From: cvs at cvs.gnupg.org (svn author dshaw) Date: Wed, 27 Aug 2008 07:58:30 +0200 Subject: [svn] GnuPG - r4817 - trunk Message-ID: Author: dshaw Date: 2008-08-27 07:58:30 +0200 (Wed, 27 Aug 2008) New Revision: 4817 Modified: trunk/ChangeLog trunk/configure.ac Log: * configure.ac: Darwin's /bin/sh has a builtin echo that doesn't understand '-n'. Use tr to trim the carriage return instead. Modified: trunk/ChangeLog =================================================================== --- trunk/ChangeLog 2008-08-19 19:36:42 UTC (rev 4816) +++ trunk/ChangeLog 2008-08-27 05:58:30 UTC (rev 4817) @@ -1,3 +1,8 @@ +2008-08-27 David Shaw + + * configure.ac: Darwin's /bin/sh has a builtin echo that doesn't + understand '-n'. Use tr to trim the carriage return instead. + 2008-04-23 Werner Koch * configure.ac: Call gl_HEADER_SYS_SOCKET and gl_TYPE_SOCKLEN_T. Modified: trunk/configure.ac =================================================================== --- trunk/configure.ac 2008-08-19 19:36:42 UTC (rev 4816) +++ trunk/configure.ac 2008-08-27 05:58:30 UTC (rev 4817) @@ -28,8 +28,9 @@ m4_define([my_issvn], [yes]) -m4_define([svn_revision], m4_esyscmd([echo -n $( (svn info 2>/dev/null \ - || echo 'Revision: 0')|sed -n '/^Revision:/ {s/[^0-9]//gp;q;}')])) +m4_define([svn_revision], m4_esyscmd([echo $((svn info 2>/dev/null \ + || echo 'Revision: 0')|sed -n '/^Revision:/ s/[^0-9]//gp'|head -1)| \ + tr -d '\n'])) AC_INIT([gnupg], [my_version[]m4_if(my_issvn,[yes],[-svn[]svn_revision])], [bug-gnupg at gnupg.org]) From cvs at cvs.gnupg.org Wed Aug 27 12:10:48 2008 From: cvs at cvs.gnupg.org (svn author wk) Date: Wed, 27 Aug 2008 12:10:48 +0200 Subject: [svn] gcry - r1307 - in trunk: cipher src tests Message-ID: Author: wk Date: 2008-08-27 12:10:47 +0200 (Wed, 27 Aug 2008) New Revision: 1307 Modified: trunk/cipher/md.c trunk/src/ChangeLog trunk/src/Makefile.am trunk/src/fips.c trunk/src/g10lib.h trunk/src/global.c trunk/tests/ChangeLog trunk/tests/basic.c Log: Allow getting out of the FIPS error state by running a self-test. Modified: trunk/src/ChangeLog =================================================================== --- trunk/src/ChangeLog 2008-08-26 11:13:57 UTC (rev 1306) +++ trunk/src/ChangeLog 2008-08-27 10:10:47 UTC (rev 1307) @@ -1,3 +1,11 @@ +2008-08-27 Werner Koch + + * global.c (_gcry_vcontrol): Allow running selftests from error + state. + * fips.c (_gcry_fips_test_error_or_operational): New. + (fips_new_state): Allow transtion from error into selftest. + Disallow error to init. + 2008-08-26 Werner Koch * fips.c (fips_new_state): Print state transitions only at Modified: trunk/tests/ChangeLog =================================================================== --- trunk/tests/ChangeLog 2008-08-26 11:13:57 UTC (rev 1306) +++ trunk/tests/ChangeLog 2008-08-27 10:10:47 UTC (rev 1307) @@ -1,3 +1,7 @@ +2008-08-27 Werner Koch + + * basic.c (main): Extended FIPS self-test test. + 2008-08-26 Werner Koch * basic.c (get_keys_new): Use transient-key flag. Modified: trunk/cipher/md.c =================================================================== --- trunk/cipher/md.c 2008-08-26 11:13:57 UTC (rev 1306) +++ trunk/cipher/md.c 2008-08-27 10:10:47 UTC (rev 1307) @@ -1011,7 +1011,7 @@ if (r && r->next) { fips_signal_error ("possible usage error"); - log_error ("WARNING: more than algorithm in md_get_algo()\n"); + log_error ("WARNING: more than one algorithm in md_get_algo()\n"); } return r ? r->module->mod_id : 0; } Modified: trunk/src/Makefile.am =================================================================== --- trunk/src/Makefile.am 2008-08-26 11:13:57 UTC (rev 1306) +++ trunk/src/Makefile.am 2008-08-27 10:10:47 UTC (rev 1307) @@ -122,9 +122,9 @@ uninstall-local: uninstall-def-file -# FIXME: We ned to figure out how to gte the actual name (parsing +# FIXME: We need to figure out how to get the actual name (parsing # libgcrypt.la?) and how to create the hmac file already at link time -# so that it can be used without first installing. +# so that it can be used without installing libgcrypt first. #install-exec-hook: # ./hmac256 --binary "What am I, a doctor or a moonshuttle conductor?" \ # $(DESTDIR)$(libdir)/libgcrypt.so.11.5.0 \ Modified: trunk/src/fips.c =================================================================== --- trunk/src/fips.c 2008-08-26 11:13:57 UTC (rev 1306) +++ trunk/src/fips.c 2008-08-27 10:10:47 UTC (rev 1307) @@ -289,6 +289,26 @@ } +/* This is a test on whether the library is in the error or + operational state. */ +int +_gcry_fips_test_error_or_operational (void) +{ + int result; + + if (!fips_mode ()) + result = 1; + else + { + lock_fsm (); + result = (current_state == STATE_OPERATIONAL + || current_state == STATE_ERROR); + unlock_fsm (); + } + return result; +} + + static void reporter (const char *domain, int algo, const char *what, const char *errtxt) { @@ -604,7 +624,7 @@ case STATE_ERROR: if (new_state == STATE_SHUTDOWN || new_state == STATE_FATALERROR - || new_state == STATE_INIT) + || new_state == STATE_SELFTEST) ok = 1; break; Modified: trunk/src/g10lib.h =================================================================== --- trunk/src/g10lib.h 2008-08-26 11:13:57 UTC (rev 1306) +++ trunk/src/g10lib.h 2008-08-27 10:10:47 UTC (rev 1307) @@ -314,6 +314,7 @@ #define fips_not_operational() (GCRY_GPG_ERR_NOT_OPERATIONAL) int _gcry_fips_test_operational (void); +int _gcry_fips_test_error_or_operational (void); void _gcry_fips_run_selftests (void); Modified: trunk/src/global.c =================================================================== --- trunk/src/global.c 2008-08-26 11:13:57 UTC (rev 1306) +++ trunk/src/global.c 2008-08-27 10:10:47 UTC (rev 1307) @@ -469,7 +469,7 @@ /* Already initialized. If we are already operational we run a selftest. If not we use the is_operational call to force us into operational state if possible. */ - if (_gcry_fips_test_operational ()) + if (_gcry_fips_test_error_or_operational ()) _gcry_fips_run_selftests (); if (_gcry_fips_is_operational ()) err = GPG_ERR_GENERAL; /* Used as TRUE value */ Modified: trunk/tests/basic.c =================================================================== --- trunk/tests/basic.c 2008-08-26 11:13:57 UTC (rev 1306) +++ trunk/tests/basic.c 2008-08-27 10:10:47 UTC (rev 1307) @@ -2042,6 +2042,7 @@ int main (int argc, char **argv) { + gpg_error_t err; int last_argc = -1; int debug = 0; int use_fips = 0; @@ -2105,10 +2106,50 @@ check_hmac (); check_pubkey (); - /* If we are in fips mode, trigger a selftest. */ + /* If we are in fips mode do some more tests. */ if (in_fips_mode) - gcry_control (GCRYCTL_FORCE_FIPS_MODE, 0); + { + gcry_md_hd_t md; + /* First trigger a self-test. */ + gcry_control (GCRYCTL_FORCE_FIPS_MODE, 0); + if (!gcry_control (GCRYCTL_OPERATIONAL_P, 0)) + fail ("not in operational state after self-test\n"); + + /* Get us into the error state. */ + err = gcry_md_open (&md, GCRY_MD_SHA1, 0); + if (err) + fail ("failed to open SHA-1 hash context: %s\n", gpg_strerror (err)); + else + { + err = gcry_md_enable (md, GCRY_MD_SHA256); + if (err) + fail ("failed to add SHA-256 hash context: %s\n", + gpg_strerror (err)); + else + { + /* gcry_md_get_algo is only defined for a context with + just one digest algorithm. With our setup it should + put the oibrary intoerror state. */ + gcry_md_get_algo (md); + gcry_md_close (md); + if (gcry_control (GCRYCTL_OPERATIONAL_P, 0)) + fail ("expected error state but still in operational state\n"); + else + { + /* Now run a self-test and to get back into + operational state. */ + gcry_control (GCRYCTL_FORCE_FIPS_MODE, 0); + if (!gcry_control (GCRYCTL_OPERATIONAL_P, 0)) + fail ("did not reach operational after error " + "and self-test\n"); + } + } + } + + } + + if (verbose) fprintf (stderr, "\nAll tests completed. Errors: %i\n", error_count); From cvs at cvs.gnupg.org Wed Aug 27 15:19:28 2008 From: cvs at cvs.gnupg.org (svn author wk) Date: Wed, 27 Aug 2008 15:19:28 +0200 Subject: [svn] gcry - r1308 - trunk/doc Message-ID: Author: wk Date: 2008-08-27 15:19:27 +0200 (Wed, 27 Aug 2008) New Revision: 1308 Added: trunk/doc/fips-fsm.fig Modified: trunk/doc/Makefile.am trunk/doc/gcrypt.texi Log: Add description of the FIPS FSM. Modified: trunk/doc/Makefile.am =================================================================== --- trunk/doc/Makefile.am 2008-08-27 10:10:47 UTC (rev 1307) +++ trunk/doc/Makefile.am 2008-08-27 13:19:27 UTC (rev 1308) @@ -18,18 +18,18 @@ # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA EXTRA_DIST = README.apichanges HACKING \ - libgcrypt-modules.eps \ - libgcrypt-modules.png \ - libgcrypt-modules.pdf + libgcrypt-modules.eps fips-fsm.eps \ + libgcrypt-modules.png fips-fsm.png \ + libgcrypt-modules.pdf fips-fsm.pdf DISTCLEANFILES = gcrypt.cps -BUILT_SOURCES = libgcrypt-modules.eps \ - libgcrypt-modules.png \ - libgcrypt-modules.pdf +BUILT_SOURCES = libgcrypt-modules.eps fips-fsm.eps \ + libgcrypt-modules.png fips-fsm.png \ + libgcrypt-modules.pdf fips-fsm.pdf info_TEXINFOS = gcrypt.texi -gcrypt_TEXINFOS = lgpl.texi gpl.texi libgcrypt-modules.fig +gcrypt_TEXINFOS = lgpl.texi gpl.texi libgcrypt-modules.fig fips-fsm.fig .fig.png: Added: trunk/doc/fips-fsm.fig =================================================================== --- trunk/doc/fips-fsm.fig 2008-08-27 10:10:47 UTC (rev 1307) +++ trunk/doc/fips-fsm.fig 2008-08-27 13:19:27 UTC (rev 1308) @@ -0,0 +1,182 @@ +#FIG 3.2 Produced by xfig version 3.2.5-alpha5 +Portrait +Center +Metric +A4 +100.00 +Single +-2 +1200 2 +0 32 #9c0000 +0 33 #8c8c8c +0 34 #8c8c8c +0 35 #424242 +0 36 #8c8c8c +0 37 #424242 +0 38 #8c8c8c +0 39 #424242 +0 40 #8c8c8c +0 41 #424242 +0 42 #8c8c8c +0 43 #424242 +6 900 270 8775 9450 +6 900 270 8775 9450 +5 1 0 2 0 7 50 -1 -1 0.000 1 1 1 0 4837.500 16740.000 6750 6705 4725 6525 2925 6705 + 1 1 2.00 120.00 240.00 +5 1 0 2 0 7 50 -1 -1 0.000 1 1 1 0 3026.138 8399.825 4185 8370 3870 7605 2925 7245 + 1 1 2.00 120.00 240.00 +6 3600 8370 5985 9450 +2 4 0 1 0 7 50 -1 -1 0.000 0 0 20 0 0 5 + 5970 9450 3600 9450 3600 8370 5970 8370 5970 9450 +4 0 0 50 -1 0 24 0.0000 4 360 1965 3870 9000 Operational\001 +-6 +6 900 4320 2970 5445 +2 4 0 1 0 7 50 -1 -1 0.000 0 0 20 0 0 5 + 2940 5445 915 5445 915 4335 2940 4335 2940 5445 +4 0 0 50 -1 0 24 0.0000 4 270 585 1620 4995 Init\001 +-6 +6 900 6345 2970 7470 +2 4 0 1 0 7 50 -1 -1 0.000 0 0 20 0 0 5 + 2955 7455 930 7455 930 6345 2955 6345 2955 7455 +4 0 0 50 -1 0 24 0.0000 4 270 1515 1215 7020 Self-Test\001 +-6 +6 6750 6345 8775 7470 +2 4 0 1 0 7 50 -1 -1 0.000 0 0 20 0 0 5 + 8775 7470 6750 7470 6750 6360 8775 6360 8775 7470 +4 0 0 50 -1 0 24 0.0000 4 270 870 7335 7020 Error\001 +-6 +6 3825 4320 5850 5445 +2 4 0 1 0 7 50 -1 -1 0.000 0 0 20 0 0 5 + 5850 5445 3825 5445 3825 4335 5850 4335 5850 5445 +4 0 0 50 -1 0 24 0.0000 4 270 1830 3915 4995 Fatal-Error\001 +-6 +6 6750 2295 8775 3420 +2 4 0 1 0 7 50 -1 -1 0.000 0 0 20 0 0 5 + 8775 3420 6750 3420 6750 2310 8775 2310 8775 3420 +4 0 0 50 -1 0 24 0.0000 4 270 1695 6930 2970 Shutdown\001 +-6 +6 2475 2295 4500 3420 +2 4 0 1 0 7 50 -1 -1 0.000 0 0 20 0 0 5 + 4500 3405 2475 3405 2475 2295 4500 2295 4500 3405 +4 0 0 50 -1 0 24 0.0000 4 270 1695 2655 2970 Power-On\001 +-6 +6 2475 270 4500 1395 +2 4 0 1 0 7 50 -1 -1 0.000 0 0 20 0 0 5 + 4500 1395 2475 1395 2475 285 4500 285 4500 1395 +4 0 0 50 -1 0 24 0.0000 4 270 1755 2565 945 Power-Off\001 +-6 +2 1 0 2 0 7 50 -1 -1 0.000 0 1 -1 1 0 2 + 1 1 2.00 120.00 240.00 + 3420 1395 3420 2295 +2 1 0 2 0 7 50 -1 -1 0.000 0 1 -1 1 0 2 + 1 1 2.00 120.00 240.00 + 3465 3420 4815 4320 +2 1 0 2 0 7 50 -1 -1 0.000 0 1 -1 1 0 2 + 1 1 2.00 120.00 240.00 + 1890 5445 1890 6345 +2 1 0 2 0 7 50 -1 -1 0.000 0 1 -1 1 0 2 + 1 1 2.00 120.00 240.00 + 2835 7380 3735 8415 +2 1 0 2 0 7 50 -1 -1 0.000 0 1 -1 1 0 2 + 1 1 2.00 120.00 240.00 + 4725 8370 4725 5490 +2 1 0 2 0 7 50 -1 -1 0.000 0 1 -1 1 0 2 + 1 1 2.00 120.00 240.00 + 4950 8370 7335 3420 +2 1 0 2 0 7 50 -1 -1 0.000 0 1 -1 1 0 2 + 1 1 2.00 120.00 240.00 + 2925 6930 6750 6930 +2 1 0 2 0 7 50 -1 -1 0.000 0 1 -1 1 0 2 + 1 1 2.00 120.00 240.00 + 2880 6480 3915 5355 +2 1 0 2 0 7 50 -1 -1 0.000 0 1 -1 1 0 2 + 1 1 2.00 120.00 240.00 + 4500 2835 6750 2835 +2 1 0 2 0 7 50 -1 -1 0.000 0 1 -1 1 0 2 + 1 1 2.00 120.00 240.00 + 7740 6345 7740 3420 +2 1 0 2 0 7 50 -1 -1 0.000 0 1 -1 1 0 2 + 1 1 2.00 120.00 240.00 + 3375 3420 1890 4320 +2 1 0 2 0 7 50 -1 -1 0.000 0 1 -1 1 0 2 + 1 1 2.00 120.00 240.00 + 5760 4410 6840 3330 +2 1 0 2 0 7 50 -1 -1 0.000 0 1 -1 1 0 2 + 1 1 2.00 120.00 240.00 + 7740 2295 4500 855 +2 1 0 2 0 7 50 -1 -1 0.000 0 1 -1 1 0 2 + 1 1 2.00 120.00 240.00 + 6840 6435 5760 5355 +2 1 0 2 0 7 50 -1 -1 0.000 0 1 -1 1 0 2 + 1 1 2.00 120.00 240.00 + 5895 8460 6840 7380 +-6 +6 3096 1593 3380 1877 +1 3 0 1 0 7 50 -1 -1 0.000 1 0.0000 3238 1735 142 142 3238 1735 3103 1690 +4 0 0 50 -1 13 12 0.0000 4 105 120 3157 1805 1\001 +-6 +6 2266 3607 2550 3891 +1 3 0 1 0 7 50 -1 -1 0.000 1 0.0000 2408 3749 142 142 2408 3749 2273 3704 +4 0 0 50 -1 13 12 0.0000 4 105 120 2327 3819 2\001 +-6 +6 1566 5667 1850 5951 +1 3 0 1 0 7 50 -1 -1 0.000 1 0.0000 1708 5809 142 142 1708 5809 1573 5764 +4 0 0 50 -1 13 12 0.0000 4 105 120 1627 5879 3\001 +-6 +6 5706 1543 5990 1827 +1 3 0 1 0 7 50 -1 -1 0.000 1 0.0000 5848 1685 142 142 5848 1685 5713 1640 +4 0 0 50 -1 13 12 0.0000 4 105 120 5767 1755 6\001 +-6 +6 5986 7757 6270 8041 +1 3 0 1 0 7 50 -1 -1 0.000 1 0.0000 6128 7899 142 142 6128 7899 5993 7854 +4 0 0 50 -1 13 12 0.0000 4 105 120 6047 7969 7\001 +-6 +6 7426 4747 7710 5031 +1 3 0 1 0 7 50 -1 -1 0.000 1 0.0000 7568 4889 142 142 7568 4889 7433 4844 +4 0 0 50 -1 13 12 0.0000 4 105 120 7487 4959 8\001 +-6 +6 5866 3737 6150 4021 +1 3 0 1 0 7 50 -1 -1 0.000 1 0.0000 6008 3879 142 142 6008 3879 5873 3834 +4 0 0 50 -1 13 12 0.0000 4 105 240 5882 3940 10\001 +-6 +6 5276 2517 5560 2801 +1 3 0 1 0 7 50 -1 -1 0.000 1 0.0000 5418 2659 142 142 5418 2659 5283 2614 +4 0 0 50 -1 13 12 0.0000 4 105 240 5292 2720 11\001 +-6 +6 4126 3573 4410 3857 +1 3 0 1 0 7 50 -1 -1 0.000 1 0.0000 4268 3715 142 142 4268 3715 4133 3670 +4 0 0 50 -1 13 12 0.0000 4 105 240 4142 3776 12\001 +-6 +6 3066 5723 3350 6007 +1 3 0 1 0 7 50 -1 -1 0.000 1 0.0000 3208 5865 142 142 3208 5865 3073 5820 +4 0 0 50 -1 13 12 0.0000 4 105 240 3082 5926 13\001 +-6 +6 4036 6623 4320 6907 +1 3 0 1 0 7 50 -1 -1 0.000 1 0.0000 4178 6765 142 142 4178 6765 4043 6720 +4 0 0 50 -1 13 12 0.0000 4 105 240 4052 6826 14\001 +-6 +6 4416 7213 4700 7497 +1 3 0 1 0 7 50 -1 -1 0.000 1 0.0000 4558 7355 142 142 4558 7355 4423 7310 +4 0 0 50 -1 13 12 0.0000 4 105 240 4432 7416 15\001 +-6 +6 5066 7223 5350 7507 +1 3 0 1 0 7 50 -1 -1 0.000 1 0.0000 5208 7365 142 142 5208 7365 5073 7320 +4 0 0 50 -1 13 12 0.0000 4 105 120 5127 7435 5\001 +-6 +6 3566 7573 3850 7857 +1 3 0 1 0 7 50 -1 -1 0.000 1 0.0000 3708 7715 142 142 3708 7715 3573 7670 +4 0 0 50 -1 13 12 0.0000 4 105 240 3582 7776 16\001 +-6 +6 4996 6193 5280 6477 +1 3 0 1 0 7 50 -1 -1 0.000 1 0.0000 5138 6335 142 142 5138 6335 5003 6290 +4 0 0 50 -1 13 12 0.0000 4 105 240 5012 6396 17\001 +-6 +6 2896 7783 3180 8067 +1 3 0 1 0 7 50 -1 -1 0.000 1 0.0000 3038 7925 142 142 3038 7925 2903 7880 +4 0 0 50 -1 13 12 0.0000 4 105 120 2957 7995 4\001 +-6 +6 6426 5753 6710 6037 +1 3 0 1 0 7 50 -1 -1 0.000 1 0.0000 6568 5895 142 142 6568 5895 6433 5850 +4 0 0 50 -1 13 12 0.0000 4 105 120 6487 5965 9\001 +-6 +-6 Modified: trunk/doc/gcrypt.texi =================================================================== --- trunk/doc/gcrypt.texi 2008-08-27 10:10:47 UTC (rev 1307) +++ trunk/doc/gcrypt.texi 2008-08-27 13:19:27 UTC (rev 1308) @@ -78,6 +78,7 @@ Appendices * FIPS Restrictions:: Restrictions in FIPS mode. +* FIPS Finite State Machine:: Description of the FIPS FSM. * Library Copying:: The GNU Lesser General Public License says how you can copy and share Libgcrypt. * Copying:: The GNU General Public License says how you @@ -85,6 +86,7 @@ Indices +* Figures and Tables:: Index of figures and tables. * Concept Index:: Index of concepts and programs. * Function and Data Index:: Index of functions, variables and data types. @@ -4520,17 +4522,19 @@ @url{http://www.gnupg.org/documentation/mailing-lists.en.html} for details.}. - at noindent -Libgcrypt consists of several subsystems as shown by this diagram: - at center @image{libgcrypt-modules, 10cm,,Module Overview} + at float Figure,fig:subsystems + at caption{Libgcrypt subsystems} + at center @image{libgcrypt-modules, 150mm,,Libgcrypt subsystems} + at end float -All of these subsystems provide a public API including the helper -systesm like S-expression. The API style depends on the subsystem; in -general an open, use, close approach is implemented. The open returns a -handle to a context used for all futher operations on this handle, -several functions may then be used on this handle and a final close -function releases all resources associated with the handle. +Libgcrypt consists of several subsystems (@pxref{fig:subsystems}) and +all these subsystems provide a public API; this includes the helper +subsystems like the one for S-expression. The API style depends on the +subsystem; in general an open, use, close approach is implemented. The +open returns a handle to a context used for all futher operations on +this handle, several functions may then be used on this handle and a +final close function releases all resources associated with the handle. @menu * Public-Key Subsystem Architecture:: All about public keys. @@ -4613,6 +4617,7 @@ @c ******************* Appendices ************************* @c ********************************************************** + at c ******************************************** @node FIPS Restrictions @appendix Restrictions in FIPS mode @@ -4629,8 +4634,143 @@ @end itemize + at c ******************************************** + at node FIPS Finite State Machine + at appendix FIPS Finite State Machine +The FIPS mode of libgcrypt implements a finite state machine (FSM) using +8 states (@pxref{tbl:fips-states}) and checks at runtime that only valid +transitions (@pxref{tbl:fips-state-transitions}) may happen. + at float Figure,fig:fips-fsm + at caption{FIPS mode state diagram} + at center @image{fips-fsm,150mm,,FIPS FSM Diagram} + at end float + + at float Table,tbl:fips-states + at caption{FIPS mode states} + at noindent +States used by the FIPS FSM: + at table @asis + + at item Power-Off +Libgcrypt is not runtime linked to another application. This usually +means that the library is not loaded into main memory. This state is +documentation only. + + at item Power-On +Libgcrypt is loaded into memory and API calls may be made. Compiler +introducted constructor functions may be run. Note that Libgcrypt does +not implement any arbitrary constructor functions to be called by the +operating system + + at item Init +The Libgcrypt initialization functions are performed and the library has +not yet run any self-test. + + at item Self-Test +Libgcrypt is performing self-tests. + + at item Operational +Libgcrypt is in the operational state and all interfaces may be used. + + at item Error +Libgrypt is in the error state. When calling any FIPS relevant +interfaces they either return an error (@code{GPG_ERR_NOT_OPERATIONAL}) +or put Libgcrypt into the Fatal-Error state and won't return. + + at item Fatal-Error +Libgcrypt is in a non-recoverable error state and +will automatically transit into the Shutdown state. + + at item Shutdown +Libgcrypt is about to be terminated and removed from the memory. The +application may at this point still runing cleanup handlers. + + at end table + at end float + + + at float Table,tbl:fips-state-transitions + at caption{FIPS mode state transitions} + at noindent +The valid state transitions (@pxref{fig:fips-fsm}) are: + at table @code + at item 1 +Power-Off to Power-On is implicitly done by the OS loading Libgcrypt as +a shared library and having it linked to an application. + + at item 2 +Power-On to Init is triggered by the application calling the +Libgcrypt intialization function @code{gcry_check_version}. + + at item 3 +Init to Self-Test is either triggred by a dedicated API call or implicit +by invoking a libgrypt service conrolled by the FSM. + + at item 4 +Self-Test to Operational is triggered after all self-tests passed +successfully. + + at item 5 +Operational to Shutdown is an artifical state without any direct action +in Libgcrypt. When reaching the Shutdown state the library is +deinitialized and can't return to any other state again. + + at item 6 +Shutdown to Power-off is the process of removing Libgcrypt from the +computer's memory. For obvious reasons the Power-Off state can't be +represented within Libgcrypt and thus this transition is for +documentation only. + + at item 7 +Operational to Error is triggered if Libgcrypt detected an application +error which can't be returned to the caller but still allows Libgcrypt +to properly run. In the Error state all FIPS relevant interfaces return +an error code. + + at item 8 +Error to Shutdown is similar to the Operational to Shutdown transition +(5). + + at item 9 +Error to Fatal-Error is triggred if Libgrypt detects an fatal error +while already being in Error state. + + at item 10 +Fatal-Error to Shutdown is automatically entered by Libgcrypt +after having reported the error. + + at item 11 +Power-On to Shutdown is an artifical state to document that Libgcrypt +has not ye been initializaed but the process is about to terminate. + + at item 12 +Power-On to Fatal-Error will be triggerd if certain Libgcrypt functions +are used without having reached the Init state. + + at item 13 +Self-Test to Fatal-Error is triggred by severe errors in Libgcrypt while +running self-tests. + + at item 14 +Self-Test to Error is triggred by a failed self-test. + + at item 15 +Operational to Fatal-Error is triggred if Libcrypt encountered a +non-recoverable error. + + at item 16 +Operational to Self-Test is triggred if the application requested to run +the self-tests again. + + at item 17 +Error to Self-Test is triggered if the application has requested to run +self-tests to get to get back into operational state after an error. + + at end table + at end float + @c ********************************************************** @c ************* Appendices (license etc.) **************** @c ********************************************************** @@ -4638,6 +4778,13 @@ @include gpl.texi + at node Figures and Tables + at unnumbered List of Figures and Tables + + at listoffloats Figure + + at listoffloats Table + @node Concept Index @unnumbered Concept Index @@ -4648,6 +4795,8 @@ @printindex fn + + @bye From cvs at cvs.gnupg.org Wed Aug 27 18:57:46 2008 From: cvs at cvs.gnupg.org (svn author dshaw) Date: Wed, 27 Aug 2008 18:57:46 +0200 Subject: [svn] GnuPG - r4818 - branches/STABLE-BRANCH-1-4 Message-ID: Author: dshaw Date: 2008-08-27 18:57:45 +0200 (Wed, 27 Aug 2008) New Revision: 4818 Modified: branches/STABLE-BRANCH-1-4/ChangeLog branches/STABLE-BRANCH-1-4/configure.ac Log: * configure.ac: Use printf for the most portable SVN version detection. Modified: branches/STABLE-BRANCH-1-4/ChangeLog =================================================================== --- branches/STABLE-BRANCH-1-4/ChangeLog 2008-08-27 05:58:30 UTC (rev 4817) +++ branches/STABLE-BRANCH-1-4/ChangeLog 2008-08-27 16:57:45 UTC (rev 4818) @@ -1,3 +1,8 @@ +2008-08-27 David Shaw + + * configure.ac: Use printf for the most portable SVN version + detection. + 2008-08-11 Werner Koch * configure.ac: Check for size of time_t. Modified: branches/STABLE-BRANCH-1-4/configure.ac =================================================================== --- branches/STABLE-BRANCH-1-4/configure.ac 2008-08-27 05:58:30 UTC (rev 4817) +++ branches/STABLE-BRANCH-1-4/configure.ac 2008-08-27 16:57:45 UTC (rev 4818) @@ -27,10 +27,8 @@ # "svn up" and "autogen.sh --force" right before creating a distribution. m4_define([my_version], [1.4.10]) m4_define([my_issvn], [yes]) - -m4_define([svn_revision], m4_esyscmd([echo $((svn info 2>/dev/null \ - || echo 'Revision: 0')|sed -n '/^Revision:/ s/[^0-9]//gp'|head -1)| \ - tr -d '\n'])) +m4_define([svn_revision], m4_esyscmd([printf "%d" $(svn info 2>/dev/null \ + | sed -n '/^Revision:/ s/[^0-9]//gp'|head -1)])) AC_INIT([gnupg], [my_version[]m4_if(my_issvn,[yes],[-svn[]svn_revision])], [bug-gnupg at gnu.org]) From cvs at cvs.gnupg.org Wed Aug 27 19:01:30 2008 From: cvs at cvs.gnupg.org (svn author dshaw) Date: Wed, 27 Aug 2008 19:01:30 +0200 Subject: [svn] GnuPG - r4819 - trunk Message-ID: Author: dshaw Date: 2008-08-27 19:01:29 +0200 (Wed, 27 Aug 2008) New Revision: 4819 Modified: trunk/ChangeLog trunk/configure.ac Log: * configure.ac: Use printf for the most portable SVN version detection. Modified: trunk/ChangeLog =================================================================== --- trunk/ChangeLog 2008-08-27 16:57:45 UTC (rev 4818) +++ trunk/ChangeLog 2008-08-27 17:01:29 UTC (rev 4819) @@ -1,5 +1,8 @@ 2008-08-27 David Shaw + * configure.ac: Use printf for the most portable SVN version + detection. + * configure.ac: Darwin's /bin/sh has a builtin echo that doesn't understand '-n'. Use tr to trim the carriage return instead. Modified: trunk/configure.ac =================================================================== --- trunk/configure.ac 2008-08-27 16:57:45 UTC (rev 4818) +++ trunk/configure.ac 2008-08-27 17:01:29 UTC (rev 4819) @@ -26,11 +26,8 @@ # "svn up" and "autogen.sh" right before creating a distribution. m4_define([my_version], [2.0.10]) m4_define([my_issvn], [yes]) - - -m4_define([svn_revision], m4_esyscmd([echo $((svn info 2>/dev/null \ - || echo 'Revision: 0')|sed -n '/^Revision:/ s/[^0-9]//gp'|head -1)| \ - tr -d '\n'])) +m4_define([svn_revision], m4_esyscmd([printf "%d" $(svn info 2>/dev/null \ + | sed -n '/^Revision:/ s/[^0-9]//gp'|head -1)])) AC_INIT([gnupg], [my_version[]m4_if(my_issvn,[yes],[-svn[]svn_revision])], [bug-gnupg at gnupg.org]) From cvs at cvs.gnupg.org Thu Aug 28 16:57:26 2008 From: cvs at cvs.gnupg.org (svn author wk) Date: Thu, 28 Aug 2008 16:57:26 +0200 Subject: [svn] GnuPG - r4820 - trunk/doc Message-ID: Author: wk Date: 2008-08-28 16:57:25 +0200 (Thu, 28 Aug 2008) New Revision: 4820 Modified: trunk/doc/DETAILS trunk/doc/gpg.texi Log: Add a warning nite to --throw-keyds. Modified: trunk/doc/DETAILS =================================================================== --- trunk/doc/DETAILS 2008-08-27 17:01:29 UTC (rev 4819) +++ trunk/doc/DETAILS 2008-08-28 14:57:25 UTC (rev 4820) @@ -60,8 +60,8 @@ be marked as ultimately trusted. For X.509 certificates an 'u' is used for a trusted root - certificates (i.e. for the truct anchor) and and 'f' for - all other validated certificates. + certificate (i.e. for the trust anchor) and an 'f' for all + other valid certificates. 3. Field: length of key in bits. Modified: trunk/doc/gpg.texi =================================================================== --- trunk/doc/gpg.texi 2008-08-27 17:01:29 UTC (rev 4819) +++ trunk/doc/gpg.texi 2008-08-28 14:57:25 UTC (rev 4820) @@ -2264,12 +2264,15 @@ @item --throw-keyids @itemx --no-throw-keyids -Do not put the recipient key IDs into encrypted messages. This helps -to hide the receivers of the message and is a limited countermeasure -against traffic analysis. On the receiving side, it may slow down the -decryption process because all available secret keys must be tried. - at option{--no-throw-keyids} disables this option. This option is essentially -the same as using @option{--hidden-recipient} for all recipients. +Do not put the recipient key IDs into encrypted messages. This helps to +hide the receivers of the message and is a limited countermeasure +against traffic analysis. at footnote{Using a little social engineering +anyone who is able to decrypt the message can check whether one of the +other recipients is the one he suspects.} On the receiving side, it may +slow down the decryption process because all available secret keys must +be tried. @option{--no-throw-keyids} disables this option. This option +is essentially the same as using @option{--hidden-recipient} for all +recipients. @item --not-dash-escaped This option changes the behavior of cleartext signatures From cvs at cvs.gnupg.org Fri Aug 29 13:09:29 2008 From: cvs at cvs.gnupg.org (svn author wk) Date: Fri, 29 Aug 2008 13:09:29 +0200 Subject: [svn] gcry - r1309 - in trunk: cipher doc random src tests Message-ID: Author: wk Date: 2008-08-29 13:09:26 +0200 (Fri, 29 Aug 2008) New Revision: 1309 Added: trunk/tests/README trunk/tests/rsa-16k.key Modified: trunk/cipher/ChangeLog trunk/cipher/cipher.c trunk/cipher/elgamal.c trunk/cipher/primegen.c trunk/doc/ChangeLog trunk/doc/Makefile.am trunk/doc/gcrypt.texi trunk/random/ChangeLog trunk/random/random-csprng.c trunk/random/random-daemon.c trunk/random/random-fips.c trunk/random/rndunix.c trunk/random/rndw32.c trunk/src/ChangeLog trunk/src/global.c trunk/src/hwfeatures.c trunk/tests/ChangeLog trunk/tests/Makefile.am trunk/tests/basic.c trunk/tests/pkbench.c Log: Changed the way the FIPS RNG is seeded. FIPS cleanups. Documentation upodates. [The diff below has been truncated] Modified: trunk/cipher/ChangeLog =================================================================== --- trunk/cipher/ChangeLog 2008-08-27 13:19:27 UTC (rev 1308) +++ trunk/cipher/ChangeLog 2008-08-29 11:09:26 UTC (rev 1309) @@ -1,3 +1,10 @@ +2008-08-28 Werner Koch + + * cipher.c (cipher_decrypt, cipher_encrypt): Return an error if + mode NONE is used. + (gcry_cipher_open): Allow mode NONE only with a debug flag set and + if not in FIPS mode. + 2008-08-26 Werner Koch * pubkey.c (pubkey_generate): Add arg KEYGEN_FLAGS. Modified: trunk/doc/ChangeLog =================================================================== --- trunk/doc/ChangeLog 2008-08-27 13:19:27 UTC (rev 1308) +++ trunk/doc/ChangeLog 2008-08-29 11:09:26 UTC (rev 1309) @@ -1,3 +1,7 @@ +2008-08-27 Werner Koch + + * Makefile.am (online): Take care of development versions. + 2008-08-18 Werner Koch * gcrypt.texi (Top): Remove the detailmenu. Modified: trunk/random/ChangeLog =================================================================== --- trunk/random/ChangeLog 2008-08-27 13:19:27 UTC (rev 1308) +++ trunk/random/ChangeLog 2008-08-29 11:09:26 UTC (rev 1309) @@ -1,3 +1,22 @@ +2008-08-29 Werner Koch + + * random-fips.c (SEED_TTL): New. + (struct rng_context): Add USE_COUNTER, remove NEED_STRONG_ENTROPY. + (x931_aes_driver): Do re-seeding if required. + (x931_generate_key, x931_generate_seed): Factor common code out to .. + (get_entropy): .. new. Always use /dev/random. + (x931_generate_key): Seed key for nonce_context from std_rng_context. + (x931_reseed): New. Seed nonce context from std_rng_context. + (get_random): Use x931_reseed. + (_gcry_rngfips_selftest): Return an error if no /dev/radom support + has been compiled in. + (get_random): Remove locking. + (_gcry_rngfips_randomize, _gcry_rngfips_create_nonce): Lock here. + +2008-08-28 Werner Koch + + * random-daemon.c (connect_to_socket): Use GPG_ERR_ENAMETOOLONG. + 2008-08-25 Werner Koch * random-fips.c (x931_aes): Take datetime_GT from an arg. Modified: trunk/src/ChangeLog =================================================================== --- trunk/src/ChangeLog 2008-08-27 13:19:27 UTC (rev 1308) +++ trunk/src/ChangeLog 2008-08-29 11:09:26 UTC (rev 1309) @@ -1,3 +1,8 @@ +2008-08-28 Werner Koch + + * hwfeatures.c (_gcry_detect_hw_features): Disable hardware + detection in FIPS mode. + 2008-08-27 Werner Koch * global.c (_gcry_vcontrol): Allow running selftests from error @@ -2,4 +7,9 @@ state. + (gcry_set_outofcore_handler): Only print a warning if used in FIPS + mode. + (gcry_xmalloc, gcry_xrealloc, gcry_xmalloc_secure, gcry_xstrdup): + Ignore an outofcore handler in FIPS mode. + * fips.c (_gcry_fips_test_error_or_operational): New. - (fips_new_state): Allow transtion from error into selftest. + (fips_new_state): Allow transition from error into selftest. Disallow error to init. Modified: trunk/tests/ChangeLog =================================================================== --- trunk/tests/ChangeLog 2008-08-27 13:19:27 UTC (rev 1308) +++ trunk/tests/ChangeLog 2008-08-29 11:09:26 UTC (rev 1309) @@ -1,5 +1,15 @@ +2008-08-28 Werner Koch + + * rsa-16k.key: New sample key. + 2008-08-27 Werner Koch + * pkbench.c (read_file): New. + (process_key_pair_file): Replace mmap by read_file. + (main): Add a --fips option. + * Makefile.am (EXTRA_DIST): Remove. + (EXTRA_PROGRAMS): Add pkbench. + * basic.c (main): Extended FIPS self-test test. 2008-08-26 Werner Koch Modified: trunk/cipher/cipher.c =================================================================== --- trunk/cipher/cipher.c 2008-08-27 13:19:27 UTC (rev 1308) +++ trunk/cipher/cipher.c 2008-08-29 11:09:26 UTC (rev 1309) @@ -731,7 +731,11 @@ break; case GCRY_CIPHER_MODE_NONE: - /* FIXME: issue a warning when this mode is used */ + /* This mode may be used for debbuging. It copies the main + text verbatim to the ciphertext. We do not allow this in + fips mode or if no debug flag has been set. */ + if (fips_mode () || !_gcry_get_debug_flag (0)) + err = GPG_ERR_INV_CIPHER_MODE; break; default: @@ -1421,8 +1425,16 @@ outbuf, (byte*)/*arggg*/inbuf, nbytes ); break; case GCRY_CIPHER_MODE_NONE: - if( inbuf != outbuf ) - memmove( outbuf, inbuf, nbytes ); + if (fips_mode () || !_gcry_get_debug_flag (0)) + { + fips_signal_error ("cipher mode NONE used"); + rc = GPG_ERR_INV_CIPHER_MODE; + } + else + { + if ( inbuf != outbuf ) + memmove (outbuf, inbuf, nbytes); + } break; default: log_fatal("cipher_encrypt: invalid mode %d\n", c->mode ); @@ -1512,8 +1524,16 @@ outbuf, (byte*)/*arggg*/inbuf, nbytes ); break; case GCRY_CIPHER_MODE_NONE: - if( inbuf != outbuf ) - memmove( outbuf, inbuf, nbytes ); + if (fips_mode () || !_gcry_get_debug_flag (0)) + { + fips_signal_error ("cipher mode NONE used"); + rc = GPG_ERR_INV_CIPHER_MODE; + } + else + { + if (inbuf != outbuf) + memmove (outbuf, inbuf, nbytes); + } break; default: log_fatal ("cipher_decrypt: invalid mode %d\n", c->mode ); Modified: trunk/cipher/elgamal.c =================================================================== --- trunk/cipher/elgamal.c 2008-08-27 13:19:27 UTC (rev 1308) +++ trunk/cipher/elgamal.c 2008-08-29 11:09:26 UTC (rev 1309) @@ -83,8 +83,9 @@ /**************** - * Michael Wiener's table on subgroup sizes to match field sizes - * (floating around somewhere - Fixme: need a reference) + * Michael Wiener's table on subgroup sizes to match field sizes. + * (floating around somewhere, probably based on the paper from + * Eurocrypt 96, page 332) */ static unsigned int wiener_map( unsigned int n ) Modified: trunk/cipher/primegen.c =================================================================== --- trunk/cipher/primegen.c 2008-08-27 13:19:27 UTC (rev 1308) +++ trunk/cipher/primegen.c 2008-08-29 11:09:26 UTC (rev 1309) @@ -395,8 +395,7 @@ /* Make a pool of 3n+5 primes (this is an arbitrary value). We require at least 30 primes for are useful selection process. - FIXME: We need to do some reseacrh on the best formula for sizing - the pool. + Fixme: We need to research the best formula for sizing the pool. */ m = n * 3 + 5; if (need_q_factor) /* Need some more in this case. */ Modified: trunk/doc/Makefile.am =================================================================== --- trunk/doc/Makefile.am 2008-08-27 13:19:27 UTC (rev 1308) +++ trunk/doc/Makefile.am 2008-08-29 11:09:26 UTC (rev 1309) @@ -45,11 +45,27 @@ fig2dev -L pdf `test -f '$<' || echo '$(srcdir)/'`$< $@ +# Make sure that gcrypt.texi is touched if any other source file has +# been modified. This is required so that the version.texi magic +# updates the release date. +gnupg.texi : $(gcrypt_TEXINFOS) + touch $(srcdir)/gcrypt.texi + online: gcrypt.html gcrypt.pdf gcrypt.info set -e; \ echo "Uploading current manuals to www.gnupg.org ..."; \ - user=werner ; dir="webspace/manuals/gcrypt-devel/" ; \ - (cd gcrypt.html && rsync -vr --exclude='.svn' . \ - $${user}@cvs.gnupg.org:$${dir} ); \ - rsync -v gcrypt.pdf gcrypt.info $${user}@cvs.gnupg.org:$${dir} + cp libgcrypt-modules.png gcrypt.html/; \ + cp fips-fsm.png gcrypt.html/; \ + user=werner ; dashdevel="" ; \ + if echo "@PACKAGE_VERSION@" | grep -- "-svn" >/dev/null; then \ + dashdevel="-devel" ; \ + cp gcrypt.pdf gcrypt.html/; \ + cp gcrypt.info gcrypt.html/; \ + else \ + rsync -v gcrypt.pdf gcrypt.info \ + $${user}@cvs.gnupg.org:webspace/manuals/ ; \ + fi ; \ + cd gcrypt.html ; \ + rsync -vr --exclude='.svn' . \ + $${user}@cvs.gnupg.org:webspace/manuals/gcrypt$${dashdevel}/ Modified: trunk/doc/gcrypt.texi =================================================================== --- trunk/doc/gcrypt.texi 2008-08-27 13:19:27 UTC (rev 1308) +++ trunk/doc/gcrypt.texi 2008-08-29 11:09:26 UTC (rev 1309) @@ -1540,8 +1540,9 @@ @table @code @item GCRY_CIPHER_MODE_NONE -No mode specified, may be set later using other functions. The value -of this constant is always 0. +No mode specified. This should not be used. The only exception is that +if Libgcrypt is not used in FIPS mode and if any debug flag has been +set, this mode may be used to bypass the actual encryption. @item GCRY_CIPHER_MODE_ECB Electronic Codebook mode. @@ -4621,16 +4622,97 @@ @node FIPS Restrictions @appendix Restrictions in FIPS mode -If Libgcrypt is used FIPS mode these restrictions are effective: +If Libgcrypt is used in FIPS mode these restrictions are effective: @itemize + at item +The cryptographic algorithms are restricted to this list: + at table @asis + at item GCRY_CIPHER_3DES +3 key EDE Triple-DES symmetric encryption. + at item GCRY_CIPHER_AES128 +AES 128 bit symmetric encryption. + at item GCRY_CIPHER_AES192 +AES 192 bit symmetric encryption. + at item GCRY_CIPHER_AES256 +AES 256 bit symmetric encryption. + at item GCRY_MD_SHA1 +SHA-1 message digest. + at item GCRY_MD_SHA224 +SHA-224 message digest. + at item GCRY_MD_SHA256 +SHA-256 message digest. + at item GCRY_MD_SHA384 +SHA-384 message digest. + at item GCRY_MD_SHA512 +SHA-512 message digest. + at item GCRY_MD_SHA1,GCRY_MD_FLAG_HMAC +HMAC using a SHA-1 message digest. + at item GCRY_MD_SHA224,GCRY_MD_FLAG_HMAC +HMAC using a SHA-224 message digest. + at item GCRY_MD_SHA256,GCRY_MD_FLAG_HMAC +HMAC using a SHA-256 message digest. + at item GCRY_MD_SHA384,GCRY_MD_FLAG_HMAC +HMAC using a SHA-384 message digest. + at item GCRY_MD_SHA512,GCRY_MD_FLAG_HMAC +HMAC using a SHA-512 message digest. + at item GCRY_PK_RSA +RSA encryption and signing. + at item GCRY_PK_DSA +DSA signing. + at end table + +Note that the CRC algorithms are not considered cryptographic algorithms +and thus are in addition available. + + at item +RSA and DSA key generation refuses to create a key with a keysize of +less than 1024 bits. + + at item +The @code{transient-key} flag for RSA key generation is ignored. + + at item +Support for the VIA Padlock engine is disabled. + @item -It may only be used on systesm with a /dev/random device. Swicthing -into FIPS mode on other systems will fail at runtime. +FIPS mode may only be used on systems with a /dev/random device. +Switching into FIPS mode on other systems will fail at runtime. + at item +Saving and loading a random seed file is not ignored. + at item +An X9.31 style random number generator is used in place of the +large-pool-CSPRNG generator. + at item +The Alternative Public Key Interface (@code{gcry_ac_xxx}) is not +supported and all API calls return an error. + + at item Registration of external modules is not supported. + + at item +Message digest debugging is disabled. + + at item +All debug output related to cryptographic data is suppressed. + + at item +On-the-fly self-tests are not performed, instead of this self-tests are +run before entering operational state. + + at item +The function @code{gcry_set_allocation_handler} may not be used. If it +is used Libgcrypt will enter the error state. + + at item +A handler set by @code{gcry_set_outofcore_handler} is ignored. + at item +A handler set by @code{gcry_set_fatalerror_handler} is ignored. + + @end itemize @@ -4799,7 +4881,15 @@ @bye +GCRYCTL_SET_RANDOM_DAEMON_SOCKET +GCRYCTL_USE_RANDOM_DAEMON +The random damon is still a bit experimental, thus we do not document +them. Not ethat they should be used during initialization and that +these functions are not really thread safe. + + + @c LocalWords: int HD Modified: trunk/random/random-csprng.c =================================================================== --- trunk/random/random-csprng.c 2008-08-27 13:19:27 UTC (rev 1308) +++ trunk/random/random-csprng.c 2008-08-29 11:09:26 UTC (rev 1309) @@ -367,9 +367,9 @@ void _gcry_rngcsprng_dump_stats (void) { - /* FIXME: don't we need proper locking here? -mo. - Yes. However this is usually called during cleanup and thenwe _ - might_ run into problems. Needs to be checked. -wk */ + /* In theory we would need to lock the stats here. However this + function is usually called during cleanup and then we _might_ run + into problems. */ log_info ("random usage: poolsize=%d mixed=%lu polls=%lu/%lu added=%lu/%lu\n" " outmix=%lu getlvl1=%lu/%lu getlvl2=%lu/%lu%s\n", @@ -422,7 +422,11 @@ #ifdef USE_RANDOM_DAEMON int last; - /* FIXME: This is not really thread safe. */ + /* This is not really thread safe. However it is expected that this + function is being called during initialization and at that point + we are for other reasons not really thread safe. We do not want + to lock it because we might eventually decide that this function + may even be called prior to gcry_check_version. */ last = allow_daemon; if (onoff != -1) allow_daemon = onoff; Modified: trunk/random/random-daemon.c =================================================================== --- trunk/random/random-daemon.c 2008-08-27 13:19:27 UTC (rev 1308) +++ trunk/random/random-daemon.c 2008-08-29 11:09:26 UTC (rev 1309) @@ -90,7 +90,7 @@ if (strlen (socketname) + 1 >= sizeof (srvr_addr->sun_path)) { log_error ("socket name `%s' too long\n", socketname); - err = gcry_error (GPG_ERR_INTERNAL); /* FIXME? */ + err = gcry_error (GPG_ERR_ENAMETOOLONG); goto out; } strcpy (srvr_addr->sun_path, socketname); @@ -285,7 +285,7 @@ break; } - /* if (1)*/ /* FIXME, verbose */ + /* if (1)*/ /* Do this in verbose mode? */ /* log_info ("received response with %d bytes of data\n", buf[1]);*/ if (buf[1] < nbytes) Modified: trunk/random/random-fips.c =================================================================== --- trunk/random/random-fips.c 2008-08-27 13:19:27 UTC (rev 1308) +++ trunk/random/random-fips.c 2008-08-29 11:09:26 UTC (rev 1309) @@ -21,8 +21,36 @@ The core of this deterministic random number generator is implemented according to the document "NIST-Recommended Random Number Generator Based on ANSI X9.31 Appendix A.2.4 Using the 3-Key - Triple DES and AES Algorithms" (2005-01-31). This implementaion + Triple DES and AES Algorithms" (2005-01-31). This implementation uses the AES variant. + + There are 3 random context which map to the different levels of + random quality: + + Generator Seed and Key Kernel entropy (init/reseed) + ------------------------------------------------------------ + GCRY_VERY_STRONG_RANDOM /dev/random 256/128 bits + GCRY_STRONG_RANDOM /dev/random 256/128 bits + gcry_create_nonce GCRY_STRONG_RANDOM n/a + + All random generators return their data in 128 bit blocks. If the + caller requested less bits, the extra bits are not used. The key + for each generator is only set once at the first time a generator + is used. The seed value is set with the key and again after 1000 + (SEED_TTL) output blocks. + + The GCRY_VERY_STRONG_RANDOM and GCRY_STRONG_RANDOM generators are + keyed and seeded from the /dev/random device. Thus these + generators may block until the kernel has collected enough entropy. + + The gcry_create_nonce generator is keyed and seeded from the + GCRY_STRONG_RANDOM generator. It may also block if the + GCRY_STRONG_RANDOM generator has not yet been used before and thus + gets initialized on the first use by gcry_create_nonce. This + special treatment is justified by the weaker requirements for a + nonce generator and to save precious kernel entropy for use by the + real random generators. + */ #include @@ -59,6 +87,11 @@ static unsigned char *tempvalue_for_x931_aes_driver; +/* After having retrieved this number of blocks from the RNG, we want + to do a reseeding. */ +#define SEED_TTL 1000 + + /* The length of the key we use: 16 bytes (128 bit) for AES128. */ #define X931_AES_KEYLEN 16 /* A global buffer used to communicate between the x931_generate_key @@ -83,10 +116,6 @@ established. */ gcry_cipher_hd_t cipher_hd; - /* If this flag is true, this context requires strong entropy; - i.e. from /dev/random. */ - int need_strong_entropy:1; - /* If this flag is true, the SEED_V buffer below carries a valid seed. */ int is_seeded:1; @@ -96,6 +125,9 @@ is available. */ int compare_value_valid:1; + /* A counter used to trigger re-seeding. */ + unsigned int use_counter; + unsigned char guard_1[1]; /* The buffer containing the seed value V. */ @@ -140,7 +172,12 @@ static rng_context_t strong_rng_context; +/* --- Local prototypes --- */ +static void x931_reseed (rng_context_t rng_ctx); +static void get_random (void *buffer, size_t length, rng_context_t rng_ctx); + + /* --- Functions --- */ @@ -412,6 +449,13 @@ while (length) { + /* We require a new seed after some time. */ + if (rng_ctx->use_counter > SEED_TTL) + { + x931_reseed (rng_ctx); + rng_ctx->use_counter = 0; + } + /* Due to the design of the RNG, we always receive 16 bytes (128 bit) of random even if we require less. The extra bytes returned are not used. Intheory we could save them for the @@ -423,6 +467,7 @@ x931_aes (result_buffer, datetime_DT, rng_ctx->seed_V, rng_ctx->cipher_hd, intermediate_I, temp_buffer); + rng_ctx->use_counter++; /* Do a basic check on the output to avoid a stuck generator. */ if (!rng_ctx->compare_value_valid) @@ -455,9 +500,9 @@ /* Callback for x931_generate_key. Note that this callback uses the - global ENTROPY_COLLECT_BUFFER which has been setup by - x931_generate_key. ORIGIN is not used but required due to the - emtropy gathering module. */ + global ENTROPY_COLLECT_BUFFER which has been setup by get_entropy. + ORIGIN is not used but required due to the design of entropy + gathering module. */ static void entropy_collect_cb (const void *buffer, size_t length, enum random_origins origin) @@ -476,15 +521,49 @@ } } + +/* Get NBYTES of entropy from the kernel device. The callers needs to + free the returned buffer. The function either succeeds or + terminates the process in case of a fatal error. */ +static void * +get_entropy (size_t nbytes) +{ +#if USE_RNDLINUX + void *result; + + gcry_assert (!entropy_collect_buffer); + entropy_collect_buffer = gcry_xmalloc_secure (nbytes); + entropy_collect_buffer_size = nbytes; + entropy_collect_buffer_len = 0; + if (_gcry_rndlinux_gather_random (entropy_collect_cb, 0, + X931_AES_KEYLEN, + GCRY_VERY_STRONG_RANDOM) < 0 + || entropy_collect_buffer_len != entropy_collect_buffer_size) + { + gcry_free (entropy_collect_buffer); + entropy_collect_buffer = NULL; + log_fatal ("error getting entropy data\n"); + } + result = entropy_collect_buffer; + entropy_collect_buffer = NULL; + return result; +#else + log_fatal ("/dev/random support is not compiled in\n"); + return NULL; /* NOTREACHED */ +#endif +} + + /* Generate a key for use with x931_aes. The function returns a handle to the cipher context readily prepared for ECB encryption. - If VERY_STRONG is true the key is read from /dev/random, otherwise - from /dev/urandom. On error NULL is returned. */ + If FOR_NONCE is true, the key is retrieved by readong random from + the standard generator. On error NULL is returned. */ static gcry_cipher_hd_t -x931_generate_key (int very_strong) +x931_generate_key (int for_nonce) { gcry_cipher_hd_t hd; gpg_error_t err; + void *buffer; gcry_assert (fips_rng_is_locked); @@ -498,34 +577,22 @@ return NULL; } - /* Get a key from the entropy source. */ -#if USE_RNDLINUX - gcry_assert (!entropy_collect_buffer); - entropy_collect_buffer = gcry_xmalloc_secure (X931_AES_KEYLEN); - entropy_collect_buffer_size = X931_AES_KEYLEN; - entropy_collect_buffer_len = 0; - if (_gcry_rndlinux_gather_random (entropy_collect_cb, 0, X931_AES_KEYLEN, From cvs at cvs.gnupg.org Fri Aug 29 17:40:26 2008 From: cvs at cvs.gnupg.org (svn author wk) Date: Fri, 29 Aug 2008 17:40:26 +0200 Subject: [svn] gcry - r1310 - in trunk: . cipher doc mpi src tests Message-ID: Author: wk Date: 2008-08-29 17:40:24 +0200 (Fri, 29 Aug 2008) New Revision: 1310 Modified: trunk/TODO trunk/cipher/ChangeLog trunk/cipher/ecc.c trunk/cipher/pubkey.c trunk/cipher/rsa.c trunk/doc/gcrypt.texi trunk/mpi/mpicoder.c trunk/src/ChangeLog trunk/src/cipher-proto.h trunk/src/fips.c trunk/tests/ChangeLog trunk/tests/keygrip.c Log: Overhauled the keygrip computation. [The diff below has been truncated] Modified: trunk/cipher/ChangeLog =================================================================== --- trunk/cipher/ChangeLog 2008-08-29 11:09:26 UTC (rev 1309) +++ trunk/cipher/ChangeLog 2008-08-29 15:40:24 UTC (rev 1310) @@ -1,3 +1,12 @@ +2008-08-29 Werner Koch + + * pubkey.c (gcry_pk_get_keygrip): Remove the special case for RSA + and check whether a custom computation function has been setup. + * rsa.c (compute_keygrip): New. + (_gcry_pubkey_extraspec_rsa): Setup this function. + * ecc.c (compute_keygrip): New. + (_gcry_pubkey_extraspec_ecdsa): Setup this function. + 2008-08-28 Werner Koch * cipher.c (cipher_decrypt, cipher_encrypt): Return an error if Modified: trunk/src/ChangeLog =================================================================== --- trunk/src/ChangeLog 2008-08-29 11:09:26 UTC (rev 1309) +++ trunk/src/ChangeLog 2008-08-29 15:40:24 UTC (rev 1310) @@ -1,3 +1,11 @@ +2008-08-29 Werner Koch + + * fips.c (_gcry_initialize_fips_mode): Changed /proc file to test + for FIPS mode. + + * cipher-proto.h (pk_compute_keygrip_t): New. + (pk_extra_spec): Add field comp_keygrip. + 2008-08-28 Werner Koch * hwfeatures.c (_gcry_detect_hw_features): Disable hardware Modified: trunk/tests/ChangeLog =================================================================== --- trunk/tests/ChangeLog 2008-08-29 11:09:26 UTC (rev 1309) +++ trunk/tests/ChangeLog 2008-08-29 15:40:24 UTC (rev 1310) @@ -1,3 +1,7 @@ +2008-08-29 Werner Koch + + * keygrip.c: Update to also check ECDSA. + 2008-08-28 Werner Koch * rsa-16k.key: New sample key. Modified: trunk/TODO =================================================================== --- trunk/TODO 2008-08-29 11:09:26 UTC (rev 1309) +++ trunk/TODO 2008-08-29 15:40:24 UTC (rev 1310) @@ -12,10 +12,6 @@ This requires the introduction of a parameter names (say) U which is calculated according to OpenSSL/PKCS#1 rules. -* Add a warning to the manual, to check that libgcrypt actually has - been compiled with thread support when used by a threaded - application. - * linker script test Write an autoconf test to check whether the linker supports a version script. @@ -97,5 +93,3 @@ ** C++ tests We have some code to allow using libgcrypt from C++, so we also should have a test case. - -* The prime generator always uses very-strong-random. Modified: trunk/cipher/ecc.c =================================================================== --- trunk/cipher/ecc.c 2008-08-29 11:09:26 UTC (rev 1309) +++ trunk/cipher/ecc.c 2008-08-29 15:40:24 UTC (rev 1310) @@ -1182,6 +1182,110 @@ } + +/* See rsa.c for a description of this function. */ +static gpg_err_code_t +compute_keygrip (gcry_md_hd_t md, gcry_sexp_t keyparam) +{ + gpg_err_code_t ec = 0; + gcry_sexp_t l1; + static const char const names[] = "pabgnq"; + gcry_mpi_t values[6]; + int idx; + + /* Clear the values for easier error cleanup. */ + for (idx=0; idx < 6; idx++) + values[idx] = NULL; + + /* Fill values with all available parameters. */ + for (idx=0; idx < 6; idx++) + { + l1 = gcry_sexp_find_token (keyparam, names+idx, 1); + if (l1) + { + values[idx] = gcry_sexp_nth_mpi (l1, 1, GCRYMPI_FMT_USG); + gcry_sexp_release (l1); + if (!values[idx]) + { + ec = GPG_ERR_INV_OBJ; + goto leave; + } + } + } + + /* Check whether a curve parameter is available and use that to fill + in missing values. */ + l1 = gcry_sexp_find_token (keyparam, "curve", 5); + if (l1) + { + char *curve; + gcry_mpi_t tmpvalues[6]; + + for (idx = 0; idx < 6; idx++) + tmpvalues[idx] = NULL; + + curve = _gcry_sexp_nth_string (l1, 1); + if (!curve) + { + ec = GPG_ERR_INV_OBJ; /* Name missing or out of core. */ + goto leave; + } + ec = _gcry_ecc_get_param (curve, tmpvalues); + gcry_free (curve); + if (ec) + goto leave; + + for (idx = 0; idx < 6; idx++) + { + if (!values[idx]) + values[idx] = tmpvalues[idx]; + else + mpi_free (tmpvalues[idx]); + } + } + + /* Check that all parameters are known and normalize all MPIs (that + should not be required but we use an internal fucntion later and + thus we better make 100% sure that they are normalized). */ + for (idx = 0; idx < 6; idx++) + if (!values[idx]) + { + ec = GPG_ERR_NO_OBJ; + goto leave; + } + else + _gcry_mpi_normalize (values[idx]); + + /* Hash them all. */ + for (idx = 0; idx < 6; idx++) + { + char buf[30]; + unsigned char *rawmpi; + unsigned int rawmpilen; + + rawmpi = _gcry_mpi_get_buffer (values[idx], &rawmpilen, NULL); + if (!rawmpi) + { + ec = gpg_err_code_from_syserror (); + goto leave; + } + snprintf (buf, sizeof buf, "(1:%c%u:", names[idx], rawmpilen); + gcry_md_write (md, buf, strlen (buf)); + gcry_md_write (md, rawmpi, rawmpilen); + gcry_md_write (md, ")", 1); + gcry_free (rawmpi); + } + + leave: + for (idx = 0; idx < 6; idx++) + _gcry_mpi_release (values[idx]); + + return ec; +} + + + + /* Self-test section. @@ -1254,6 +1358,8 @@ }; pk_extra_spec_t _gcry_pubkey_extraspec_ecdsa = { - run_selftests + run_selftests, + NULL, + compute_keygrip }; Modified: trunk/cipher/pubkey.c =================================================================== --- trunk/cipher/pubkey.c 2008-08-29 11:09:26 UTC (rev 1309) +++ trunk/cipher/pubkey.c 2008-08-29 15:40:24 UTC (rev 1310) @@ -878,7 +878,7 @@ const char *name; gcry_sexp_t list; - /* Clear the array for easir error cleanup. */ + /* Clear the array for easier error cleanup. */ for (name = element_names, idx = 0; *name; name++, idx++) elements[idx] = NULL; gcry_assert (idx >= 6); /* We know that ECC has at least 6 elements. */ @@ -2432,10 +2432,10 @@ gcry_sexp_t list = NULL, l2 = NULL; gcry_pk_spec_t *pubkey = NULL; gcry_module_t module = NULL; + pk_extra_spec_t *extraspec; const char *s; char *name = NULL; int idx; - int is_rsa; const char *elems; gcry_md_hd_t md = NULL; @@ -2469,53 +2469,45 @@ goto fail; /* Unknown algorithm. */ pubkey = (gcry_pk_spec_t *) module->spec; + extraspec = module->extraspec; - /* FIXME, special handling should be implemented by the algorithms, - not by the libgcrypt core. */ - is_rsa = module->mod_id == GCRY_PK_RSA; elems = pubkey->elements_grip; - if (! elems) + if (!elems) goto fail; /* No grip parameter. */ if (gcry_md_open (&md, GCRY_MD_SHA1, 0)) goto fail; -#if USE_ECC -# ifdef __GNUC__ -# warning needs to be fixed for ECC. -# endif -#endif - - for (idx = 0, s = elems; *s; s++, idx++) + if (extraspec && extraspec->comp_keygrip) { - const char *data; - size_t datalen; - - l2 = gcry_sexp_find_token (list, s, 1); - if (! l2) + /* Module specific method to compute a keygrip. */ + if (extraspec->comp_keygrip (md, list)) goto fail; - data = gcry_sexp_nth_data (l2, 1, &datalen); - if (! data) - goto fail; - if (!is_rsa) + } + else + { + /* Generic method to compute a keygrip. */ + for (idx = 0, s = elems; *s; s++, idx++) { + const char *data; + size_t datalen; char buf[30]; - - sprintf (buf, "(1:%c%u:", *s, (unsigned int)datalen); + + l2 = gcry_sexp_find_token (list, s, 1); + if (! l2) + goto fail; + data = gcry_sexp_nth_data (l2, 1, &datalen); + if (! data) + goto fail; + + snprintf (buf, sizeof buf, "(1:%c%u:", *s, (unsigned int)datalen); gcry_md_write (md, buf, strlen (buf)); + gcry_md_write (md, data, datalen); + gcry_sexp_release (l2); + gcry_md_write (md, ")", 1); } - - /* PKCS-15 says that for RSA only the modulus should be hashed - - however, it is not clear wether this is meant to use the raw - bytes (assuming this is an unsigned integer) or whether the DER - required 0 should be prefixed. We hash the raw bytes. For - non-RSA we hash S-expressions. */ - gcry_md_write (md, data, datalen); - gcry_sexp_release (l2); - if (!is_rsa) - gcry_md_write (md, ")", 1); } - + if (!array) { array = gcry_malloc (20); Modified: trunk/cipher/rsa.c =================================================================== --- trunk/cipher/rsa.c 2008-08-29 11:09:26 UTC (rev 1309) +++ trunk/cipher/rsa.c 2008-08-29 15:40:24 UTC (rev 1310) @@ -686,7 +686,45 @@ } +/* Compute a keygrip. MD is the hash context which we are going to + update. KEYPARAM is an S-expression with the key parameters, this + is usually a public key but may also be a secret key. An example + of such an S-expression is: + (rsa + (n #00B...#) + (e #010001#)) + + PKCS-15 says that for RSA only the modulus should be hashed - + however, it is not clear wether this is meant to use the raw bytes + (assuming this is an unsigned integer) or whether the DER required + 0 should be prefixed. We hash the raw bytes. */ +static gpg_err_code_t +compute_keygrip (gcry_md_hd_t md, gcry_sexp_t keyparam) +{ + gcry_sexp_t l1; + const char *data; + size_t datalen; + + l1 = gcry_sexp_find_token (keyparam, "n", 1); + if (!l1) + return GPG_ERR_NO_OBJ; + + data = gcry_sexp_nth_data (l1, 1, &datalen); + if (!data) + { + gcry_sexp_release (l1); + return GPG_ERR_NO_OBJ; + } + + gcry_md_write (md, data, datalen); + gcry_sexp_release (l1); + + return 0; +} + + + /* Self-test section. @@ -761,6 +799,7 @@ pk_extra_spec_t _gcry_pubkey_extraspec_rsa = { run_selftests, - rsa_generate + rsa_generate, + compute_keygrip }; Modified: trunk/doc/gcrypt.texi =================================================================== --- trunk/doc/gcrypt.texi 2008-08-29 11:09:26 UTC (rev 1309) +++ trunk/doc/gcrypt.texi 2008-08-29 15:40:24 UTC (rev 1310) @@ -529,10 +529,10 @@ @itemize @item -If the file @file{/proc/fips140} exists and contains the string value - at code{1}, Libgcrypt is put into FIPS mode at initialization time. -Obviously this works only on systems with a @code{proc} file system -(ie.e GNU/Linux). +If the file @file{/proc/sys/crypto/fips_enabled} exists and contains a +numeric value other than @code{0}, Libgcrypt is put into FIPS mode at +initialization time. Obviously this works only on systems with a + at code{proc} file system (ie.e GNU/Linux). @item If the file @file{/etc/gcrypt/fips140.force} exists, Libgcrypt is put Modified: trunk/mpi/mpicoder.c =================================================================== --- trunk/mpi/mpicoder.c 2008-08-29 11:09:26 UTC (rev 1309) +++ trunk/mpi/mpicoder.c 2008-08-29 15:40:24 UTC (rev 1310) @@ -247,8 +247,8 @@ #endif } - /* this is sub-optimal but we need to do the shift oepration because - * the caller has to free the returned buffer */ + /* This is sub-optimal but we need to do the shift operation + because the caller has to free the returned buffer */ for(p=buffer; !*p && *nbytes; p++, --*nbytes ) ; if( p != buffer ) Modified: trunk/src/cipher-proto.h =================================================================== --- trunk/src/cipher-proto.h 2008-08-29 11:09:26 UTC (rev 1309) +++ trunk/src/cipher-proto.h 2008-08-29 15:40:24 UTC (rev 1310) @@ -48,7 +48,11 @@ gcry_mpi_t *skey, gcry_mpi_t **retfactors); +/* The type is used to compute the keygrip. */ +typedef gpg_err_code_t (*pk_comp_keygrip_t) + (gcry_md_hd_t md, gcry_sexp_t keyparm); + /* Extra module specification structures. These are used for internal modules which provide more functions than available through the public algorithm register APIs. */ @@ -66,6 +70,7 @@ { selftest_func_t selftest; pk_ext_generate_t ext_generate; + pk_comp_keygrip_t comp_keygrip; } pk_extra_spec_t; Modified: trunk/src/fips.c =================================================================== --- trunk/src/fips.c 2008-08-29 11:09:26 UTC (rev 1309) +++ trunk/src/fips.c 2008-08-29 15:40:24 UTC (rev 1310) @@ -115,13 +115,14 @@ { FILE *fp; int saved_errno; + static const char const procfname[] = "/proc/sys/crypto/fips_enabled"; - fp = fopen ("/proc/fips140", "r"); + fp = fopen (procfname, "r"); if (fp) { char line[256]; - if (fgets (line, sizeof line, fp) && atoi (line) == 1) + if (fgets (line, sizeof line, fp) && atoi (line)) { /* System is in fips mode. */ fclose (fp); @@ -136,7 +137,7 @@ /* Problem reading the fips file despite that we have the proc file system. We better stop right away. */ log_info ("FATAL: error reading `%s' in libgcrypt: %s\n", - "/proc/fips140", strerror (saved_errno)); + procfname, strerror (saved_errno)); abort (); } } Modified: trunk/tests/keygrip.c =================================================================== --- trunk/tests/keygrip.c 2008-08-29 11:09:26 UTC (rev 1309) +++ trunk/tests/keygrip.c 2008-08-29 15:40:24 UTC (rev 1310) @@ -45,15 +45,29 @@ exit (1); } +static void +print_hex (const char *text, const void *buf, size_t n) +{ + const unsigned char *p = buf; + + fputs (text, stdout); + for (; n; n--, p++) + printf ("%02X", *p); + putchar ('\n'); +} + + static struct { + int algo; const char *key; const unsigned char grip[20]; } key_grips[] = { { + GCRY_PK_RSA, "(private-key" " (rsa" " (n #00B6B509596A9ECABC939212F891E656A626BA07DA8521A9CAD4C08E640C04052FBB87F424EF1A0275A48A9299AC9DB69ABE3D0124E6C756B1F7DFB9B842D6251AEA6EE85390495CADA73D671537FCE5850A932F32BAB60AB1AC1F852C1F83C625E7A7D70CDA9EF16D5C8E47739D77DF59261ABE8454807FF441E143FBD37F8545#)" @@ -65,6 +79,7 @@ "\x32\xCF\xFA\x85\xB1\x79\x1F\xBB\x26\x14\xE9\x1A\xFD\xF3\xAF\xE3\x32\x08\x2E\x25" }, { + GCRY_PK_DSA, " (public-key" " (dsa" " (p #0084E4C626E16005770BD9509ABF7354492E85B8C0060EFAAAEC617F725B592FAA59DF5460575F41022776A9718CE62EDD542AB73C7720869EBDBC834D174ADCD7136827DF51E2613545A25CA573BC502A61B809000B6E35F5EB7FD6F18C35678C23EA1C3638FB9CFDBA2800EE1B62F41A4479DE824F2834666FBF8DC5B53C2617#)" @@ -75,6 +90,7 @@ }, { + GCRY_PK_DSA, "(private-key" " (dsa" " (p #0084E4C626E16005770BD9509ABF7354492E85B8C0060EFAAAEC617F725B592FAA59DF5460575F41022776A9718CE62EDD542AB73C7720869EBDBC834D174ADCD7136827DF51E2613545A25CA573BC502A61B809000B6E35F5EB7FD6F18C35678C23EA1C3638FB9CFDBA2800EE1B62F41A4479DE824F2834666FBF8DC5B53C2617#)" @@ -83,7 +99,40 @@ " (y #3D5DD14AFA2BF24A791E285B90232213D0E3BA74AB1109E768AED19639A322F84BB7D959E2BA92EF73DE4C7F381AA9F4053CFA3CD4527EF9043E304E5B95ED0A3A5A9D590AA641C13DB2B6E32B9B964A6A2C730DD3EA7C8E13F7A140AFF1A91CE375E9B9B960384779DC4EA180FA1F827C52288F366C0770A220F50D6D8FD6F6#)" " (x #0087F9E91BFBCC1163DE71ED86D557708E32F8ADDE#)))", "\x04\xA3\x4F\xA0\x2B\x03\x94\xD7\x32\xAD\xD5\x9B\x50\xAF\xDB\x5D\x57\x22\xA6\x10" + }, + { + GCRY_PK_ECDSA, + "(public-key" + " (ecdsa" + " (p #00FFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFF#)" + " (a #00FFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFC#)" + " (b #5AC635D8AA3A93E7B3EBBD55769886BC651D06B0CC53B0F63BCE3C3E27D2604B#)" + " (g #046B17D1F2E12C4247F8BCE6E563A440F277037D812DEB33A0F4A13945D898C2964FE342E2FE1A7F9B8EE7EB4A7C0F9E162BCE33576B315ECECBB6406837BF51F5#)" + " (n #00FFFFFFFF00000000FFFFFFFFFFFFFFFFBCE6FAADA7179E84F3B9CAC2FC632551#)" + " (q #04C8A4CEC2E9A9BC8E173531A67B0840DF345C32E261ADD780E6D83D56EFADFD5DE872F8B854819B59543CE0B7F822330464FBC4E6324DADDCD9D059554F63B344#)))", + "\xE6\xDF\x94\x2D\xBD\x8C\x77\x05\xA3\xDD\x41\x6E\xFC\x04\x01\xDB\x31\x0E\x99\xB6" + }, + { + GCRY_PK_ECDSA, + "(public-key" + " (ecdsa" + " (p #00FFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFF#)" + " (curve \"NIST P-256\")" + " (b #5AC635D8AA3A93E7B3EBBD55769886BC651D06B0CC53B0F63BCE3C3E27D2604B#)" + " (g #046B17D1F2E12C4247F8BCE6E563A440F277037D812DEB33A0F4A13945D898C2964FE342E2FE1A7F9B8EE7EB4A7C0F9E162BCE33576B315ECECBB6406837BF51F5#)" + " (n #00FFFFFFFF00000000FFFFFFFFFFFFFFFFBCE6FAADA7179E84F3B9CAC2FC632551#)" + " (q #04C8A4CEC2E9A9BC8E173531A67B0840DF345C32E261ADD780E6D83D56EFADFD5DE872F8B854819B59543CE0B7F822330464FBC4E6324DADDCD9D059554F63B344#)))", + "\xE6\xDF\x94\x2D\xBD\x8C\x77\x05\xA3\xDD\x41\x6E\xFC\x04\x01\xDB\x31\x0E\x99\xB6" + }, + { + GCRY_PK_ECDSA, + "(public-key" + " (ecdsa" + " (curve secp256r1)" + " (q #04C8A4CEC2E9A9BC8E173531A67B0840DF345C32E261ADD780E6D83D56EFADFD5DE872F8B854819B59543CE0B7F822330464FBC4E6324DADDCD9D059554F63B344#)))", + "\xE6\xDF\x94\x2D\xBD\x8C\x77\x05\xA3\xDD\x41\x6E\xFC\x04\x01\xDB\x31\x0E\x99\xB6" } + }; static void @@ -97,12 +146,27 @@ for (i = 0; i < (sizeof (key_grips) / sizeof (*key_grips)); i++) { From cvs at cvs.gnupg.org Sun Aug 31 13:55:10 2008 From: cvs at cvs.gnupg.org (svn author mo) Date: Sun, 31 Aug 2008 13:55:10 +0200 Subject: [svn] GnuPG - r4821 - trunk/scd Message-ID: Author: mo Date: 2008-08-31 13:55:09 +0200 (Sun, 31 Aug 2008) New Revision: 4821 Modified: trunk/scd/ChangeLog trunk/scd/app-openpgp.c trunk/scd/command.c trunk/scd/scdaemon.c Log: 2008-08-30 Moritz * scdaemon.c (main): Use estream_asprintf instead of asprintf. * command.c (update_reader_status_file): Likewise. (cmd_serialno): Use estream_asprintf instead of asprintf and xfree instead of free to release memory allocated through (estream_)asprintf. (cmd_learn): Likewise. (pin_cb): Likewise. * app-openpgp.c (get_public_key): Likewise. Modified: trunk/scd/ChangeLog =================================================================== --- trunk/scd/ChangeLog 2008-08-28 14:57:25 UTC (rev 4820) +++ trunk/scd/ChangeLog 2008-08-31 11:55:09 UTC (rev 4821) @@ -1,3 +1,14 @@ +2008-08-30 Moritz + + * scdaemon.c (main): Use estream_asprintf instead of asprintf. + * command.c (update_reader_status_file): Likewise. + (cmd_serialno): Use estream_asprintf instead of asprintf + and xfree instead of free to release memory allocated + through (estream_)asprintf. + (cmd_learn): Likewise. + (pin_cb): Likewise. + * app-openpgp.c (get_public_key): Likewise. + 2008-08-18 Werner Koch * app-openpgp.c (do_setattr): Fix test for v2 cards. Modified: trunk/scd/app-openpgp.c =================================================================== --- trunk/scd/app-openpgp.c 2008-08-28 14:57:25 UTC (rev 4820) +++ trunk/scd/app-openpgp.c 2008-08-31 11:55:09 UTC (rev 4821) @@ -1093,9 +1093,9 @@ } hexkeyid = fpr + 24; - ret = asprintf (&command, - "gpg --list-keys --with-colons --with-key-data '%s'", - fpr); + ret = estream_asprintf (&command, + "gpg --list-keys --with-colons --with-key-data '%s'", + fpr); if (ret < 0) { err = gpg_error_from_syserror (); @@ -1103,7 +1103,7 @@ } fp = popen (command, "r"); - free (command); + xfree (command); if (!fp) { err = gpg_error_from_syserror (); Modified: trunk/scd/command.c =================================================================== --- trunk/scd/command.c 2008-08-28 14:57:25 UTC (rev 4820) +++ trunk/scd/command.c 2008-08-31 11:55:09 UTC (rev 4821) @@ -471,13 +471,13 @@ if (rc) return rc; - rc = asprintf (&serial_and_stamp, "%s %lu", serial, (unsigned long)stamp); + rc = estream_asprintf (&serial_and_stamp, "%s %lu", serial, (unsigned long)stamp); xfree (serial); if (rc < 0) return out_of_core (); rc = 0; assuan_write_status (ctx, "SERIALNO", serial_and_stamp); - free (serial_and_stamp); + xfree (serial_and_stamp); return 0; } @@ -567,7 +567,7 @@ rc = app_get_serial_and_stamp (ctrl->app_ctx, &serial, &stamp); if (rc) return rc; - rc = asprintf (&serial_and_stamp, "%s %lu", serial, (unsigned long)stamp); + rc = estream_asprintf (&serial_and_stamp, "%s %lu", serial, (unsigned long)stamp); xfree (serial); if (rc < 0) return out_of_core (); @@ -578,26 +578,26 @@ { char *command; - rc = asprintf (&command, "KNOWNCARDP %s", serial_and_stamp); + rc = estream_asprintf (&command, "KNOWNCARDP %s", serial_and_stamp); if (rc < 0) { - free (serial_and_stamp); + xfree (serial_and_stamp); return out_of_core (); } rc = 0; rc = assuan_inquire (ctx, command, NULL, NULL, 0); - free (command); /* (must use standard free here) */ + xfree (command); if (rc) { if (gpg_err_code (rc) != GPG_ERR_ASS_CANCELED) log_error ("inquire KNOWNCARDP failed: %s\n", gpg_strerror (rc)); - free (serial_and_stamp); + xfree (serial_and_stamp); return rc; } /* not canceled, so we have to proceeed */ } - free (serial_and_stamp); + xfree (serial_and_stamp); } /* Let the application print out its collection of useful status @@ -784,11 +784,11 @@ if (info) { log_debug ("prompting for keypad entry '%s'\n", info); - rc = asprintf (&command, "POPUPKEYPADPROMPT %s", info); + rc = estream_asprintf (&command, "POPUPKEYPADPROMPT %s", info); if (rc < 0) return gpg_error (gpg_err_code_from_errno (errno)); rc = assuan_inquire (ctx, command, &value, &valuelen, MAXLEN_PIN); - free (command); + xfree (command); } else { @@ -804,14 +804,14 @@ *retstr = NULL; log_debug ("asking for PIN '%s'\n", info); - rc = asprintf (&command, "NEEDPIN %s", info); + rc = estream_asprintf (&command, "NEEDPIN %s", info); if (rc < 0) return gpg_error (gpg_err_code_from_errno (errno)); /* Fixme: Write an inquire function which returns the result in secure memory and check all further handling of the PIN. */ rc = assuan_inquire (ctx, command, &value, &valuelen, MAXLEN_PIN); - free (command); + xfree (command); if (rc) return rc; @@ -1918,7 +1918,7 @@ gpg_error_t err; homestr = make_filename (opt.homedir, NULL); - if (asprintf (&envstr, "GNUPGHOME=%s", homestr) < 0) + if (estream_asprintf (&envstr, "GNUPGHOME=%s", homestr) < 0) log_error ("out of core while building environment\n"); else { @@ -1946,7 +1946,7 @@ log_error ("failed to run event handler `%s': %s\n", fname, gpg_strerror (err)); xfree (fname); - free (envstr); + xfree (envstr); } xfree (homestr); } Modified: trunk/scd/scdaemon.c =================================================================== --- trunk/scd/scdaemon.c 2008-08-28 14:57:25 UTC (rev 4820) +++ trunk/scd/scdaemon.c 2008-08-31 11:55:09 UTC (rev 4821) @@ -702,8 +702,8 @@ close (fd); /* create the info string: :: */ - if (asprintf (&infostr, "SCDAEMON_INFO=%s:%lu:1", - socket_name, (ulong)pid ) < 0) + if (estream_asprintf (&infostr, "SCDAEMON_INFO=%s:%lu:1", + socket_name, (ulong) pid) < 0) { log_error ("out of core\n"); kill (pid, SIGTERM); @@ -738,7 +738,7 @@ { printf ( "%s; export SCDAEMON_INFO;\n", infostr); } - free (infostr); + xfree (infostr); exit (0); } /* NOTREACHED */