Import gcrypt public-key cryptography and implement signature checking.

This commit is contained in:
Vladimir 'phcoder' Serbinenko 2013-01-11 21:32:42 +01:00
parent 535714bdcf
commit 5e3b8dcbb5
238 changed files with 40500 additions and 417 deletions

View file

@ -1,3 +1,93 @@
2010-08-19 Werner Koch <wk@g10code.com>
* cipher.c (gcry_cipher_open): Remove double release of the module.
Fixes bug#1263.
2010-06-10 Jeff Johnson <n3npq@mac.com> (wk)
* ecc.c (ecc_generate_ext): Parse transient-key flag.
(generate_key): Add arg TRANSIENT_KEY and use it to set the random
level.
2010-04-12 Brad Hards <bradh@frogmouth.net> (wk)
Spelling fixes.
2010-03-26 Werner Koch <wk@g10code.com>
* tiger.c (asn): Unfetter the old TIGER from an OID.
(TIGER_CONTEXT): Add field VARIANT.
(tiger_init): Factor code out to ...
(do_init): New.
(tiger1_init, tiger2_init): New.
(_gcry_digest_spec_tiger1, _gcry_digest_spec_tiger2): New.
* md.c (digest_table): Add TIGER1 and TIGER2 variants.
2009-12-11 Werner Koch <wk@g10code.com>
* sha256.c (Cho, Maj, Sum0, Sum1): Turn macros into inline
functions.
(transform): Partly unroll to interweave the chain variables
* sha512.c (ROTR, Ch, Maj, Sum0, Sum1): Turn macros into inline
functions.
(transform): Partly unroll to interweave the chain variables.
Suggested by Christian Grothoff.
2009-12-10 Werner Koch <wk@g10code.com>
* Makefile.am (o_flag_munging): New.
(tiger.o, tiger.lo): Use it.
* cipher.c (do_ctr_encrypt): Add arg OUTBUFLEN. Check for
suitable value. Add check for valid inputlen. Wipe temporary
memory.
(do_ctr_decrypt): Likewise.
(do_cbc_encrypt, do_cbc_decrypt): Add arg OUTBUFLEN. Check for
suitable value. Move check for valid inputlen to here; change
returned error from INV_ARG to INV_LENGTH.
(do_ecb_encrypt, do_ecb_decrypt): Ditto.
(do_cfb_encrypt, do_cfb_decrypt): Ditto.
(do_ofb_encrypt, do_ofb_decrypt): Ditto.
(cipher_encrypt, cipher_encrypt): Adjust for above changes.
(gcry_cipher_encrypt, gcry_cipher_decrypt): Simplify.
2009-12-09 Werner Koch <wk@g10code.com>
* cipher.c (gcry_cipher_open): Allow for GCRY_CIPHER_MODE_AESWRAP.
(cipher_encrypt, cipher_decrypt): Ditto.
(do_aeswrap_encrypt, do_aeswrap_decrypt): New.
(struct gcry_cipher_handle): Add field marks.
(cipher_setkey, cipher_setiv): Update marks flags.
(cipher_reset): Reset marks.
(cipher_encrypt, cipher_decrypt): Add new arg OUTBUFLEN.
(gcry_cipher_encrypt, gcry_cipher_decrypt): Pass outbuflen to
cipher_encrypt. Replace GPG_ERR_TOO_SHORT by
GPG_ERR_BUFFER_TOO_SHORT.
2009-08-21 Werner Koch <wk@g10code.com>
* dsa.c (dsa_generate_ext): Release retfactors array before
setting it to NULL. Reported by Daiko Ueno.
2009-07-02 Werner Koch <wk@g10code.com>
* md.c (md_read): Fix incomplete check for NULL.
Reported by Fabian Kail.
2009-03-31 Werner Koch <wk@g10code.com>
* rsa.c (rsa_check_secret_key): Return GPG_ERR_BAD_SECKEY and not
GPG_ERR_PUBKEY_ALGO.
2009-02-16 Werner Koch <wk@g10code.com>
* rsa.c (generate_x931): Do not initialize TBL with automatic
variables.
* whirlpool.c, tiger.c, sha256.c, sha1.c, rmd160.c, md5.c
* md4.c, crc.c: Remove memory.h. This is garbage from gnupg.
Reported by Dan Fandrich.
2009-01-22 Werner Koch <wk@g10code.com>
* ecc.c (compute_keygrip): Remove superfluous const.
@ -3888,8 +3978,8 @@ Mon Feb 16 10:08:47 1998 Werner Koch (wk@isil.d.shuttle.de)
(digest_algo_to_string): New.
Copyright 1998,1999,2000,2001,2002,2003,2004,2005,2006
2007, 2008, 2009 Free Software Foundation, Inc.
Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006
2007, 2008, 2009, 2010 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

View file

@ -0,0 +1,82 @@
# Makefile for cipher modules
# Copyright (C) 1998, 1999, 2000, 2001, 2002,
# 2003, 2009 Free Software Foundation, Inc.
#
# This file is part of Libgcrypt.
#
# Libgcrypt is free software; you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as
# published by the Free Software Foundation; either version 2.1 of
# the License, or (at your option) any later version.
#
# Libgcrypt is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this program; if not, see <http://www.gnu.org/licenses/>.
# Process this file with automake to produce Makefile.in
EXTRA_DIST = Manifest
# Need to include ../src in addition to top_srcdir because gcrypt.h is
# a built header.
AM_CPPFLAGS = -I../src -I$(top_srcdir)/src
AM_CFLAGS = $(GPG_ERROR_CFLAGS)
noinst_LTLIBRARIES = libcipher.la
GCRYPT_MODULES = @GCRYPT_CIPHERS@ @GCRYPT_PUBKEY_CIPHERS@ @GCRYPT_DIGESTS@
libcipher_la_DEPENDENCIES = $(GCRYPT_MODULES)
libcipher_la_LIBADD = $(GCRYPT_MODULES)
libcipher_la_SOURCES = \
cipher.c pubkey.c ac.c md.c \
hmac-tests.c \
bithelp.h \
primegen.c \
hash-common.c hash-common.h \
rmd.h
EXTRA_libcipher_la_SOURCES = \
arcfour.c \
blowfish.c \
cast5.c \
crc.c \
des.c \
dsa.c \
elgamal.c \
ecc.c \
md4.c \
md5.c \
rijndael.c rijndael-tables.h \
rmd160.c \
rsa.c \
seed.c \
serpent.c \
sha1.c \
sha256.c \
sha512.c \
tiger.c \
whirlpool.c \
twofish.c \
rfc2268.c \
camellia.c camellia.h camellia-glue.c
if ENABLE_O_FLAG_MUNGING
o_flag_munging = sed -e 's/-O[2-9s]*/-O1/g'
else
o_flag_munging = cat
endif
# We need to lower the optimization for this module.
tiger.o: $(srcdir)/tiger.c
`echo $(COMPILE) -c $(srcdir)/tiger.c | $(o_flag_munging) `
tiger.lo: $(srcdir)/tiger.c
`echo $(LTCOMPILE) -c $(srcdir)/tiger.c | $(o_flag_munging) `

View file

@ -0,0 +1,73 @@
# Manifest - checksums of the cipher directory
# Copyright 2003 Free Software Foundation, Inc.
#
# This file is part of Libgcrypt.
#
# Libgcrypt is free software; you can redistribute it and/or modify
# it under the terms of the GNU Lesser general Public License as
# published by the Free Software Foundation; either version 2.1 of
# the License, or (at your option) any later version.
#
# Libgcrypt is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
# Checksums for all source files in this directory. Format is
# filename, blanks, base-64 part of an OpenPGP detached signature
# without the header lines. Blank lines and lines beginning with a
# hash mark are ignored. A tool to process this file is available by
# cvs -d :pserver:anoncvs@cvs.gnupg.org:/cvs/wk co misc-scripts/manifest-tool
#
# The special entry "$names$" holds a signature over all sorted
# filenames excluding itself.
# Algorithm API
cipher.c iQCVAwUAQDzrVjEAnp832S/7AQIPDgP+OVJ/YNWY5m7c09EBbPAzL/WsGoj6wrBNMmkRlMOqTHeh+OOtjuFHt1f9uhfM2Nzl7sJ5+h4ryZKLEZmQPRMTZTnAqkvGdsrJWJnigUA9QwYdV0ONqC9C63gpuG465gO9TZVOqlQu/FTxSRuTQYUulkaBNG71n8nZEOusBVwV2YA==58xH
pubkey.c iQCVAwUAP9XQ3jEAnp832S/7AQJ5UgQAyHfEBvPVJ8wTRg8c7ixS2GiVmIgwIo5tvQaiQJTPWASevvYrB+2Z2qa9cATyu50ACjLzbaquGBgPzjJV3dU/qttT1gCqRuN/LCNvXFe5qnIZezejc3RAadFNTw/pOTHq0wxD1Keg66ruei9R36Nba59pEQIWIBXTfubRft2hMYk==E09t
ac.c iQCVAwUAQDzsOzEAnp832S/7AQJCBQP/WI6EV/dsR4rmha6RVhvkjZo17kQ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InWR7NmevBkKvhsJALjVooc0KGQfo2lAAmy3Xi/4QQN8VPn51DVjDIgf7x+DQh/9TFJHMccxI9asUgi4+TNnmMqLU1k3N8S2PjyZ1sjeC8B79fKPpwCzj72WkqPkzZw3l2jArr+dU==NdJT
rfc2268.c iQCVAwUAQCN+3jEAnp832S/7AQLv1gQA1hJh29hAjKi4uLSGxXvJ6cyYmPdmevdKrbLnuHZWtHe4xvCgy/nTdEojEpxgLp/hL/ogasuWRC1W16Wiz9ryxf7YR0uhZWayO/bQNagpfU5MIkJTLuKqqgpwYumCSQfOugXVAqcgEzj+13eeyJaFVrzwrNa67sh84nmbjOjNjvE==0zBq
# Random number related
random.c iQCVAwUAP7nsITEAnp832S/7AQK4SAQAtvfUgrtGOQ2PlxGMla0qJLPHjJacMwgq0ecusiI79elPdDsFfCCk6dK1Ug2kFbNm22nCGHNcUquqbX7noi7ZVQnmPBQXzyLNZd7GmrawRZfdlRerTUDBpSnR8V8ui/5+YYp627E7kKGC0hPSgqXFql6oBMIfno0LZwFJTjIevRY==L419
random.h iQCVAwUAP7ovKDEAnp832S/7AQJ3bQQAjnPebnyTC7sphAv2I7uIz+yPgw1ZfbVhLv+OiWDlO9ish+fRyyMpy+HELBOgZjJdgRegqhlZC6qyns5arM/VglYi+PzvdLO3hIqHE/YFfpIFPz8wBrcmlqrYyd3CsGqcYsfjocXNttCBLeSWmoJ09ltKQH8yzJf3oAgN6X1yuc4==eNoU
rand-internal.h iQCVAwUAP7ouvDEAnp832S/7AQLYnAQAhdI7ERoJVCkV8GiV7MjaUxv1WIL7iZ+jIOvVhv4fNyhCGCGoEtTjkyput/lj7Nsh3FXEqRhypGGrCLf47x/gua5n+BwffogxVyUDqiOyyGhNTPpe3fQcNBvbPCtco8yMK4GJO5G3BqzlPyN+BMeogLymyV6Sm1mvh5LZDyAFbfQ==tZSE
rndlinux.c iQCVAwUAP9iPYTEAnp832S/7AQL6/AP/ZDrbOkVuB9qJ7sKeX1MImZEsz3mi0xPovJzaB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Vu8Qk4ylqv//BGyeRa3jZCcfPHI35q6HilCs2VBm8hiBMjHSqY/VPn2ZQ0yg/lt6qEvl7YjsLmyMICvjG+ncszHoq9pRvnF3vTnM18sPIioXLk8fskuM0XOCNBs0ARBAQjY9UGI==olUN
# Configuration
Makefile.am iQCVAwUAQCN33TEAnp832S/7AQKFJAQAz7BDkC814q+QiuE/jnutJHR5qlgbrm3ikGbQwdRzYUscst4bCCWy3uKL/sIPGLg+JQXtF5FnsQy3s4D9BOYhp72cA9ktYK65hhi4pNm/JQ0lXkZMNfk8Go5lNzKezlWwHvkMwRXR0Fep0wPdyeaKW5BfaW2ABvgep6Bp+hHEbyg==zSyi
$names$ iQCVAwUAQCN3EDEAnp832S/7AQJXLAP8DvHTpm5DkTF35EmzeKpi9ie59AZcZanD19ir/e/7+PaQxr2riuLHDGwFKTju+dcvvBsqrygXOC378GXVWzIF2OZwS4EdDcJ+pgojo9UpsqpKsJHouY4Ugx5cQialxba462kUn8hcihSBnMyc4LzbJ5WQ4puQuqy544d2x94+2ms==G4Ls

View file

@ -2499,7 +2499,7 @@ typedef enum dencode_action
dencode_action_t;
/* Encode or decode a message according to the the encoding method
METHOD; ACTION specifies wether the message that is contained in
METHOD; ACTION specifies whether the message that is contained in
BUFFER_IN and of length BUFFER_IN_N should be encoded or decoded.
The resulting message will be stored in a newly allocated buffer in
BUFFER_OUT and BUFFER_OUT_N. */

File diff suppressed because it is too large Load diff

View file

@ -25,7 +25,6 @@
#include <string.h>
#include "g10lib.h"
#include "memory.h"
#include "cipher.h"
#include "bithelp.h"

View file

@ -106,7 +106,7 @@
*
* if ( (error_msg = selftest()) )
* {
* fprintf(stderr, "An error in the DES/Tripple-DES implementation occured: %s\n", error_msg);
* fprintf(stderr, "An error in the DES/Triple-DES implementation occurred: %s\n", error_msg);
* abort();
* }
*/

View file

@ -907,6 +907,7 @@ dsa_generate_ext (int algo, unsigned int nbits, unsigned long evalue,
gcry_mpi_release ((*retfactors)[i]);
(*retfactors)[i] = NULL;
}
gcry_free (*retfactors);
*retfactors = NULL;
if (ec)
{

View file

@ -1,5 +1,5 @@
/* ecc.c - Elliptic Curve Cryptography
Copyright (C) 2007, 2008 Free Software Foundation, Inc.
Copyright (C) 2007, 2008, 2010 Free Software Foundation, Inc.
This file is part of Libgcrypt.
@ -504,6 +504,7 @@ generate_curve (unsigned int nbits, const char *name,
*/
static gpg_err_code_t
generate_key (ECC_secret_key *sk, unsigned int nbits, const char *name,
int transient_key,
gcry_mpi_t g_x, gcry_mpi_t g_y,
gcry_mpi_t q_x, gcry_mpi_t q_y)
{
@ -512,6 +513,7 @@ generate_key (ECC_secret_key *sk, unsigned int nbits, const char *name,
gcry_mpi_t d;
mpi_point_t Q;
mpi_ec_t ctx;
gcry_random_level_t random_level;
err = generate_curve (nbits, name, &E, &nbits);
if (err)
@ -528,9 +530,11 @@ generate_key (ECC_secret_key *sk, unsigned int nbits, const char *name,
log_mpidump ("ecc generation Gz", E.G.z);
}
random_level = transient_key ? GCRY_STRONG_RANDOM : GCRY_VERY_STRONG_RANDOM;
if (DBG_CIPHER)
log_debug ("choosing a random x of size %u\n", nbits);
d = gen_k (E.n, GCRY_VERY_STRONG_RANDOM);
log_debug ("choosing a random x of size %u%s\n", nbits,
transient_key? " (transient-key)":"");
d = gen_k (E.n, random_level);
/* Compute Q. */
point_init (&Q);
@ -962,6 +966,7 @@ ecc_generate_ext (int algo, unsigned int nbits, unsigned long evalue,
gcry_mpi_t g_x, g_y, q_x, q_y;
char *curve_name = NULL;
gcry_sexp_t l1;
int transient_key = 0;
(void)algo;
(void)evalue;
@ -978,6 +983,14 @@ ecc_generate_ext (int algo, unsigned int nbits, unsigned long evalue,
if (!curve_name)
return GPG_ERR_INV_OBJ; /* No curve name or value too large. */
}
/* Parse the optional transient-key flag. */
l1 = gcry_sexp_find_token (genparms, "transient-key", 0);
if (l1)
{
transient_key = 1;
gcry_sexp_release (l1);
}
}
/* NBITS is required if no curve name has been given. */
@ -988,7 +1001,7 @@ ecc_generate_ext (int algo, unsigned int nbits, unsigned long evalue,
g_y = mpi_new (0);
q_x = mpi_new (0);
q_y = mpi_new (0);
ec = generate_key (&sk, nbits, curve_name, g_x, g_y, q_x, q_y);
ec = generate_key (&sk, nbits, curve_name, transient_key, g_x, g_y, q_x, q_y);
gcry_free (curve_name);
if (ec)
return ec;
@ -1266,7 +1279,7 @@ compute_keygrip (gcry_md_hd_t md, gcry_sexp_t keyparam)
}
/* Check that all parameters are known and normalize all MPIs (that
should not be required but we use an internal fucntion later and
should not be required but we use an internal function later and
thus we better make 100% sure that they are normalized). */
for (idx = 0; idx < 6; idx++)
if (!values[idx])

View file

@ -87,6 +87,10 @@ static struct digest_table_entry
#if USE_TIGER
{ &_gcry_digest_spec_tiger,
&dummy_extra_spec, GCRY_MD_TIGER },
{ &_gcry_digest_spec_tiger1,
&dummy_extra_spec, GCRY_MD_TIGER1 },
{ &_gcry_digest_spec_tiger2,
&dummy_extra_spec, GCRY_MD_TIGER2 },
#endif
#if USE_WHIRLPOOL
{ &_gcry_digest_spec_whirlpool,
@ -101,7 +105,7 @@ static gcry_module_t digests_registered;
/* This is the lock protecting DIGESTS_REGISTERED. */
static ath_mutex_t digests_registered_lock = ATH_MUTEX_INITIALIZER;
/* Flag to check wether the default ciphers have already been
/* Flag to check whether the default ciphers have already been
registered. */
static int default_digests_registered;
@ -948,10 +952,13 @@ md_read( gcry_md_hd_t a, int algo )
if (! algo)
{
/* return the first algorithm */
if (r && r->next)
log_debug ("more than one algorithm in md_read(0)\n");
return r->digest->read( &r->context.c );
/* Return the first algorithm */
if (r)
{
if (r->next)
log_debug ("more than one algorithm in md_read(0)\n");
return r->digest->read (&r->context.c);
}
}
else
{
@ -1135,7 +1142,7 @@ md_asn_oid (int algorithm, size_t *asnlen, size_t *mdlen)
* Note: Because this function is in most cases used to return an
* integer value, we can make it easier for the caller to just look at
* the return value. The caller will in all cases consult the value
* and thereby detecting whether a error occured or not (i.e. while checking
* and thereby detecting whether a error occurred or not (i.e. while checking
* the block size)
*/
gcry_error_t

View file

@ -53,7 +53,6 @@
#include <string.h>
#include "g10lib.h"
#include "memory.h"
#include "cipher.h"
#include "bithelp.h"

View file

@ -37,7 +37,6 @@
#include <string.h>
#include "g10lib.h"
#include "memory.h"
#include "cipher.h"
#include "bithelp.h"

View file

@ -988,7 +988,7 @@ is_prime (gcry_mpi_t n, int steps, unsigned int *count)
/* Given ARRAY of size N with M elements set to true produce a
modified array with the next permutation of M elements. Note, that
ARRAY is used in a one-bit-per-byte approach. To detected the last
permutation it is useful to intialize the array with the first M
permutation it is useful to initialize the array with the first M
element set to true and use this test:
m_out_of_n (array, m, n);
for (i = j = 0; i < n && j < m; i++)
@ -1170,7 +1170,7 @@ gcry_prime_generate (gcry_mpi_t *prime, unsigned int prime_bits,
return gcry_error (err);
}
/* Check wether the number X is prime. */
/* Check whether the number X is prime. */
gcry_error_t
gcry_prime_check (gcry_mpi_t x, unsigned int flags)
{

View file

@ -85,7 +85,7 @@ static gcry_module_t pubkeys_registered;
/* This is the lock protecting PUBKEYS_REGISTERED. */
static ath_mutex_t pubkeys_registered_lock = ATH_MUTEX_INITIALIZER;;
/* Flag to check wether the default pubkeys have already been
/* Flag to check whether the default pubkeys have already been
registered. */
static int default_pubkeys_registered;
@ -1567,7 +1567,7 @@ sexp_data_to_mpi (gcry_sexp_t input, unsigned int nbits, gcry_mpi_t *ret_mpi,
Do a PK encrypt operation
Caller has to provide a public key as the SEXP pkey and data as a
SEXP with just one MPI in it. Alternativly S_DATA might be a
SEXP with just one MPI in it. Alternatively S_DATA might be a
complex S-Expression, similar to the one used for signature
verification. This provides a flag which allows to handle PKCS#1
block type 2 padding. The function returns a a sexp which may be
@ -2357,7 +2357,7 @@ gcry_pk_get_nbits (gcry_sexp_t key)
/* Return the so called KEYGRIP which is the SHA-1 hash of the public
key parameters expressed in a way depended on the algorithm.
key parameters expressed in a way depending on the algorithm.
ARRAY must either be 20 bytes long or NULL; in the latter case a
newly allocated array of that size is returned, otherwise ARRAY or
@ -2503,15 +2503,15 @@ gcry_pk_ctl (int cmd, void *buffer, size_t buflen)
care or a combination of the GCRY_PK_USAGE_xxx flags;
GCRYCTL_GET_ALGO_USAGE:
Return the usage glafs for the give algo. An invalid alog
does return 0. Disabled algos are ignored here becuase we
Return the usage flags for the given algo. An invalid algo
returns 0. Disabled algos are ignored here because we
only want to know whether the algo is at all capable of
the usage.
Note: Because this function is in most cases used to return an
integer value, we can make it easier for the caller to just look at
the return value. The caller will in all cases consult the value
and thereby detecting whether a error occured or not (i.e. while
and thereby detecting whether a error occurred or not (i.e. while
checking the block size) */
gcry_error_t
gcry_pk_algo_info (int algorithm, int what, void *buffer, size_t *nbytes)

View file

@ -22,7 +22,7 @@
/* This implementation was written by Nikos Mavroyanopoulos for GNUTLS
* as a Libgcrypt module (gnutls/lib/x509/rc2.c) and later adapted for
* direct use by Libgcrypt by Werner Koch. This implementation is
* only useful for pkcs#12 descryption.
* only useful for pkcs#12 decryption.
*
* The implementation here is based on Peter Gutmann's RRC.2 paper.
*/

View file

@ -24,7 +24,6 @@
#include <string.h>
#include "g10lib.h"
#include "memory.h"
#include "rmd.h"
#include "cipher.h" /* Only used for the rmd160_hash_buffer() prototype. */

View file

@ -444,18 +444,28 @@ generate_x931 (RSA_secret_key *sk, unsigned int nbits, unsigned long e_value,
else
{
/* Parameters to derive the key are given. */
/* Note that we explicitly need to setup the values of tbl
because some compilers (e.g. OpenWatcom, IRIX) don't allow
to initialize a structure with automatic variables. */
struct { const char *name; gcry_mpi_t *value; } tbl[] = {
{ "Xp1", &xp1 },
{ "Xp2", &xp2 },
{ "Xp", &xp },
{ "Xq1", &xq1 },
{ "Xq2", &xq2 },
{ "Xq", &xq },
{ NULL, NULL }
{ "Xp1" },
{ "Xp2" },
{ "Xp" },
{ "Xq1" },
{ "Xq2" },
{ "Xq" },
{ NULL }
};
int idx;
gcry_sexp_t oneparm;
tbl[0].value = &xp1;
tbl[1].value = &xp2;
tbl[2].value = &xp;
tbl[3].value = &xq1;
tbl[4].value = &xq2;
tbl[5].value = &xq;
for (idx=0; tbl[idx].name; idx++)
{
oneparm = gcry_sexp_find_token (deriveparms, tbl[idx].name, 0);
@ -572,7 +582,7 @@ generate_x931 (RSA_secret_key *sk, unsigned int nbits, unsigned long e_value,
/****************
* Test wether the secret key is valid.
* Test whether the secret key is valid.
* Returns: true if this is a valid key.
*/
static int
@ -876,7 +886,7 @@ rsa_check_secret_key (int algo, gcry_mpi_t *skey)
err = GPG_ERR_NO_OBJ; /* To check the key we need the optional
parameters. */
else if (!check_secret_key (&sk))
err = GPG_ERR_PUBKEY_ALGO;
err = GPG_ERR_BAD_SECKEY;
return err;
}
@ -942,7 +952,7 @@ rsa_decrypt (int algo, gcry_mpi_t *result, gcry_mpi_t *data,
gcry_mpi_mod (r, r, sk.n);
/* Calculate inverse of r. It practically impossible that the
follwing test fails, thus we do not add code to release
following test fails, thus we do not add code to release
allocated resources. */
if (!gcry_mpi_invm (ri, r, sk.n))
return GPG_ERR_INTERNAL;
@ -1053,7 +1063,7 @@ rsa_get_nbits (int algo, gcry_mpi_t *pkey)
(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
however, it is not clear whether 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

View file

@ -37,7 +37,6 @@
#endif
#include "g10lib.h"
#include "memory.h"
#include "bithelp.h"
#include "cipher.h"
#include "hash-common.h"

View file

@ -1,5 +1,5 @@
/* sha256.c - SHA256 hash function
* Copyright (C) 2003, 2006, 2008 Free Software Foundation, Inc.
* Copyright (C) 2003, 2006, 2008, 2009 Free Software Foundation, Inc.
*
* This file is part of Libgcrypt.
*
@ -41,7 +41,6 @@
#include <string.h>
#include "g10lib.h"
#include "memory.h"
#include "bithelp.h"
#include "cipher.h"
#include "hash-common.h"
@ -95,10 +94,6 @@ sha224_init (void *context)
/*
Transform the message X which consists of 16 32-bit-words. See FIPS
180-2 for details. */
#define Cho(x,y,z) (z ^ (x & (y ^ z))) /* (4.2) same as SHA-1's F1 */
#define Maj(x,y,z) ((x & y) | (z & (x|y))) /* (4.3) same as SHA-1's F3 */
#define Sum0(x) (ror ((x), 2) ^ ror ((x), 13) ^ ror ((x), 22)) /* (4.4) */
#define Sum1(x) (ror ((x), 6) ^ ror ((x), 11) ^ ror ((x), 25)) /* (4.5) */
#define S0(x) (ror ((x), 7) ^ ror ((x), 18) ^ ((x) >> 3)) /* (4.6) */
#define S1(x) (ror ((x), 17) ^ ror ((x), 19) ^ ((x) >> 10)) /* (4.7) */
#define R(a,b,c,d,e,f,g,h,k,w) do \
@ -114,6 +109,35 @@ sha224_init (void *context)
b = a; \
a = t1 + t2; \
} while (0)
/* (4.2) same as SHA-1's F1. */
static inline u32
Cho (u32 x, u32 y, u32 z)
{
return (z ^ (x & (y ^ z)));
}
/* (4.3) same as SHA-1's F3 */
static inline u32
Maj (u32 x, u32 y, u32 z)
{
return ((x & y) | (z & (x|y)));
}
/* (4.4) */
static inline u32
Sum0 (u32 x)
{
return (ror (x, 2) ^ ror (x, 13) ^ ror (x, 22));
}
/* (4.5) */
static inline u32
Sum1 (u32 x)
{
return (ror (x, 6) ^ ror (x, 11) ^ ror (x, 25));
}
static void
transform (SHA256_CONTEXT *hd, const unsigned char *data)
@ -172,8 +196,55 @@ transform (SHA256_CONTEXT *hd, const unsigned char *data)
for (; i < 64; i++)
w[i] = S1(w[i-2]) + w[i-7] + S0(w[i-15]) + w[i-16];
for (i=0; i < 64; i++)
R(a,b,c,d,e,f,g,h,K[i],w[i]);
for (i=0; i < 64;)
{
#if 0
R(a,b,c,d,e,f,g,h,K[i],w[i]);
i++;
#else
t1 = h + Sum1 (e) + Cho (e, f, g) + K[i] + w[i];
t2 = Sum0 (a) + Maj (a, b, c);
d += t1;
h = t1 + t2;
t1 = g + Sum1 (d) + Cho (d, e, f) + K[i+1] + w[i+1];
t2 = Sum0 (h) + Maj (h, a, b);
c += t1;
g = t1 + t2;
t1 = f + Sum1 (c) + Cho (c, d, e) + K[i+2] + w[i+2];
t2 = Sum0 (g) + Maj (g, h, a);
b += t1;
f = t1 + t2;
t1 = e + Sum1 (b) + Cho (b, c, d) + K[i+3] + w[i+3];
t2 = Sum0 (f) + Maj (f, g, h);
a += t1;
e = t1 + t2;
t1 = d + Sum1 (a) + Cho (a, b, c) + K[i+4] + w[i+4];
t2 = Sum0 (e) + Maj (e, f, g);
h += t1;
d = t1 + t2;
t1 = c + Sum1 (h) + Cho (h, a, b) + K[i+5] + w[i+5];
t2 = Sum0 (d) + Maj (d, e, f);
g += t1;
c = t1 + t2;
t1 = b + Sum1 (g) + Cho (g, h, a) + K[i+6] + w[i+6];
t2 = Sum0 (c) + Maj (c, d, e);
f += t1;
b = t1 + t2;
t1 = a + Sum1 (f) + Cho (f, g, h) + K[i+7] + w[i+7];
t2 = Sum0 (b) + Maj (b, c, d);
e += t1;
a = t1 + t2;
i += 8;
#endif
}
hd->h0 += a;
hd->h1 += b;
@ -184,10 +255,6 @@ transform (SHA256_CONTEXT *hd, const unsigned char *data)
hd->h6 += g;
hd->h7 += h;
}
#undef Cho
#undef Maj
#undef Sum0
#undef Sum1
#undef S0
#undef S1
#undef R

View file

@ -1,5 +1,5 @@
/* sha512.c - SHA384 and SHA512 hash functions
* Copyright (C) 2003, 2008 Free Software Foundation, Inc.
* Copyright (C) 2003, 2008, 2009 Free Software Foundation, Inc.
*
* This file is part of Libgcrypt.
*
@ -98,6 +98,36 @@ sha384_init (void *context)
}
static inline u64
ROTR (u64 x, u64 n)
{
return ((x >> n) | (x << (64 - n)));
}
static inline u64
Ch (u64 x, u64 y, u64 z)
{
return ((x & y) ^ ( ~x & z));
}
static inline u64
Maj (u64 x, u64 y, u64 z)
{
return ((x & y) ^ (x & z) ^ (y & z));
}
static inline u64
Sum0 (u64 x)
{
return (ROTR (x, 28) ^ ROTR (x, 34) ^ ROTR (x, 39));
}
static inline u64
Sum1 (u64 x)
{
return (ROTR (x, 14) ^ ROTR (x, 18) ^ ROTR (x, 41));
}
/****************
* Transform the message W which consists of 16 64-bit-words
*/
@ -182,21 +212,26 @@ transform (SHA512_CONTEXT *hd, const unsigned char *data)
}
#endif
#define ROTR(x,n) (((x)>>(n)) | ((x)<<(64-(n))))
#define Ch(x,y,z) (((x) & (y)) ^ ((~(x)) & (z)))
#define Maj(x,y,z) (((x) & (y)) ^ ((x) & (z)) ^ ((y) & (z)))
#define Sum0(x) (ROTR((x),28) ^ ROTR((x),34) ^ ROTR((x),39))
#define Sum1(x) (ROTR((x),14) ^ ROTR((x),18) ^ ROTR((x),41))
#define S0(x) (ROTR((x),1) ^ ROTR((x),8) ^ ((x)>>7))
#define S1(x) (ROTR((x),19) ^ ROTR((x),61) ^ ((x)>>6))
for (t = 16; t < 80; t++)
w[t] = S1 (w[t - 2]) + w[t - 7] + S0 (w[t - 15]) + w[t - 16];
for (t = 0; t < 80; t++)
for (t = 0; t < 80; )
{
u64 t1, t2;
/* Performance on a AMD Athlon(tm) Dual Core Processor 4050e
with gcc 4.3.3 using gcry_md_hash_buffer of each 10000 bytes
initialized to 0,1,2,3...255,0,... and 1000 iterations:
Not unrolled with macros: 440ms
Unrolled with macros: 350ms
Unrolled with inline: 330ms
*/
#if 0 /* Not unrolled. */
t1 = h + Sum1 (e) + Ch (e, f, g) + k[t] + w[t];
t2 = Sum0 (a) + Maj (a, b, c);
h = g;
@ -207,12 +242,53 @@ transform (SHA512_CONTEXT *hd, const unsigned char *data)
c = b;
b = a;
a = t1 + t2;
t++;
#else /* Unrolled to interweave the chain variables. */
t1 = h + Sum1 (e) + Ch (e, f, g) + k[t] + w[t];
t2 = Sum0 (a) + Maj (a, b, c);
d += t1;
h = t1 + t2;
/* printf("t=%d a=%016llX b=%016llX c=%016llX d=%016llX "
"e=%016llX f=%016llX g=%016llX h=%016llX\n",t,a,b,c,d,e,f,g,h); */
t1 = g + Sum1 (d) + Ch (d, e, f) + k[t+1] + w[t+1];
t2 = Sum0 (h) + Maj (h, a, b);
c += t1;
g = t1 + t2;
t1 = f + Sum1 (c) + Ch (c, d, e) + k[t+2] + w[t+2];
t2 = Sum0 (g) + Maj (g, h, a);
b += t1;
f = t1 + t2;
t1 = e + Sum1 (b) + Ch (b, c, d) + k[t+3] + w[t+3];
t2 = Sum0 (f) + Maj (f, g, h);
a += t1;
e = t1 + t2;
t1 = d + Sum1 (a) + Ch (a, b, c) + k[t+4] + w[t+4];
t2 = Sum0 (e) + Maj (e, f, g);
h += t1;
d = t1 + t2;
t1 = c + Sum1 (h) + Ch (h, a, b) + k[t+5] + w[t+5];
t2 = Sum0 (d) + Maj (d, e, f);
g += t1;
c = t1 + t2;
t1 = b + Sum1 (g) + Ch (g, h, a) + k[t+6] + w[t+6];
t2 = Sum0 (c) + Maj (c, d, e);
f += t1;
b = t1 + t2;
t1 = a + Sum1 (f) + Ch (f, g, h) + k[t+7] + w[t+7];
t2 = Sum0 (b) + Maj (b, c, d);
e += t1;
a = t1 + t2;
t += 8;
#endif
}
/* update chaining vars */
/* Update chaining vars. */
hd->h0 += a;
hd->h1 += b;
hd->h2 += c;

View file

@ -0,0 +1,105 @@
#include <stdio.h>
#include <stdlib.h>
#include <sys/resource.h>
int
main (int argc, char **argv)
{
struct rusage buf;
if (argc > 1)
{
system (argv[1]);
if (getrusage (RUSAGE_CHILDREN, &buf ))
{
perror ("getrusage");
return 1;
}
}
else
{
if (getrusage (RUSAGE_SELF, &buf ))
{
perror ("getrusage");
return 1;
}
}
printf ("ru_utime = %ld.%06ld\n",
buf.ru_utime.tv_sec, buf.ru_utime.tv_usec);
printf ("ru_stime = %ld.%06ld\n",
buf.ru_stime.tv_sec, buf.ru_stime.tv_usec);
printf ("ru_maxrss = %ld\n", buf.ru_maxrss );
printf ("ru_ixrss = %ld\n", buf.ru_ixrss );
printf ("ru_idrss = %ld\n", buf.ru_idrss );
printf ("ru_isrss = %ld\n", buf.ru_isrss );
printf ("ru_minflt = %ld\n", buf.ru_minflt );
printf ("ru_majflt = %ld\n", buf.ru_majflt );
printf ("ru_nswap = %ld\n", buf.ru_nswap );
printf ("ru_inblock = %ld\n", buf.ru_inblock );
printf ("ru_oublock = %ld\n", buf.ru_oublock );
printf ("ru_msgsnd = %ld\n", buf.ru_msgsnd );
printf ("ru_msgrcv = %ld\n", buf.ru_msgrcv );
printf ("ru_nsignals= %ld\n", buf.ru_nsignals );
printf ("ru_nvcsw = %ld\n", buf.ru_nvcsw );
printf ("ru_nivcsw = %ld\n", buf.ru_nivcsw );
fprintf (stderr, "ru_utime ru_stime ru_minflt ru_nccsw ru_nivcsw\n");
fprintf (stderr, "%ld.%06ld %ld.%06ld %5ld %5ld %5ld\n");
return 0;
}
/* Codesnippet for debugging in random.c. */
#if 0
static void
collect_rusage_stats (struct rusage *rb)
{
static int idx;
static struct rusage buf[100];
if (!rb)
{
int i;
fprintf (stderr, "ru_utime ru_stime ru_minflt ru_nvcsw ru_nivcsw\n");
for (i=0; i < idx; i++)
fprintf (stderr, "%ld.%06ld %ld.%06ld %5ld %5ld %5ld\n",
buf[i].ru_utime.tv_sec, buf[i].ru_utime.tv_usec,
buf[i].ru_stime.tv_sec, buf[i].ru_stime.tv_usec,
buf[i].ru_minflt,
buf[i].ru_nvcsw,
buf[i].ru_nivcsw);
}
else if (idx < DIM(buf))
{
buf[idx++] = *rb;
}
}
#endif
/*
void
_gcry_random_dump_stats()
{
@@ -233,8 +261,11 @@
rndstats.naddbytes, rndstats.addbytes,
rndstats.mixkey, rndstats.ngetbytes1, rndstats.getbytes1,
rndstats.ngetbytes2, rndstats.getbytes2 );
+
+ collect_rusage_stats (NULL);
}
========
getrusage (RUSAGE_SELF, &buf );
+ collect_rusage_stats (&buf);
add_randomness( &buf, sizeof buf, 1 );
memset( &buf, 0, sizeof buf );
}
*/

View file

@ -1,5 +1,5 @@
/* tiger.c - The TIGER hash function
* Copyright (C) 1998, 2001, 2002, 2003 Free Software Foundation, Inc.
* Copyright (C) 1998, 2001, 2002, 2003, 2010 Free Software Foundation, Inc.
*
* This file is part of Libgcrypt.
*
@ -18,25 +18,26 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
/* See http://www.cs.technion.ac.il/~biham/Reports/Tiger/ */
#include <config.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "g10lib.h"
#include "memory.h"
#include "cipher.h"
/* We really need a 64 bit type for this code. */
#ifdef HAVE_U64_TYPEDEF
/* we really need it here, but as this is only experiment we
* can live without Tiger */
typedef struct {
u64 a, b, c;
byte buf[64];
int count;
u32 nblocks;
typedef struct
{
u64 a, b, c;
byte buf[64];
int count;
u32 nblocks;
int variant; /* 0 = old code, 1 = fixed code, 2 - TIGER2. */
} TIGER_CONTEXT;
@ -588,7 +589,7 @@ static u64 sbox4[256] = {
};
static void
tiger_init( void *context )
do_init (void *context, int variant)
{
TIGER_CONTEXT *hd = context;
@ -597,6 +598,25 @@ tiger_init( void *context )
hd->c = 0xf096a5b4c3b2e187LL;
hd->nblocks = 0;
hd->count = 0;
hd->variant = variant;
}
static void
tiger_init (void *context)
{
do_init (context, 0);
}
static void
tiger1_init (void *context)
{
do_init (context, 1);
}
static void
tiger2_init (void *context)
{
do_init (context, 2);
}
static void
@ -763,6 +783,7 @@ tiger_final( void *context )
TIGER_CONTEXT *hd = context;
u32 t, msb, lsb;
byte *p;
byte pad = hd->variant == 2? 0x80 : 0x01;
tiger_write(hd, NULL, 0); /* flush */;
@ -782,13 +803,13 @@ tiger_final( void *context )
if( hd->count < 56 ) /* enough room */
{
hd->buf[hd->count++] = 0x01; /* pad */
hd->buf[hd->count++] = pad;
while( hd->count < 56 )
hd->buf[hd->count++] = 0; /* pad */
}
else /* need one extra block */
{
hd->buf[hd->count++] = 0x01; /* pad character */
hd->buf[hd->count++] = pad; /* pad character */
while( hd->count < 64 )
hd->buf[hd->count++] = 0;
tiger_write(hd, NULL, 0); /* flush */;
@ -815,10 +836,24 @@ tiger_final( void *context )
*p++ = hd->a >> 24; *p++ = hd->a >> 16; \
*p++ = hd->a >> 8; *p++ = hd->a; } while(0)
#endif
X(a);
X(b);
X(c);
#define Y(a) do { *p++ = hd->a ; *p++ = hd->a >> 8; \
*p++ = hd->a >> 16; *p++ = hd->a >> 24; \
*p++ = hd->a >> 32; *p++ = hd->a >> 40; \
*p++ = hd->a >> 48; *p++ = hd->a >> 56; } while(0)
if (hd->variant == 0)
{
X(a);
X(b);
X(c);
}
else
{
Y(a);
Y(b);
Y(c);
}
#undef X
#undef Y
}
static byte *
@ -829,22 +864,47 @@ tiger_read( void *context )
return hd->buf;
}
static byte asn[19] = /* Object ID is 1.3.6.1.4.1.11591.12.2 */
/* This is the old TIGER variant based on the unfixed reference
implementation. IT was used in GnupG up to 1.3.2. We don't provide
an OID anymore because that would not be correct. */
gcry_md_spec_t _gcry_digest_spec_tiger =
{
"TIGER192", NULL, 0, NULL, 24,
tiger_init, tiger_write, tiger_final, tiger_read,
sizeof (TIGER_CONTEXT)
};
/* This is the fixed TIGER implementation. */
static byte asn1[19] = /* Object ID is 1.3.6.1.4.1.11591.12.2 */
{ 0x30, 0x29, 0x30, 0x0d, 0x06, 0x09, 0x2b, 0x06,
0x01, 0x04, 0x01, 0xda, 0x47, 0x0c, 0x02,
0x05, 0x00, 0x04, 0x18 };
static gcry_md_oid_spec_t oid_spec_tiger[] =
static gcry_md_oid_spec_t oid_spec_tiger1[] =
{
/* GNU.digestAlgorithm TIGER */
{ "1.3.6.1.4.1.11591.12.2" },
{ NULL }
};
gcry_md_spec_t _gcry_digest_spec_tiger =
gcry_md_spec_t _gcry_digest_spec_tiger1 =
{
"TIGER192", asn, DIM (asn), oid_spec_tiger, 24,
tiger_init, tiger_write, tiger_final, tiger_read,
"TIGER", asn1, DIM (asn1), oid_spec_tiger1, 24,
tiger1_init, tiger_write, tiger_final, tiger_read,
sizeof (TIGER_CONTEXT)
};
/* This is TIGER2 which usues a changed padding algorithm. */
gcry_md_spec_t _gcry_digest_spec_tiger2 =
{
"TIGER2", NULL, 0, NULL, 24,
tiger2_init, tiger_write, tiger_final, tiger_read,
sizeof (TIGER_CONTEXT)
};

View file

@ -522,7 +522,7 @@ static byte calc_sb_tbl[512] = {
* preprocessed through q0 and q1 respectively; for longer keys they are the
* output of previous stages. j is the index of the first key byte to use.
* CALC_K computes a pair of subkeys for 128-bit Twofish, by calling CALC_K_2
* twice, doing the Psuedo-Hadamard Transform, and doing the necessary
* twice, doing the Pseudo-Hadamard Transform, and doing the necessary
* rotations. Its parameters are: a, the array to write the results into,
* j, the index of the first output entry, k and l, the preprocessed indices
* for index 2i, and m and n, the preprocessed indices for index 2i+1.

View file

@ -36,7 +36,6 @@
#include "types.h"
#include "g10lib.h"
#include "memory.h"
#include "cipher.h"
#include "bithelp.h"