Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/nettle/dsa-compat.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /* dsa-compat.h
0002 
0003    Old DSA publickey interface.
0004 
0005    Copyright (C) 2002, 2013, 2014 Niels Möller
0006 
0007    This file is part of GNU Nettle.
0008 
0009    GNU Nettle is free software: you can redistribute it and/or
0010    modify it under the terms of either:
0011 
0012      * the GNU Lesser General Public License as published by the Free
0013        Software Foundation; either version 3 of the License, or (at your
0014        option) any later version.
0015 
0016    or
0017 
0018      * the GNU General Public License as published by the Free
0019        Software Foundation; either version 2 of the License, or (at your
0020        option) any later version.
0021 
0022    or both in parallel, as here.
0023 
0024    GNU Nettle is distributed in the hope that it will be useful,
0025    but WITHOUT ANY WARRANTY; without even the implied warranty of
0026    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0027    General Public License for more details.
0028 
0029    You should have received copies of the GNU General Public License and
0030    the GNU Lesser General Public License along with this program.  If
0031    not, see http://www.gnu.org/licenses/.
0032 */
0033 
0034 #ifndef NETTLE_DSA_COMPAT_H_INCLUDED
0035 #define NETTLE_DSA_COMPAT_H_INCLUDED
0036 
0037 #include "dsa.h"
0038 
0039 #include "sha1.h"
0040 #include "sha2.h"
0041 
0042 /* Name mangling */
0043 #define dsa_public_key_init nettle_dsa_public_key_init
0044 #define dsa_public_key_clear nettle_dsa_public_key_clear
0045 #define dsa_private_key_init nettle_dsa_private_key_init
0046 #define dsa_private_key_clear nettle_dsa_private_key_clear
0047 #define dsa_sha1_sign nettle_dsa_sha1_sign
0048 #define dsa_sha1_verify nettle_dsa_sha1_verify
0049 #define dsa_sha256_sign nettle_dsa_sha256_sign
0050 #define dsa_sha256_verify nettle_dsa_sha256_verify
0051 #define dsa_sha1_sign_digest nettle_dsa_sha1_sign_digest
0052 #define dsa_sha1_verify_digest nettle_dsa_sha1_verify_digest
0053 #define dsa_sha256_sign_digest nettle_dsa_sha256_sign_digest
0054 #define dsa_sha256_verify_digest nettle_dsa_sha256_verify_digest
0055 #define dsa_compat_generate_keypair nettle_dsa_compat_generate_keypair
0056 
0057 /* Switch meaning of dsa_generate_keypair */
0058 #undef dsa_generate_keypair
0059 #define dsa_generate_keypair nettle_dsa_compat_generate_keypair
0060 
0061 #ifdef __cplusplus
0062 extern "C" {
0063 #endif
0064 
0065 struct dsa_public_key
0066 {
0067   /* Same as struct dsa_params, but can't use that struct here without
0068      breaking backwards compatibility. Layout must be identical, since
0069      this is cast to a struct dsa_param pointer for calling _dsa_sign
0070      and _dsa_verify */
0071   mpz_t p;
0072   mpz_t q;
0073   mpz_t g;
0074 
0075   /* Public value */
0076   mpz_t y;
0077 };
0078 
0079 struct dsa_private_key
0080 {
0081   /* Unlike an rsa public key, private key operations will need both
0082    * the private and the public information. */
0083   mpz_t x;
0084 };
0085 
0086 /* Signing a message works as follows:
0087  *
0088  * Store the private key in a dsa_private_key struct.
0089  *
0090  * Initialize a hashing context, by callling
0091  *   sha1_init
0092  *
0093  * Hash the message by calling
0094  *   sha1_update
0095  *
0096  * Create the signature by calling
0097  *   dsa_sha1_sign
0098  *
0099  * The signature is represented as a struct dsa_signature. This call also
0100  * resets the hashing context.
0101  *
0102  * When done with the key and signature, don't forget to call
0103  * dsa_signature_clear.
0104  */
0105 
0106 /* Calls mpz_init to initialize bignum storage. */
0107 void
0108 dsa_public_key_init(struct dsa_public_key *key);
0109 
0110 /* Calls mpz_clear to deallocate bignum storage. */
0111 void
0112 dsa_public_key_clear(struct dsa_public_key *key);
0113 
0114 
0115 /* Calls mpz_init to initialize bignum storage. */
0116 void
0117 dsa_private_key_init(struct dsa_private_key *key);
0118 
0119 /* Calls mpz_clear to deallocate bignum storage. */
0120 void
0121 dsa_private_key_clear(struct dsa_private_key *key);
0122 
0123 int
0124 dsa_sha1_sign(const struct dsa_public_key *pub,
0125           const struct dsa_private_key *key,
0126           void *random_ctx, nettle_random_func *random,
0127           struct sha1_ctx *hash,
0128           struct dsa_signature *signature);
0129 
0130 int
0131 dsa_sha256_sign(const struct dsa_public_key *pub,
0132         const struct dsa_private_key *key,
0133         void *random_ctx, nettle_random_func *random,
0134         struct sha256_ctx *hash,
0135         struct dsa_signature *signature);
0136 
0137 int
0138 dsa_sha1_verify(const struct dsa_public_key *key,
0139         struct sha1_ctx *hash,
0140         const struct dsa_signature *signature);
0141 
0142 int
0143 dsa_sha256_verify(const struct dsa_public_key *key,
0144           struct sha256_ctx *hash,
0145           const struct dsa_signature *signature);
0146 
0147 int
0148 dsa_sha1_sign_digest(const struct dsa_public_key *pub,
0149              const struct dsa_private_key *key,
0150              void *random_ctx, nettle_random_func *random,
0151              const uint8_t *digest,
0152              struct dsa_signature *signature);
0153 int
0154 dsa_sha256_sign_digest(const struct dsa_public_key *pub,
0155                const struct dsa_private_key *key,
0156                void *random_ctx, nettle_random_func *random,
0157                const uint8_t *digest,
0158                struct dsa_signature *signature);
0159 
0160 int
0161 dsa_sha1_verify_digest(const struct dsa_public_key *key,
0162                const uint8_t *digest,
0163                const struct dsa_signature *signature);
0164 
0165 int
0166 dsa_sha256_verify_digest(const struct dsa_public_key *key,
0167              const uint8_t *digest,
0168              const struct dsa_signature *signature);
0169 
0170 /* Key generation */
0171 int
0172 dsa_generate_keypair(struct dsa_public_key *pub,
0173              struct dsa_private_key *key,
0174 
0175              void *random_ctx, nettle_random_func *random,
0176              void *progress_ctx, nettle_progress_func *progress,
0177              unsigned p_bits, unsigned q_bits);
0178 
0179 #ifdef __cplusplus
0180 }
0181 #endif
0182 
0183 #endif /* NETTLE_DSA_COMPAT_H_INCLUDED */