/*
This file is part of GNUnet.
- (C) 2001-2013 Christian Grothoff (and other contributing authors)
+ Copyright (C) 2001-2013 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
* @return updated crc sum (must be subjected to #GNUNET_CRYPTO_crc16_finish to get actual crc16)
*/
uint32_t
-GNUNET_CRYPTO_crc16_step (uint32_t sum, const void *buf, size_t len);
+GNUNET_CRYPTO_crc16_step (uint32_t sum,
+ const void *buf,
+ size_t len);
/**
* @return crc16 value
*/
uint16_t
-GNUNET_CRYPTO_crc16_n (const void *buf, size_t len);
+GNUNET_CRYPTO_crc16_n (const void *buf,
+ size_t len);
/**
* @return the resulting CRC32 checksum
*/
int32_t
-GNUNET_CRYPTO_crc32_n (const void *buf, size_t len);
+GNUNET_CRYPTO_crc32_n (const void *buf,
+ size_t len);
/**
* @param length buffer length
*/
void
-GNUNET_CRYPTO_random_block (enum GNUNET_CRYPTO_Quality mode, void *buffer, size_t length);
+GNUNET_CRYPTO_random_block (enum GNUNET_CRYPTO_Quality mode,
+ void *buffer,
+ size_t length);
/**
* @ingroup crypto
* @return a random value in the interval [0,@a i) (exclusive).
*/
uint32_t
-GNUNET_CRYPTO_random_u32 (enum GNUNET_CRYPTO_Quality mode, uint32_t i);
+GNUNET_CRYPTO_random_u32 (enum GNUNET_CRYPTO_Quality mode,
+ uint32_t i);
/**
* @return random 64-bit number
*/
uint64_t
-GNUNET_CRYPTO_random_u64 (enum GNUNET_CRYPTO_Quality mode, uint64_t max);
+GNUNET_CRYPTO_random_u64 (enum GNUNET_CRYPTO_Quality mode,
+ uint64_t max);
/**
* @return the permutation array (allocated from heap)
*/
unsigned int *
-GNUNET_CRYPTO_random_permute (enum GNUNET_CRYPTO_Quality mode, unsigned int n);
+GNUNET_CRYPTO_random_permute (enum GNUNET_CRYPTO_Quality mode,
+ unsigned int n);
/**
* @return the size of the encrypted block, -1 for errors
*/
ssize_t
-GNUNET_CRYPTO_symmetric_encrypt (const void *block, size_t size,
+GNUNET_CRYPTO_symmetric_encrypt (const void *block,
+ size_t size,
const struct GNUNET_CRYPTO_SymmetricSessionKey *sessionkey,
const struct GNUNET_CRYPTO_SymmetricInitializationVector *iv,
void *result);
* @return -1 on failure, size of decrypted block on success
*/
ssize_t
-GNUNET_CRYPTO_symmetric_decrypt (const void *block, size_t size,
+GNUNET_CRYPTO_symmetric_decrypt (const void *block,
+ size_t size,
const struct GNUNET_CRYPTO_SymmetricSessionKey *sessionkey,
const struct GNUNET_CRYPTO_SymmetricInitializationVector *iv,
void *result);
* safely cast to char*, a '\\0' termination is set).
*/
void
-GNUNET_CRYPTO_hash_to_enc (const struct GNUNET_HashCode * block,
+GNUNET_CRYPTO_hash_to_enc (const struct GNUNET_HashCode *block,
struct GNUNET_CRYPTO_HashAsciiEncoded *result);
* @return #GNUNET_OK on success, #GNUNET_SYSERR if result has the wrong encoding
*/
int
-GNUNET_CRYPTO_hash_from_string2 (const char *enc, size_t enclen,
+GNUNET_CRYPTO_hash_from_string2 (const char *enc,
+ size_t enclen,
struct GNUNET_HashCode *result);
*/
void
GNUNET_CRYPTO_hash_context_read (struct GNUNET_HashContext *hc,
- const void *buf,
- size_t size);
+ const void *buf,
+ size_t size);
/**
*/
void
GNUNET_CRYPTO_hash_context_finish (struct GNUNET_HashContext *hc,
- struct GNUNET_HashCode *r_hash);
+ struct GNUNET_HashCode *r_hash);
/**
*/
void
GNUNET_CRYPTO_hmac (const struct GNUNET_CRYPTO_AuthKey *key,
- const void *plaintext, size_t plaintext_len,
- struct GNUNET_HashCode * hmac);
+ const void *plaintext,
+ size_t plaintext_len,
+ struct GNUNET_HashCode *hmac);
/**
* @param cls closure
* @param res resulting hash, NULL on error
*/
-typedef void (*GNUNET_CRYPTO_HashCompletedCallback) (void *cls,
- const struct GNUNET_HashCode *res);
+typedef void
+(*GNUNET_CRYPTO_HashCompletedCallback) (void *cls,
+ const struct GNUNET_HashCode *res);
/**
*/
struct GNUNET_CRYPTO_FileHashContext *
GNUNET_CRYPTO_hash_file (enum GNUNET_SCHEDULER_Priority priority,
- const char *filename, size_t blocksize,
+ const char *filename,
+ size_t blocksize,
GNUNET_CRYPTO_HashCompletedCallback callback,
void *callback_cls);
void
GNUNET_CRYPTO_hmac_derive_key (struct GNUNET_CRYPTO_AuthKey *key,
const struct GNUNET_CRYPTO_SymmetricSessionKey *rkey,
- const void *salt, size_t salt_len, ...);
+ const void *salt, size_t salt_len,
+ ...);
/**
* @return #GNUNET_YES on success
*/
int
-GNUNET_CRYPTO_hkdf (void *result, size_t out_len, int xtr_algo, int prf_algo,
- const void *xts, size_t xts_len, const void *skm,
- size_t skm_len, ...);
+GNUNET_CRYPTO_hkdf (void *result,
+ size_t out_len,
+ int xtr_algo,
+ int prf_algo,
+ const void *xts,
+ size_t xts_len,
+ const void *skm,
+ size_t skm_len,
+ ...);
/**
* @return #GNUNET_YES on success
*/
int
-GNUNET_CRYPTO_hkdf_v (void *result, size_t out_len, int xtr_algo, int prf_algo,
- const void *xts, size_t xts_len, const void *skm,
- size_t skm_len, va_list argp);
+GNUNET_CRYPTO_hkdf_v (void *result,
+ size_t out_len,
+ int xtr_algo,
+ int prf_algo,
+ const void *xts,
+ size_t xts_len,
+ const void *skm,
+ size_t skm_len,
+ va_list argp);
/**
* @return #GNUNET_YES on success
*/
int
-GNUNET_CRYPTO_kdf_v (void *result, size_t out_len, const void *xts,
- size_t xts_len, const void *skm, size_t skm_len,
+GNUNET_CRYPTO_kdf_v (void *result,
+ size_t out_len,
+ const void *xts,
+ size_t xts_len,
+ const void *skm,
+ size_t skm_len,
va_list argp);
* @return #GNUNET_YES on success
*/
int
-GNUNET_CRYPTO_kdf (void *result, size_t out_len, const void *xts,
- size_t xts_len, const void *skm, size_t skm_len, ...);
+GNUNET_CRYPTO_kdf (void *result,
+ size_t out_len,
+ const void *xts,
+ size_t xts_len,
+ const void *skm,
+ size_t skm_len,
+ ...);
/**
struct GNUNET_CRYPTO_EddsaPublicKey *pub);
+
+/**
+ * @ingroup crypto
+ * Convert ECDSA public key to ECDHE public key.
+ * Please be very careful when using this function, as mixing
+ * cryptographic primitives is not always healthy.
+ *
+ * @param ecdsa ecdsa public key
+ * @param ecdhe[OUT] ecdhe public key
+ */
+void
+GNUNET_CRYPTO_ecdsa_public_to_ecdhe (const struct GNUNET_CRYPTO_EcdsaPublicKey *ecdsa,
+ struct GNUNET_CRYPTO_EcdhePublicKey *ecdhe);
+
+
+/**
+ * @ingroup crypto
+ * Convert ECDSA private key to ECDHE private key.
+ * Please be very careful when using this function, as mixing
+ * cryptographic primitives is not always healthy.
+ *
+ * @param ecdsa ecdsa private key
+ * @param ecdhe[OUT] ecdhe private key
+ */
+void
+GNUNET_CRYPTO_ecdsa_private_to_ecdhe (const struct GNUNET_CRYPTO_EcdsaPrivateKey *ecdsa,
+ struct GNUNET_CRYPTO_EcdhePrivateKey *ecdhe);
+
+
/**
* @ingroup crypto
* Extract the public key for the given private key.
struct GNUNET_CRYPTO_EcdsaPublicKey *pub);
+/**
+ * Convert a string representing a private key to a private key.
+ *
+ * @param enc encoded public key
+ * @param enclen number of bytes in @a enc (without 0-terminator)
+ * @param priv where to store the private key
+ * @return #GNUNET_OK on success
+ */
+int
+GNUNET_CRYPTO_eddsa_private_key_from_string (const char *enc,
+ size_t enclen,
+ struct GNUNET_CRYPTO_EddsaPrivateKey *pub);
+
+
/**
* Convert a string representing a public key to a public key.
*
struct GNUNET_CRYPTO_EddsaPrivateKey *
GNUNET_CRYPTO_eddsa_key_create_from_file (const char *filename);
+
+/**
+ * Forward declaration to simplify #include-structure.
+ */
struct GNUNET_CONFIGURATION_Handle;
GNUNET_CRYPTO_rsa_private_key_get_public (const struct GNUNET_CRYPTO_rsa_PrivateKey *priv);
+/**
+ * Compute hash over the public key.
+ *
+ * @param key public key to hash
+ * @param hc where to store the hash code
+ */
+void
+GNUNET_CRYPTO_rsa_public_key_hash (const struct GNUNET_CRYPTO_rsa_PublicKey *key,
+ struct GNUNET_HashCode *hc);
+
+
/**
* Free memory occupied by the public key.
*
*/
size_t
GNUNET_CRYPTO_rsa_blinding_key_encode (const struct GNUNET_CRYPTO_rsa_BlindingKey *bkey,
- char **buffer);
+ char **buffer);
/**
*/
struct GNUNET_CRYPTO_rsa_BlindingKey *
GNUNET_CRYPTO_rsa_blinding_key_decode (const char *buf,
- size_t len);
+ size_t len);
/**
*/
size_t
GNUNET_CRYPTO_rsa_blind (const struct GNUNET_HashCode *hash,
- struct GNUNET_CRYPTO_rsa_BlindingKey *bkey,
- struct GNUNET_CRYPTO_rsa_PublicKey *pkey,
- char **buffer);
+ struct GNUNET_CRYPTO_rsa_BlindingKey *bkey,
+ struct GNUNET_CRYPTO_rsa_PublicKey *pkey,
+ char **buffer);
/**
*/
struct GNUNET_CRYPTO_rsa_Signature *
GNUNET_CRYPTO_rsa_sign (const struct GNUNET_CRYPTO_rsa_PrivateKey *key,
- const void *msg,
- size_t msg_len);
+ const void *msg,
+ size_t msg_len);
/**
/**
- * Encode the given signature in a format suitable for
- * storing it into a file.
+ * Encode the given signature in a format suitable for storing it into a file.
*
* @param sig the signature
* @param[out] buffer set to a buffer with the encoded key
/**
- * Decode the signature from the data-format back
- * to the "normal", internal format.
+ * Decode the signature from the data-format back to the "normal", internal
+ * format.
*
* @param buf the buffer where the public key data is stored
* @param len the length of the data in @a buf
/**
- * Unblind a signature made on blinding signature purpose. The signature
- * purpose should have been generated with #GNUNET_CRYPTO_rsa_sign() using
- * a message that was generated with #GNUNET_CRYPTO_rsa_blind().
+ * Unblind a blind-signed signature. The signature should have been generated
+ * with #GNUNET_CRYPTO_rsa_sign() using a hash that was blinded with
+ * #GNUNET_CRYPTO_rsa_blind().
*
* @param sig the signature made on the blinded signature purpose
* @param bkey the blinding key used to blind the signature purpose
/**
- * Verify signature with the given hash.
+ * Verify whether the given hash corresponds to the given signature and the
+ * signature is valid with respect to the given public key.
*
* @param hash the message to verify to match the @a sig
* @param sig signature that is being validated