Drop automake-installed files

Drop files that are provided by automake. They are better to be in sync
with automake used.

Signed-off-by: Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
Update .gitingore to ignore more files

* .gitignore: add more tests, temporary files, etc to the list of
ignored files.

Signed-off-by: Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
Implement GOST 28147-89 "gammirovanie" mode

* cipher/Makefile.am, cipher/cipher-internal.h,
 cipher/cipher-ofbgost.c cipher/cipher.c src/gcrypt.h.in: GOST 28147-89
 declares special mode named "gammirovanie". It looks mostly like OFB
 mode, except that encrypted cipherstream is processed a little bit
 more. Implement it as a generic encryption mode (like it is done for
 AESWRAP).
* doc/gcrypt.texi: document GCRY_CIPHER_MODE_OFBGOST.

Signed-off-by: Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>

start adding ofbgost checks

Signed-off-by: Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>

OFBGOST improvements

Signed-off-by: Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>

OFBGOST -> CNTGOST

Signed-off-by: Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>

cntgost

Signed-off-by: Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
Fixup tests ordering for new automake

Signed-off-by: Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
gost28147: add (disabled) s-box from 34.11 CryptoPro params

Signed-off-by: Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
Check that secret keys are valid while running basic pubkey tests

* tests/basic.c (do_check_one_pubkey): call gcry_pk_testkey on passed
  secret keys.

Signed-off-by: Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
Add a simple (raw) PKCS#1 padding mode

* src/cipher.h (PUBKEY_ENC_PKCS1_RAW): New.
* cipher/pubkey-util.c (_gcry_pk_util_parse_flaglist): Handle pkcs1-raw
  flag.
* cipher/pubkey-util.c (_gcry_pk_util_data_to_mpi):
  Handle s-exp like (data (flags pkcs1-raw) (value xxxxx))
* cipher/rsa-common.c (_gcry_rsa_pkcs1_encode_raw_for_sig):
  PKCS#1-encode data with embedded hash OID for signature verification.
* tests/basic.c (check_pubkey_sign): Add tests for s-exps with pkcs1-raw
  flag.

--
Allow user to specify (flags pkcs1-raw) to enable pkcs1 padding of raw
value (no hash algorithm is specified). It is up to the user to verify
that the passed value is properly formatted and includes DER-encoded
ASN OID of the used hash function.

Signed-off-by: Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
Add an utility to calculate hashes over a set of files

* tests/gchash.c: New.

--
An utility like rhash that has the ability to calculate different hashes
over a set of files it usefull. Add gchash utility to calculate hashes
supported by libgcrypt.

Signed-off-by: Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
Truncate hash values for ECDSA signature scheme

* cipher/dsa-common (_gcry_dsa_normalize_hash): New. Truncate opaque
  mpis as required for DSA and ECDSA signature schemas.
* cipher/dsa.c (verify): Return gpg_err_code_t value from verify() to
  behave like the rest of internal sign/verify functions.
* cipher/dsa.c (sign, verify, dsa_verify): Factor out hash truncation.
* cipher/ecc-ecdsa.c (_gcry_ecc_ecdsa_sign): Factor out hash truncation.
* cipher/ecc-ecdsa.c (_gcry_ecc_ecdsa_verify):
  as required by ECDSA scheme, truncate hash values to bitlength of
  used curve.
* tests/pubkey.c (check_ecc_sample_key): add a testcase for hash
  truncation.

Signed-off-by: Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
Correct formatting of gcry_mac_get_algo_keylen documentation

* doc/gcrypt.texi: add braces near gcry_mac_get_algo_keylen
  documentation.

Use braces around unsigned int in gcry_mac_get_algo_keylen
documentation, otherwise texinfo breaks that and uses 'int' as a
function definition.

Signed-off-by: Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
Add a function to retrieve algorithm used by MAC handler

* cipher/mac.c (_gcry_mac_get_algo): New function, returns used algo.
* src/visibility.c (gcry_mac_get_algo): New wrapper.
* src/visibility.h: Hanlde gcry_mac_get_algo.
* src/gcrypt-int.h (_gcry_mac_get_algo): New.
* src/gcrypt.h.in (gcry_mac_get_algo): New.
* src/libgcrypt.def (gcry_mac_get_algo): New.
* src/libgcrypt.vers (gcry_mac_get_algo): New.
* doc/gcrypt.texi: Document gcry_mac_get_algo.
* tests/basic.c (check_one_mac): Verify gcry_mac_get_algo.

Signed-off-by: Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
Add MD2-HMAC calculation support

* src/gcrypt.h.in (GCRY_MAC_HMAC_MD2): New.
* cipher/mac-hmac.c: Support GCRY_MAC_HMAC_MD2.

Signed-off-by: Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
Add GOST R 34.10-2001 curves per RFC4357

* cipher/ecc-curves.c (domain_parms): Add 3 curves defined in rfc4357.
* cipher/ecc-curves.c (curve_aliases): Add OID and Xch aliases for GOST
  curves.
* tests/curves.c (N_CURVES): Update value.

Signed-off-by: Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
Fix typo in search_oid

* cipher/md.c (search_oid): Invert condition on oid comparison.

--
Function stricmp() returns 0 in case strings match, so proper condition
that checks for matching OID strings should be if (!stricmp(...))

Signed-off-by: Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
gost 34.11-94 add OIDs

Signed-off-by: Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
Add GOST R 34.10-2012 curves proposed by TC26

* cipher/ecc-curves.c (domain_parmss): Add two GOST R 34.10-2012 curves
  proposed/pending to standardization by TC26 (Russian cryptography
  technical comitee).
* cipher/ecc-curves.c (curve_alias): Add OID aliases.
* tests/curves.c: Increase N_CURVES.

Signed-off-by: Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>