/*
This file is part of GNUnet.
(C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2012 Christian Grothoff (and other contributing authors)
GNUnet is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
by the Free Software Foundation; either version 2, or (at your
option) any later version.
GNUnet 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
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNUnet; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
/**
* @file include/gnunet_crypto_lib.h
* @brief cryptographic primitives for GNUnet
*
* @author Christian Grothoff
* @author Krista Bennett
* @author Gerd Knorr <kraxel@bytesex.org>
* @author Ioana Patrascu
* @author Tzvetan Horozov
*/
#ifndef GNUNET_CRYPTO_LIB_H
#define GNUNET_CRYPTO_LIB_H
#ifdef __cplusplus
extern "C"
{
#if 0 /* keep Emacsens' auto-indent happy */
}
#endif
#endif
#include "gnunet_common.h"
#include "gnunet_scheduler_lib.h"
/**
* Desired quality level for cryptographic operations.
*/
enum GNUNET_CRYPTO_Quality
{
/**
* No good quality of the operation is needed (i.e.,
* random numbers can be pseudo-random).
*/
GNUNET_CRYPTO_QUALITY_WEAK,
/**
* High-quality operations are desired.
*/
GNUNET_CRYPTO_QUALITY_STRONG,
/**
* Randomness for IVs etc. is required.
*/
GNUNET_CRYPTO_QUALITY_NONCE
};
/**
* @brief length of the sessionkey in bytes (256 BIT sessionkey)
*/
#define GNUNET_CRYPTO_AES_KEY_LENGTH (256/8)
/**
* @brief Length of RSA encrypted data (2048 bit)
*
* We currently do not handle encryption of data
* that can not be done in a single call to the
* RSA methods (read: large chunks of data).
* We should never need that, as we can use
* the GNUNET_CRYPTO_hash for larger pieces of data for signing,
* and for encryption, we only need to encode sessionkeys!
*/
#define GNUNET_CRYPTO_RSA_DATA_ENCODING_LENGTH 256
/**
* Length of an RSA KEY (n,e,len), 2048 bit (=256 octests) key n, 2 byte e
*/
#define GNUNET_CRYPTO_RSA_KEY_LENGTH 258
/**
* Length of a hash value
*/
#define GNUNET_CRYPTO_HASH_LENGTH (512/8)
/**
* Maximum length of an ECC signature.
* Note: round up to multiple of 8 minus 2 for alignment.
*/
#define GNUNET_CRYPTO_ECC_SIGNATURE_DATA_ENCODING_LENGTH 190
/**
* Maximum length of the public key (q-point, Q = dP) when encoded.
*/
#define GNUNET_CRYPTO_ECC_MAX_PUBLIC_KEY_LENGTH 140
/**
* The private information of an RSA key pair.
*/
struct GNUNET_CRYPTO_RsaPrivateKey;
/**
* The private information of an ECC private key.
*/
struct GNUNET_CRYPTO_EccPrivateKey;
GNUNET_NETWORK_STRUCT_BEGIN
/**
* GNUnet mandates a certain format for the encoding
* of private RSA key information that is provided
* by the RSA implementations. This format is used
* to serialize a private RSA key (typically when
* writing it to disk).
*/
struct GNUNET_CRYPTO_RsaPrivateKeyBinaryEncoded
{
/**
* Total size of the structure, in bytes, in big-endian!
*/
uint16_t len GNUNET_PACKED;
uint16_t sizen GNUNET_PACKED; /* in big-endian! */
uint16_t sizee GNUNET_PACKED; /* in big-endian! */
uint16_t sized GNUNET_PACKED; /* in big-endian! */
uint16_t sizep GNUNET_PACKED; /* in big-endian! */
uint16_t sizeq GNUNET_PACKED; /* in big-endian! */
uint16_t sizedmp1 GNUNET_PACKED; /* in big-endian! */
uint16_t sizedmq1 GNUNET_PACKED; /* in big-endian! */
/* followed by the actual values */
};
GNUNET_NETWORK_STRUCT_END
/**
* @brief 0-terminated ASCII encoding of a struct GNUNET_HashCode.
*/
struct GNUNET_CRYPTO_HashAsciiEncoded
{
unsigned <