base64.h | base64.h | |||
---|---|---|---|---|
/* | /* | |||
* base64.h | * Copyright (c) 2000, 2002 Virtual Unlimited B.V. | |||
* | ||||
* Base64 encoding/decoding, header | ||||
* | ||||
* Copyright (c) 2000 Virtual Unlimited B.V. | ||||
* | ||||
* Author: Bob Deblier <bob@virtualunlimited.com> | ||||
* | * | |||
* This library is free software; you can redistribute it and/or | * This library is free software; you can redistribute it and/or | |||
* modify it under the terms of the GNU Lesser General Public | * modify it under the terms of the GNU Lesser General Public | |||
* License as published by the Free Software Foundation; either | * License as published by the Free Software Foundation; either | |||
* version 2.1 of the License, or (at your option) any later version. | * version 2.1 of the License, or (at your option) any later version. | |||
* | * | |||
* This library is distributed in the hope that it will be useful, | * This library is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
* Lesser General Public License for more details. | * Lesser General Public License for more details. | |||
* | * | |||
* You should have received a copy of the GNU Lesser General Public | * You should have received a copy of the GNU Lesser General Public | |||
* License along with this library; if not, write to the Free Software | * License along with this library; if not, write to the Free Software | |||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 US A | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 US A | |||
* | * | |||
*/ | */ | |||
/*!\file base64.h | ||||
* \brief Base64 encoding and decoding, headers. | ||||
* \author Bob Deblier <bob.deblier@pandora.be> | ||||
*/ | ||||
#ifndef _BASE64_H | #ifndef _BASE64_H | |||
#define _BASE64_H | #define _BASE64_H | |||
#include "beecrypt.h" | #include "beecrypt.h" | |||
/*!\ | ||||
* Decode white space character set (default). | ||||
*/ | ||||
extern const char* b64decode_whitespace; | ||||
#define B64DECODE_WHITESPACE " \f\n\r\t\v" | ||||
/*!\ | ||||
* Encode 72 characters per line (default). | ||||
*/ | ||||
extern int b64encode_chars_per_line; | ||||
#define B64ENCODE_CHARS_PER_LINE 72 | ||||
/*!\ | ||||
* Encode end-of-line string (default). | ||||
*/ | ||||
extern const char* b64encode_eolstr; | ||||
#define B64ENCODE_EOLSTR "\n" | ||||
#ifdef __cplusplus | #ifdef __cplusplus | |||
extern "C" { | extern "C" { | |||
#endif | #endif | |||
BEEDLLAPI | /*! | |||
* Encode chunks of 3 bytes of binary input into 4 bytes of base64 output. | ||||
* \param data binary data | ||||
* \param ns no. bytes of data (0 uses strlen(data)) | ||||
* \return (malloc'd) base64 string | ||||
*/ | ||||
BEECRYPTAPI | ||||
char* b64encode(const void* data, size_t ns); | ||||
/*! | ||||
* Encode crc of binary input data into 5 bytes of base64 output. | ||||
* \param data binary data | ||||
* \param ns no. bytes of binary data | ||||
* \return (malloc'd) base64 string | ||||
*/ | ||||
BEECRYPTAPI | ||||
char* b64crc(const unsigned char* data, size_t ns); | ||||
/*! | ||||
* Decode chunks of 4 bytes of base64 input into 3 bytes of binary output. | ||||
* \param s base64 string | ||||
* \retval datap address of (malloc'd) binary data | ||||
* \retval lenp address of no. bytes of binary data | ||||
* \return 0 on success, 1: s == NULL, 2: bad length, 3: bad char | ||||
*/ | ||||
BEECRYPTAPI | ||||
int b64decode(const char* s, void** datap, size_t* lenp); | ||||
/*! | ||||
*/ | ||||
BEECRYPTAPI | ||||
char* b64enc(const memchunk*); | char* b64enc(const memchunk*); | |||
BEEDLLAPI | ||||
/*! | ||||
*/ | ||||
BEECRYPTAPI | ||||
memchunk* b64dec(const char*); | memchunk* b64dec(const char*); | |||
#ifdef __cplusplus | #ifdef __cplusplus | |||
} | } | |||
#endif | #endif | |||
#endif | #endif | |||
End of changes. 5 change blocks. | ||||
9 lines changed or deleted | 59 lines changed or added | |||
beecrypt.h | beecrypt.h | |||
---|---|---|---|---|
/* | /* | |||
* beecrypt.h | * Copyright (c) 1999, 2000, 2001, 2002 Virtual Unlimited B.V. | |||
* | ||||
* BeeCrypt library hooks & stubs, header | ||||
* | ||||
* Copyright (c) 1999, 2000, 2001 Virtual Unlimited B.V. | ||||
* | ||||
* Author: Bob Deblier <bob@virtualunlimited.com> | ||||
* | * | |||
* This library is free software; you can redistribute it and/or | * This library is free software; you can redistribute it and/or | |||
* modify it under the terms of the GNU Lesser General Public | * modify it under the terms of the GNU Lesser General Public | |||
* License as published by the Free Software Foundation; either | * License as published by the Free Software Foundation; either | |||
* version 2.1 of the License, or (at your option) any later version. | * version 2.1 of the License, or (at your option) any later version. | |||
* | * | |||
* This library is distributed in the hope that it will be useful, | * This library is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
* Lesser General Public License for more details. | * Lesser General Public License for more details. | |||
* | * | |||
* You should have received a copy of the GNU Lesser General Public | * You should have received a copy of the GNU Lesser General Public | |||
* License along with this library; if not, write to the Free Software | * License along with this library; if not, write to the Free Software | |||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 US A | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 US A | |||
* | * | |||
*/ | */ | |||
/*!\file beecrypt.h | ||||
* \brief BeeCrypt API, headers. | ||||
* | ||||
* These API functions provide an abstract way for using most of | ||||
* the various algorithms implemented by the library. | ||||
* | ||||
* \author Bob Deblier <bob.deblier@pandora.be> | ||||
* \ingroup ES_m PRNG_m HASH_m HMAC_m BC_m | ||||
*/ | ||||
#ifndef _BEECRYPT_H | #ifndef _BEECRYPT_H | |||
#define _BEECRYPT_H | #define _BEECRYPT_H | |||
#ifdef HAVE_CONFIG_H | #include "beecrypt.api.h" | |||
# include "config.h" | ||||
#endif | ||||
#include "memchunk.h" | #include "memchunk.h" | |||
#include "mp32number.h" | #include "mpnumber.h" | |||
/* | /* | |||
* Entropy Sources | * Entropy Sources | |||
*/ | */ | |||
typedef int (*entropyNext)(uint32*, int); | /*!\typedef entropyNext | |||
* \brief Prototype definition for an entropy-generating function. | ||||
/* | * \ingroup ES_m | |||
* The struct 'entropySource' holds information and pointers to code specif | ||||
ic | ||||
* to each entropy source. Each specific entropy source MUST be written to | ||||
be | ||||
* multithread-safe. | ||||
* | ||||
* The struct contains the following function(s): | ||||
* | ||||
* int (*next)(uint32* data, int size); | ||||
* | ||||
* This function will fill an array of 32-bit unsigned integers of given si | ||||
ze | ||||
* with entropy. | ||||
* Return value is 0 on success, or -1 on failure. | ||||
*/ | */ | |||
typedef int (*entropyNext)(byte*, size_t); | ||||
/*!\brief This struct holds information and pointers to code specific to ea | ||||
ch | ||||
* source of entropy. | ||||
* \ingroup ES_m | ||||
*/ | ||||
typedef struct | typedef struct | |||
{ | { | |||
/*!\var name | ||||
* \brief The entropy source's name. | ||||
*/ | ||||
const char* name; | const char* name; | |||
/*!\var next | ||||
* \brief Points to the function which produces the entropy. | ||||
*/ | ||||
const entropyNext next; | const entropyNext next; | |||
} entropySource; | } entropySource; | |||
/* | ||||
* You can use the following functions to find entropy sources implemented | ||||
by | ||||
* the library: | ||||
* | ||||
* entropySourceCount returns the number of sources available. | ||||
* | ||||
* entropySourceGet returns the entropy source with a given index (starting | ||||
* at zero, up to entropySourceCount() - 1), or NULL if the index was out o | ||||
f | ||||
* bounds. | ||||
* | ||||
* entropySourceFind returns the entropy source with the given name, or NUL | ||||
L | ||||
* if no entropy source exists with that name. | ||||
*/ | ||||
#ifdef __cplusplus | #ifdef __cplusplus | |||
extern "C" { | extern "C" { | |||
#endif | #endif | |||
BEEDLLAPI | /*!\fn int entropySourceCount() | |||
int entropySourceCount(); | * \brief This function returns the number of entropy sources implemented b | |||
BEEDLLAPI | y | |||
const entropySource* entropySourceGet(int); | * the library. | |||
BEEDLLAPI | * \return The number of implemented entropy sources. | |||
const entropySource* entropySourceFind(const char*); | */ | |||
BEEDLLAPI | BEECRYPTAPI | |||
const entropySource* entropySourceDefault(); | int entropySourceCount(void); | |||
/* | /*!\fn const entropySource* entropySourceGet(int n) | |||
* The following function can try multiple entropy sources for gathering | * \brief This function returns the \a n -th entropy source implemented by | |||
* the requested amount. It will only try multiple sources if variable | * the library. | |||
* BEECRYPT_ENTROPY is not set. | * \param n Index of the requested entropy source; legal values are 0 | |||
* through entropySourceCount() - 1. | ||||
* \return A pointer to an entropy source or null, if the index was out of | ||||
* range. | ||||
*/ | */ | |||
BEEDLLAPI | BEECRYPTAPI | |||
int entropyGatherNext(uint32*, i | const entropySource* entropySourceGet(int n); | |||
nt); | ||||
/*!\fn const entropySource* entropySourceFind(const char* name) | ||||
* \brief This function returns the entropy source specified by the given n | ||||
ame. | ||||
* \param name Name of the requested entropy source. | ||||
* \return A pointer to an entropy source or null, if the name wasn't found | ||||
. | ||||
*/ | ||||
BEECRYPTAPI | ||||
const entropySource* entropySourceFind(const char* name); | ||||
/*!\fn const entropySource* entropySourceDefault() | ||||
* \brief This functions returns the default entropy source; the default va | ||||
lue | ||||
* can be specified by setting environment variable BEECRYPT_ENTROPY. | ||||
* \return A pointer to an entropy source or null, in case an error occured | ||||
. | ||||
*/ | ||||
BEECRYPTAPI | ||||
const entropySource* entropySourceDefault(void); | ||||
/*!\fn int entropyGatherNext(byte* data, size_t size) | ||||
* \brief This function gathers \a size bytes of entropy into \a data. | ||||
* | ||||
* Unless environment variable BEECRYPT_ENTROPY is set, this function will | ||||
* try each successive entropy source to gather up the requested amount. | ||||
* | ||||
* \param data Points to where the entropy should be stored. | ||||
* \param size Indicates how many bytes of entropy should be gathered. | ||||
* \retval 0 On success. | ||||
* \retval -1 On failure. | ||||
*/ | ||||
BEECRYPTAPI | ||||
int entropyGatherNext(byte*, siz | ||||
e_t); | ||||
#ifdef __cplusplus | #ifdef __cplusplus | |||
} | } | |||
#endif | #endif | |||
/* | /* | |||
* Pseudo-random Number Generators | * Pseudo-random Number Generators | |||
*/ | */ | |||
typedef void randomGeneratorParam; | typedef void randomGeneratorParam; | |||
typedef int (*randomGeneratorSetup )(randomGeneratorParam*); | typedef int (*randomGeneratorSetup )(randomGeneratorParam*); | |||
typedef int (*randomGeneratorSeed )(randomGeneratorParam*, const uint32*, | typedef int (*randomGeneratorSeed )(randomGeneratorParam*, const byte*, s | |||
int); | ize_t); | |||
typedef int (*randomGeneratorNext )(randomGeneratorParam*, uint32*, int); | typedef int (*randomGeneratorNext )(randomGeneratorParam*, byte*, size_t) | |||
; | ||||
typedef int (*randomGeneratorCleanup)(randomGeneratorParam*); | typedef int (*randomGeneratorCleanup)(randomGeneratorParam*); | |||
/* | /* | |||
* The struct 'randomGenerator' holds information and pointers to code spec ific | * The struct 'randomGenerator' holds information and pointers to code spec ific | |||
* to each random generator. Each specific random generator MUST be written to | * to each random generator. Each specific random generator MUST be written to | |||
* be multithread safe. | * be multithread safe. | |||
* | * | |||
* WARNING: each randomGenerator, when used in cryptographic applications, MUST | * WARNING: each randomGenerator, when used in cryptographic applications, MUST | |||
* be guaranteed to be of suitable quality and strength (i.e. don't use the | * be guaranteed to be of suitable quality and strength (i.e. don't use the | |||
* random() function found in most UN*X-es). | * random() function found in most UN*X-es). | |||
* | * | |||
* Multiple instances of each randomGenerator can be used (even concurrentl y), | * Multiple instances of each randomGenerator can be used (even concurrentl y), | |||
* provided they each use their own randomGeneratorParam parameters, a chun k | * provided they each use their own randomGeneratorParam parameters, a chun k | |||
* of memory which must be at least as large as indicated by the paramsize | * of memory which must be at least as large as indicated by the paramsize | |||
* field. | * field. | |||
* | * | |||
* The struct contains the following function(s): | ||||
* | ||||
* int (*setup)(randomGeneratorParam* param); | ||||
* | ||||
* This function will initialize the parameters for use, and seed the gener | ||||
ator | ||||
* with entropy from the default entropy source. | ||||
* Return value is 0 on success, or -1 on failure. | ||||
* | ||||
* int (*seed)(randomGeneratorParam* param, const uint32* data, int size); | ||||
* | ||||
* This function reseeds the random generator with user-provided entropy. | ||||
* Return value is 0 on success, or -1 on failure. | ||||
* | ||||
* int (*next)(randomGeneratorParam* param, uint32* data, int size); | ||||
* | ||||
* This function will fill an array of 32-bit unsigned integers of given si | ||||
ze | ||||
* with pseudo-random data. | ||||
* Return value is 0 on success, or -1 on failure. | ||||
* | ||||
* int (*cleanup)(randomGeneratorParam* param); | ||||
* | ||||
* This function will cleanup after the use of a generator | ||||
* Return value is 0 on success, or -1 on failure. | ||||
*/ | */ | |||
/*!\brief This struct holds information and pointers to code specific to ea | ||||
ch | ||||
* pseudo-random number generator. | ||||
* \ingroup PRNG_m | ||||
*/ | ||||
typedef struct | typedef struct | |||
{ | { | |||
/*!\var name | ||||
* \brief The random generator's name. | ||||
*/ | ||||
const char* name; | const char* name; | |||
const unsigned int paramsize; | /*!\var paramsize | |||
* \brief The size of the random generator's parameters. | ||||
* \note The implementor should set this by using sizeof(<struct hol | ||||
ding | ||||
* random generator's parameters>). | ||||
*/ | ||||
const size_t paramsize; | ||||
/*!\var setup | ||||
* \brief Points to the setup function. | ||||
*/ | ||||
const randomGeneratorSetup setup; | const randomGeneratorSetup setup; | |||
/*!\var seed | ||||
* \brief Points to the seeding function. | ||||
*/ | ||||
const randomGeneratorSeed seed; | const randomGeneratorSeed seed; | |||
/*!\var seed | ||||
* \brief Points to the function which generates the random data. | ||||
*/ | ||||
const randomGeneratorNext next; | const randomGeneratorNext next; | |||
/*!\var seed | ||||
* \brief Points to the cleanup function. | ||||
*/ | ||||
const randomGeneratorCleanup cleanup; | const randomGeneratorCleanup cleanup; | |||
} randomGenerator; | } randomGenerator; | |||
/* | /* | |||
* You can use the following functions to find random generators implemente d by | * You can use the following functions to find random generators implemente d by | |||
* the library: | * the library: | |||
* | * | |||
* randomGeneratorCount returns the number of generators available. | * randomGeneratorCount returns the number of generators available. | |||
* | * | |||
* randomGeneratorGet returns the random generator with a given index (star ting | * randomGeneratorGet returns the random generator with a given index (star ting | |||
skipping to change at line 179 | skipping to change at line 200 | |||
* bounds. | * bounds. | |||
* | * | |||
* randomGeneratorFind returns the random generator with the given name, or | * randomGeneratorFind returns the random generator with the given name, or | |||
* NULL if no random generator exists with that name. | * NULL if no random generator exists with that name. | |||
*/ | */ | |||
#ifdef __cplusplus | #ifdef __cplusplus | |||
extern "C" { | extern "C" { | |||
#endif | #endif | |||
BEEDLLAPI | BEECRYPTAPI | |||
int randomGeneratorCount(); | int randomGeneratorCount(void); | |||
BEEDLLAPI | BEECRYPTAPI | |||
const randomGenerator* randomGeneratorGet(int); | const randomGenerator* randomGeneratorGet(int); | |||
BEEDLLAPI | BEECRYPTAPI | |||
const randomGenerator* randomGeneratorFind(const char*); | const randomGenerator* randomGeneratorFind(const char*); | |||
BEEDLLAPI | BEECRYPTAPI | |||
const randomGenerator* randomGeneratorDefault(); | const randomGenerator* randomGeneratorDefault(void); | |||
#ifdef __cplusplus | #ifdef __cplusplus | |||
} | } | |||
#endif | #endif | |||
/* | /* | |||
* The struct 'randomGeneratorContext' is used to contain both the function al | * The struct 'randomGeneratorContext' is used to contain both the function al | |||
* part (the randomGenerator), and its parameters. | * part (the randomGenerator), and its parameters. | |||
*/ | */ | |||
skipping to change at line 213 | skipping to change at line 234 | |||
/* | /* | |||
* The following functions can be used to initialize and free a | * The following functions can be used to initialize and free a | |||
* randomGeneratorContext. Initializing will allocate a buffer of the size | * randomGeneratorContext. Initializing will allocate a buffer of the size | |||
* required by the randomGenerator, freeing will deallocate that buffer. | * required by the randomGenerator, freeing will deallocate that buffer. | |||
*/ | */ | |||
#ifdef __cplusplus | #ifdef __cplusplus | |||
extern "C" { | extern "C" { | |||
#endif | #endif | |||
BEEDLLAPI | BEECRYPTAPI | |||
int randomGeneratorContextInit(randomGeneratorContext*, const randomGenerat or*); | int randomGeneratorContextInit(randomGeneratorContext*, const randomGenerat or*); | |||
BEEDLLAPI | BEECRYPTAPI | |||
int randomGeneratorContextFree(randomGeneratorContext*); | int randomGeneratorContextFree(randomGeneratorContext*); | |||
BEECRYPTAPI | ||||
int randomGeneratorContextNext(randomGeneratorContext*, byte*, size_t); | ||||
#ifdef __cplusplus | #ifdef __cplusplus | |||
} | } | |||
#endif | #endif | |||
/* | /* | |||
* Hash Functions | * Hash Functions | |||
*/ | */ | |||
/*!typedef void hashFunctionParam | ||||
* \ingroup HASH_m | ||||
*/ | ||||
typedef void hashFunctionParam; | typedef void hashFunctionParam; | |||
typedef int (*hashFunctionReset )(hashFunctionParam*); | typedef int (*hashFunctionReset )(hashFunctionParam*); | |||
typedef int (*hashFunctionUpdate)(hashFunctionParam*, const byte*, int); | typedef int (*hashFunctionUpdate)(hashFunctionParam*, const byte*, size_t); | |||
typedef int (*hashFunctionDigest)(hashFunctionParam*, uint32*); | typedef int (*hashFunctionDigest)(hashFunctionParam*, byte*); | |||
/* | /* | |||
* The struct 'hashFunction' holds information and pointers to code specifi c | * The struct 'hashFunction' holds information and pointers to code specifi c | |||
* to each hash function. Specific hash functions MAY be written to be | * to each hash function. Specific hash functions MAY be written to be | |||
* multithread-safe. | * multithread-safe. | |||
* | * | |||
* The struct contains the following function(s): | ||||
* | ||||
* int (*reset)(hashFunctionParam* param); | ||||
* | ||||
* This function will re-initialize the parameters of this hash function. | ||||
* Return value is 0 on success, or -1 on failure. | ||||
* | ||||
* int (*update)(hashFunctionParam* param, const byte* data, int size); | ||||
* | ||||
* This function updates the hash function with an array of bytes. | ||||
* Return value is 0 on success, or -1 on failure. | ||||
* | ||||
* int (*digest)(hashFunctionParam* param, uint32* data); | ||||
* | ||||
* This function computes the digest of all the data passed to the hash | ||||
* function, and stores the result in data. | ||||
* Return value is 0 on success, or -1 on failure. | ||||
* NOTE: data MUST have a size (in bytes) of at least 'digestsize' as descr ibed | * NOTE: data MUST have a size (in bytes) of at least 'digestsize' as descr ibed | |||
* in the hashFunction struct. | * in the hashFunction struct. | |||
* NOTE: for safety reasons, after calling digest, each specific implementa tion | * NOTE: for safety reasons, after calling digest, each specific implementa tion | |||
* MUST reset itself so that previous values in the parameters are erased. | * MUST reset itself so that previous values in the parameters are erased. | |||
*/ | */ | |||
typedef struct | typedef struct | |||
{ | { | |||
const char* name; | const char* name; | |||
const unsigned int paramsize; /* in bytes | const size_t paramsize; /* in bytes | |||
*/ | */ | |||
const unsigned int blocksize; /* in bytes | const size_t blocksize; /* in bytes | |||
*/ | */ | |||
const unsigned int digestsize; /* in bytes | const size_t digestsize; /* in bytes | |||
*/ | */ | |||
const hashFunctionReset reset; | const hashFunctionReset reset; | |||
const hashFunctionUpdate update; | const hashFunctionUpdate update; | |||
const hashFunctionDigest digest; | const hashFunctionDigest digest; | |||
} hashFunction; | } hashFunction; | |||
/* | /* | |||
* You can use the following functions to find hash functions implemented b y | * You can use the following functions to find hash functions implemented b y | |||
* the library: | * the library: | |||
* | * | |||
* hashFunctionCount returns the number of hash functions available. | * hashFunctionCount returns the number of hash functions available. | |||
skipping to change at line 289 | skipping to change at line 298 | |||
* bounds. | * bounds. | |||
* | * | |||
* hashFunctionFind returns the hash function with the given name, or | * hashFunctionFind returns the hash function with the given name, or | |||
* NULL if no hash function exists with that name. | * NULL if no hash function exists with that name. | |||
*/ | */ | |||
#ifdef __cplusplus | #ifdef __cplusplus | |||
extern "C" { | extern "C" { | |||
#endif | #endif | |||
BEEDLLAPI | BEECRYPTAPI | |||
int hashFunctionCount(); | int hashFunctionCount(void); | |||
BEEDLLAPI | BEECRYPTAPI | |||
const hashFunction* hashFunctionGet(int); | const hashFunction* hashFunctionGet(int); | |||
BEEDLLAPI | BEECRYPTAPI | |||
const hashFunction* hashFunctionFind(const char*); | const hashFunction* hashFunctionFind(const char*); | |||
BEEDLLAPI | BEECRYPTAPI | |||
const hashFunction* hashFunctionDefault(); | const hashFunction* hashFunctionDefault(void); | |||
#ifdef __cplusplus | #ifdef __cplusplus | |||
} | } | |||
#endif | #endif | |||
/* | /* | |||
* The struct 'hashFunctionContext' is used to contain both the functional | * The struct 'hashFunctionContext' is used to contain both the functional | |||
* part (the hashFunction), and its parameters. | * part (the hashFunction), and its parameters. | |||
*/ | */ | |||
skipping to change at line 323 | skipping to change at line 332 | |||
/* | /* | |||
* The following functions can be used to initialize and free a | * The following functions can be used to initialize and free a | |||
* hashFunctionContext. Initializing will allocate a buffer of the size | * hashFunctionContext. Initializing will allocate a buffer of the size | |||
* required by the hashFunction, freeing will deallocate that buffer. | * required by the hashFunction, freeing will deallocate that buffer. | |||
*/ | */ | |||
#ifdef __cplusplus | #ifdef __cplusplus | |||
extern "C" { | extern "C" { | |||
#endif | #endif | |||
BEEDLLAPI | BEECRYPTAPI | |||
int hashFunctionContextInit(hashFunctionContext*, const hashFunction*); | int hashFunctionContextInit(hashFunctionContext*, const hashFunction*); | |||
BEEDLLAPI | BEECRYPTAPI | |||
int hashFunctionContextFree(hashFunctionContext*); | int hashFunctionContextFree(hashFunctionContext*); | |||
BEEDLLAPI | BEECRYPTAPI | |||
int hashFunctionContextReset(hashFunctionContext*); | int hashFunctionContextReset(hashFunctionContext*); | |||
BEEDLLAPI | BEECRYPTAPI | |||
int hashFunctionContextUpdate(hashFunctionContext*, const byte*, int); | int hashFunctionContextUpdate(hashFunctionContext*, const byte*, size_t); | |||
BEEDLLAPI | BEECRYPTAPI | |||
int hashFunctionContextUpdateMC(hashFunctionContext*, const memchunk*); | int hashFunctionContextUpdateMC(hashFunctionContext*, const memchunk*); | |||
BEEDLLAPI | BEECRYPTAPI | |||
int hashFunctionContextUpdateMP32(hashFunctionContext*, const mp32number*); | int hashFunctionContextUpdateMP(hashFunctionContext*, const mpnumber*); | |||
BEEDLLAPI | BEECRYPTAPI | |||
int hashFunctionContextDigest(hashFunctionContext*, mp32number*); | int hashFunctionContextDigest(hashFunctionContext*, byte*); | |||
BEEDLLAPI | BEECRYPTAPI | |||
int hashFunctionContextDigestMatch(hashFunctionContext*, const mp32number*) | int hashFunctionContextDigestMP(hashFunctionContext*, mpnumber*); | |||
; | BEECRYPTAPI | |||
int hashFunctionContextDigestMatch(hashFunctionContext*, const mpnumber*); | ||||
#ifdef __cplusplus | #ifdef __cplusplus | |||
} | } | |||
#endif | #endif | |||
/* | /* | |||
* Keyed Hash Functions, a.k.a. Message Authentication Codes | * Keyed Hash Functions, a.k.a. Message Authentication Codes | |||
*/ | */ | |||
/*!\typedef void keyedHashFunctionParam | ||||
* \ingroup HMAC_m | ||||
*/ | ||||
typedef void keyedHashFunctionParam; | typedef void keyedHashFunctionParam; | |||
typedef int (*keyedHashFunctionSetup )(keyedHashFunctionParam*, const uint 32*, int); | typedef int (*keyedHashFunctionSetup )(keyedHashFunctionParam*, const byte *, size_t); | |||
typedef int (*keyedHashFunctionReset )(keyedHashFunctionParam*); | typedef int (*keyedHashFunctionReset )(keyedHashFunctionParam*); | |||
typedef int (*keyedHashFunctionUpdate )(keyedHashFunctionParam*, const byte | typedef int (*keyedHashFunctionUpdate )(keyedHashFunctionParam*, const byte | |||
*, int); | *, size_t); | |||
typedef int (*keyedHashFunctionDigest )(keyedHashFunctionParam*, uint32*); | typedef int (*keyedHashFunctionDigest )(keyedHashFunctionParam*, byte*); | |||
/* | /* | |||
* The struct 'keyedHashFunction' holds information and pointers to code | * The struct 'keyedHashFunction' holds information and pointers to code | |||
* specific to each keyed hash function. Specific keyed hash functions MAY be | * specific to each keyed hash function. Specific keyed hash functions MAY be | |||
* written to be multithread-safe. | * written to be multithread-safe. | |||
* | * | |||
* The struct field 'keybitsmin' contains the minimum number of bits a key | * The struct field 'keybitsmin' contains the minimum number of bits a key | |||
* must contains, 'keybitsmax' the maximum number of bits a key may contain , | * must contains, 'keybitsmax' the maximum number of bits a key may contain , | |||
* 'keybitsinc', the increment in bits that may be used between min and max . | * 'keybitsinc', the increment in bits that may be used between min and max . | |||
* | * | |||
* The struct contains the following function(s): | ||||
* | ||||
* int (*setup)(keyedHashFunctionParam *param, const uint32* key, int keybi | ||||
ts); | ||||
* | ||||
* This function will setup the keyed hash function parameters with the giv | ||||
en | ||||
* secret key; it will also 'reset' the parameters. | ||||
* Return value is 0 on success, or -1 on failure. | ||||
* NOTE: after use, it is recommended to wipe the parameters by calling set | ||||
up | ||||
* again with another (dummy) key. | ||||
* | ||||
* int (*reset)(keyedHashFunctionParam* param); | ||||
* | ||||
* This function will re-initialize the parameters of this keyed hash funct | ||||
ion. | ||||
* Return value is 0 on success, or -1 on failure. | ||||
* | ||||
* int (*update)(keyedHashFunctionParam* param, const byte* data, int size) | ||||
; | ||||
* | ||||
* This function updates the keyed hash function with an array of bytes. | ||||
* Return value is 0 on success, or -1 on failure. | ||||
* | ||||
* int (*digest)(keyedHashFunctionParam* param, uint32* data); | ||||
* | ||||
* This function computes the digest (or authentication code) of all the da | ||||
ta | ||||
* passed to the keyed hash function, and stores the result in data. | ||||
* Return value is 0 on success, or -1 on failure. | ||||
* NOTE: data must be at least have a bytesize of 'digestsize' as described | * NOTE: data must be at least have a bytesize of 'digestsize' as described | |||
* in the keyedHashFunction struct. | * in the keyedHashFunction struct. | |||
* NOTE: for safety reasons, after calling digest, each specific implementa tion | * NOTE: for safety reasons, after calling digest, each specific implementa tion | |||
* MUST reset itself so that previous values in the parameters are erased. | * MUST reset itself so that previous values in the parameters are erased. | |||
*/ | */ | |||
typedef struct | typedef struct | |||
{ | { | |||
const char* name; | const char* name; | |||
const unsigned int paramsize; /* i | const size_t paramsize; /* i | |||
n bytes */ | n bytes */ | |||
const unsigned int blocksize; /* i | const size_t blocksize; /* i | |||
n bytes */ | n bytes */ | |||
const unsigned int digestsize; /* i | const size_t digestsize; /* i | |||
n bytes */ | n bytes */ | |||
const unsigned int keybitsmin; /* i | const size_t keybitsmin; /* i | |||
n bits */ | n bits */ | |||
const unsigned int keybitsmax; /* i | const size_t keybitsmax; /* i | |||
n bits */ | n bits */ | |||
const unsigned int keybitsinc; /* i | const size_t keybitsinc; /* i | |||
n bits */ | n bits */ | |||
const keyedHashFunctionSetup setup; | const keyedHashFunctionSetup setup; | |||
const keyedHashFunctionReset reset; | const keyedHashFunctionReset reset; | |||
const keyedHashFunctionUpdate update; | const keyedHashFunctionUpdate update; | |||
const keyedHashFunctionDigest digest; | const keyedHashFunctionDigest digest; | |||
} keyedHashFunction; | } keyedHashFunction; | |||
/* | /* | |||
* You can use the following functions to find keyed hash functions impleme nted | * You can use the following functions to find keyed hash functions impleme nted | |||
* by the library: | * by the library: | |||
* | * | |||
skipping to change at line 428 | skipping to change at line 417 | |||
* was out of bounds. | * was out of bounds. | |||
* | * | |||
* keyedHashFunctionFind returns the keyed hash function with the given nam e, | * keyedHashFunctionFind returns the keyed hash function with the given nam e, | |||
* or NULL if no keyed hash function exists with that name. | * or NULL if no keyed hash function exists with that name. | |||
*/ | */ | |||
#ifdef __cplusplus | #ifdef __cplusplus | |||
extern "C" { | extern "C" { | |||
#endif | #endif | |||
BEEDLLAPI | BEECRYPTAPI | |||
int keyedHashFunctionCou | int keyedHashFunctionCou | |||
nt(); | nt(void); | |||
BEEDLLAPI | BEECRYPTAPI | |||
const keyedHashFunction* keyedHashFunctionGet(int); | const keyedHashFunction* keyedHashFunctionGet(int); | |||
BEEDLLAPI | BEECRYPTAPI | |||
const keyedHashFunction* keyedHashFunctionFind(const char*); | const keyedHashFunction* keyedHashFunctionFind(const char*); | |||
BEEDLLAPI | BEECRYPTAPI | |||
const keyedHashFunction* keyedHashFunctionDefault(); | const keyedHashFunction* keyedHashFunctionDefault(void); | |||
#ifdef __cplusplus | #ifdef __cplusplus | |||
} | } | |||
#endif | #endif | |||
/* | /* | |||
* The struct 'keyedHashFunctionContext' is used to contain both the functi onal | * The struct 'keyedHashFunctionContext' is used to contain both the functi onal | |||
* part (the keyedHashFunction), and its parameters. | * part (the keyedHashFunction), and its parameters. | |||
*/ | */ | |||
skipping to change at line 462 | skipping to change at line 451 | |||
/* | /* | |||
* The following functions can be used to initialize and free a | * The following functions can be used to initialize and free a | |||
* keyedHashFunctionContext. Initializing will allocate a buffer of the siz e | * keyedHashFunctionContext. Initializing will allocate a buffer of the siz e | |||
* required by the keyedHashFunction, freeing will deallocate that buffer. | * required by the keyedHashFunction, freeing will deallocate that buffer. | |||
*/ | */ | |||
#ifdef __cplusplus | #ifdef __cplusplus | |||
extern "C" { | extern "C" { | |||
#endif | #endif | |||
BEEDLLAPI | BEECRYPTAPI | |||
int keyedHashFunctionContextInit(keyedHashFunctionContext*, const keyedHash Function*); | int keyedHashFunctionContextInit(keyedHashFunctionContext*, const keyedHash Function*); | |||
BEEDLLAPI | BEECRYPTAPI | |||
int keyedHashFunctionContextFree(keyedHashFunctionContext*); | int keyedHashFunctionContextFree(keyedHashFunctionContext*); | |||
BEEDLLAPI | BEECRYPTAPI | |||
int keyedHashFunctionContextSetup(keyedHashFunctionContext*, const uint32*, | int keyedHashFunctionContextSetup(keyedHashFunctionContext*, const byte*, s | |||
int); | ize_t); | |||
BEEDLLAPI | BEECRYPTAPI | |||
int keyedHashFunctionContextReset(keyedHashFunctionContext*); | int keyedHashFunctionContextReset(keyedHashFunctionContext*); | |||
BEEDLLAPI | BEECRYPTAPI | |||
int keyedHashFunctionContextUpdate(keyedHashFunctionContext*, const byte*, | int keyedHashFunctionContextUpdate(keyedHashFunctionContext*, const byte*, | |||
int); | size_t); | |||
BEEDLLAPI | BEECRYPTAPI | |||
int keyedHashFunctionContextUpdateMC(keyedHashFunctionContext*, const memch unk*); | int keyedHashFunctionContextUpdateMC(keyedHashFunctionContext*, const memch unk*); | |||
BEEDLLAPI | BEECRYPTAPI | |||
int keyedHashFunctionContextUpdateMP32(keyedHashFunctionContext*, const mp3 | int keyedHashFunctionContextUpdateMP(keyedHashFunctionContext*, const mpnum | |||
2number*); | ber*); | |||
BEEDLLAPI | BEECRYPTAPI | |||
int keyedHashFunctionContextDigest(keyedHashFunctionContext*, mp32number*); | int keyedHashFunctionContextDigest(keyedHashFunctionContext*, byte*); | |||
BEEDLLAPI | BEECRYPTAPI | |||
int keyedHashFunctionContextDigestMatch(keyedHashFunctionContext*, const mp | int keyedHashFunctionContextDigestMP(keyedHashFunctionContext*, mpnumber*); | |||
32number*); | BEECRYPTAPI | |||
int keyedHashFunctionContextDigestMatch(keyedHashFunctionContext*, const mp | ||||
number*); | ||||
#ifdef __cplusplus | #ifdef __cplusplus | |||
} | } | |||
#endif | #endif | |||
/* | /* | |||
* Block ciphers | * Block ciphers | |||
*/ | */ | |||
/*!\enum cipherOperation | ||||
* \brief Specifies whether to perform encryption or decryption. | ||||
* \ingroup BC_m | ||||
*/ | ||||
typedef enum | typedef enum | |||
{ | { | |||
NOCRYPT, | ||||
ENCRYPT, | ENCRYPT, | |||
DECRYPT | DECRYPT | |||
} cipherOperation; | } cipherOperation; | |||
typedef enum | /*!\typedef void blockCipherParam | |||
{ | * \brief Placeholder type definition for blockcipher parameters. | |||
ECB, | * \sa aesParam, blowfishParam. | |||
CBC | * \ingroup BC_m | |||
} cipherMode; | */ | |||
typedef void blockCipherParam; | typedef void blockCipherParam; | |||
typedef int (*blockModeEncrypt)(blockCipherParam*, int, uint32*, const uint | /*!\brief Prototype definition for a setup function. | |||
32*); | * \ingroup BC_m | |||
typedef int (*blockModeDecrypt)(blockCipherParam*, int, uint32*, const uint | */ | |||
32*); | typedef int (*blockCipherSetup )(blockCipherParam*, const byte*, size_t, c | |||
ipherOperation); | ||||
/*!\typedef int (*blockCipherSetIV)(blockCipherPatam* bp, const byte* iv) | ||||
* \brief Prototype definition for an initialization vector setup function. | ||||
* \param bp The blockcipher's parameters. | ||||
* \param iv The blockciphers' IV value. | ||||
* \note iv length must be equal to the cipher's block size. | ||||
* \retval 0 on success. | ||||
* \retval -1 on failure. | ||||
* \ingroup BC_m | ||||
*/ | ||||
typedef int (*blockCipherSetIV )(blockCipherParam*, const byte*); | ||||
/*!\typedef int (*blockCipherRawcrypt)(blockCipherParam* bp, uint32_t* dst, | ||||
const uint32_t* src) | ||||
* \brief Prototype for a \e raw encryption or decryption function. | ||||
* \param bp The blockcipher's parameters. | ||||
* \param dst The ciphertext address; must be aligned on 32-bit boundary. | ||||
* \param src The cleartext address; must be aligned on 32-bit boundary. | ||||
* \retval 0 on success. | ||||
* \retval -1 on failure. | ||||
* \ingroup BC_m | ||||
*/ | ||||
typedef int (*blockCipherRawcrypt)(blockCipherParam*, uint32_t*, const uint | ||||
32_t*); | ||||
/*!\typedef int (*blockCipherModcrypt)(blockCipherParam* bp, uint32_t* dst, | ||||
const uint32_t* src, unsigned int nblocks) | ||||
* \brief Prototype for a \e encryption or decryption function which operat | ||||
es | ||||
* on multiple blocks in a certain mode. | ||||
* \param bp The blockcipher's parameters. | ||||
* \param dst The ciphertext address; must be aligned on 32-bit boundary. | ||||
* \param src The cleartext address; must be aligned on 32-bit boundary. | ||||
* \param nblocks The number of blocks to process. | ||||
* \retval 0 on success. | ||||
* \retval -1 on failure. | ||||
* \ingroup BC_m | ||||
*/ | ||||
typedef int (*blockCipherModcrypt)(blockCipherParam*, uint32_t*, const uint | ||||
32_t*, unsigned int); | ||||
typedef uint32_t* (*blockCipherFeedback)(blockCipherParam*); | ||||
typedef struct | typedef struct | |||
{ | { | |||
const blockModeEncrypt encrypt; | const blockCipherRawcrypt encrypt; | |||
const blockModeDecrypt decrypt; | const blockCipherRawcrypt decrypt; | |||
} blockMode; | } blockCipherRaw; | |||
typedef int (*blockCipherSetup )(blockCipherParam*, const uint32*, int, ci | typedef struct | |||
pherOperation); | { | |||
typedef int (*blockCipherSetIV )(blockCipherParam*, const uint32*); | const blockCipherModcrypt encrypt; | |||
typedef int (*blockCipherEncrypt)(blockCipherParam*, uint32*, const uint32* | const blockCipherModcrypt decrypt; | |||
); | } blockCipherMode; | |||
typedef int (*blockCipherDecrypt)(blockCipherParam*, uint32*, const uint32* | ||||
); | ||||
/* | /*!\brief Holds information and pointers to code specific to each cipher. | |||
* The struct 'blockCipher' holds information and pointers to code specific | ||||
* to each blockcipher. Specific block ciphers MAY be written to be | ||||
* multithread-safe. | ||||
* | ||||
* The struct field 'keybitsmin' contains the minimum number of bits a key | ||||
* must contains, 'keybitsmax' the maximum number of bits a key may contain | ||||
, | ||||
* 'keybitsinc', the increment in bits that may be used between min and max | ||||
. | ||||
* | ||||
* The struct contains the following function(s): | ||||
* | ||||
* int (*setup)(blockCipherParam *param, const uint32* key, int keybits, ci | ||||
pherOperation); | ||||
* | ||||
* This function will setup the blockcipher parameters with the given secre | ||||
t | ||||
* key for either encryption or decryption; | ||||
* Return value is 0 on success, or -1 on failure. | ||||
* NOTE: after use, it is recommended to wipe the parameters by calling set | ||||
up | ||||
* again with another (dummy) key. | ||||
* | ||||
* int (*encrypt)(blockCipherParam* param, uint32* block); | ||||
* | ||||
* This function will encrypt one block of data (with bit size equal to | ||||
* 'blockbits') | ||||
* Return value is 0 on success, or -1 on failure. | ||||
* NOTE: this is raw encryption, without padding, etc. | ||||
* | * | |||
* int (*decrypt)(blockCipherParam* param, uint32* block); | * Specific block ciphers \e may be written to be multithread-safe. | |||
* | * | |||
* This function will decrypt one block of data (with bit size equal to | * \ingroup BC_m | |||
* 'blockbits') | ||||
* Return value is 0 on success, or -1 on failure. | ||||
* NOTE: this is raw decryption, without padding, etc. | ||||
*/ | */ | |||
typedef struct | typedef struct | |||
{ | { | |||
/*!\var name | ||||
* \brief The blockcipher's name. | ||||
*/ | ||||
const char* name; | const char* name; | |||
const unsigned int paramsize; /* in bytes | /*!\var paramsize | |||
*/ | * \brief The size of the parameters required by this cipher, in byt | |||
const unsigned int blocksize; /* in bytes | es. | |||
*/ | */ | |||
const unsigned int keybitsmin; /* in bits * | const size_t paramsize; | |||
/ | /*!\var blocksize | |||
const unsigned int keybitsmax; /* in bits * | * \brief The size of one block of data, in bytes. | |||
/ | */ | |||
const unsigned int keybitsinc; /* in bits * | const size_t blocksize; | |||
/ | /*!\var keybitsmin | |||
* \brief The minimum number of key bits. | ||||
*/ | ||||
const size_t keybitsmin; | ||||
/*!\var keybitsmax | ||||
* \brief The maximum number of key bits. | ||||
*/ | ||||
const size_t keybitsmax; | ||||
/*!\var keybitsinc | ||||
* \brief The allowed increment in key bits between min and max. | ||||
* \see keybitsmin and keybitsmax. | ||||
*/ | ||||
const size_t keybitsinc; | ||||
/*!\var setup | ||||
* \brief Pointer to the cipher's setup function. | ||||
*/ | ||||
const blockCipherSetup setup; | const blockCipherSetup setup; | |||
/*!\var setiv | ||||
* \brief Pointer to the cipher's initialization vector setup functi | ||||
on. | ||||
*/ | ||||
const blockCipherSetIV setiv; | const blockCipherSetIV setiv; | |||
const blockCipherEncrypt encrypt; | /*!\var raw | |||
const blockCipherDecrypt decrypt; | * \brief The cipher's raw functions. | |||
const blockMode* mode; | */ | |||
const blockCipherRaw raw; | ||||
/*!\var ecb | ||||
* \brief The cipher's ECB functions. | ||||
*/ | ||||
const blockCipherMode ecb; | ||||
const blockCipherMode cbc; | ||||
/*!\var getfb | ||||
* \brief Pointer to the cipher's feedback-returning function. | ||||
*/ | ||||
const blockCipherFeedback getfb; | ||||
} blockCipher; | } blockCipher; | |||
/* | ||||
* You can use the following functions to find blockciphers implemented by | ||||
* the library: | ||||
* | ||||
* blockCipherCount returns the number of blockciphers available. | ||||
* | ||||
* blockCipherGet returns the blockcipher with a given index (starting | ||||
* at zero, up to blockCipherCount() - 1), or NULL if the index was out of | ||||
* bounds. | ||||
* | ||||
* blockCipherFind returns the blockcipher with the given name, or | ||||
* NULL if no hash function exists with that name. | ||||
*/ | ||||
#ifdef __cplusplus | #ifdef __cplusplus | |||
extern "C" { | extern "C" { | |||
#endif | #endif | |||
BEEDLLAPI | /*!\fn int blockCipherCount() | |||
int blockCipherCount(); | * \brief This function returns the number of blockciphers implemented | |||
BEEDLLAPI | * by the library. | |||
* \return The number of implemented blockciphers. | ||||
*/ | ||||
BEECRYPTAPI | ||||
int blockCipherCount(void); | ||||
/*!\fn const blockCipher* blockCipherGet(int n) | ||||
* \brief This function returns the \a n -th blockcipher implemented by | ||||
* the library. | ||||
* \param n Index of the requested blockcipher; legal values are 0 | ||||
* through blockCipherCount() - 1. | ||||
* \return A pointer to a blockcipher or null, if the index was out of | ||||
* range. | ||||
*/ | ||||
BEECRYPTAPI | ||||
const blockCipher* blockCipherGet(int); | const blockCipher* blockCipherGet(int); | |||
BEEDLLAPI | ||||
/*!\fn const blockCIiher* blockCipherFind(const char* name) | ||||
* \brief This function returns the blockcipher specified by the given name | ||||
. | ||||
* \param name Name of the requested blockcipher. | ||||
* \return A pointer to a blockcipher or null, if the name wasn't found. | ||||
*/ | ||||
BEECRYPTAPI | ||||
const blockCipher* blockCipherFind(const char*); | const blockCipher* blockCipherFind(const char*); | |||
BEEDLLAPI | ||||
const blockCipher* blockCipherDefault(); | /*!\fn const blockCipher* blockCipherDefault() | |||
* \brief This functions returns the default blockcipher; the default value | ||||
* can be specified by setting environment variable BEECRYPT_CIPHER. | ||||
* \return A pointer to a blockcipher or null, in case an error occured. | ||||
*/ | ||||
BEECRYPTAPI | ||||
const blockCipher* blockCipherDefault(void); | ||||
#ifdef __cplusplus | #ifdef __cplusplus | |||
} | } | |||
#endif | #endif | |||
/* | /*!\brief Holds a pointer to a blockcipher as well as its parameters. | |||
* The struct 'blockCipherContext' is used to contain both the functional | * \warning A context can be used by only one thread at the same time. | |||
* part (the blockCipher), and its parameters. | * \ingroup BC_m | |||
*/ | */ | |||
typedef struct | typedef struct | |||
{ | { | |||
const blockCipher* algo; | /*!\var algo | |||
blockCipherParam* param; | * \brief Pointer to a blockCipher. | |||
*/ | ||||
const blockCipher* algo; | ||||
/*!\var param | ||||
* \brief Pointer to the parameters used by algo. | ||||
*/ | ||||
blockCipherParam* param; | ||||
/*!\var op | ||||
*/ | ||||
cipherOperation op; | ||||
} blockCipherContext; | } blockCipherContext; | |||
/* | /* | |||
* The following functions can be used to initialize and free a | * The following functions can be used to initialize and free a | |||
* blockCipherContext. Initializing will allocate a buffer of the size | * blockCipherContext. Initializing will allocate a buffer of the size | |||
* required by the blockCipher, freeing will deallocate that buffer. | * required by the blockCipher, freeing will deallocate that buffer. | |||
*/ | */ | |||
#ifdef __cplusplus | #ifdef __cplusplus | |||
extern "C" { | extern "C" { | |||
#endif | #endif | |||
BEEDLLAPI | BEECRYPTAPI | |||
int blockCipherContextInit(blockCipherContext*, const blockCipher*); | int blockCipherContextInit(blockCipherContext*, const blockCipher*); | |||
BEEDLLAPI | ||||
int blockCipherContextSetup(blockCipherContext*, const uint32*, int, cipher | BEECRYPTAPI | |||
Operation); | int blockCipherContextSetup(blockCipherContext*, const byte*, size_t, ciphe | |||
BEEDLLAPI | rOperation); | |||
int blockCipherContextSetIV(blockCipherContext*, const uint32*); | ||||
BEEDLLAPI | BEECRYPTAPI | |||
int blockCipherContextSetIV(blockCipherContext*, const byte*); | ||||
BEECRYPTAPI | ||||
int blockCipherContextFree(blockCipherContext*); | int blockCipherContextFree(blockCipherContext*); | |||
BEECRYPTAPI | ||||
int blockCipherContextECB(blockCipherContext*, uint32_t*, const uint32_t*, | ||||
int); | ||||
BEECRYPTAPI | ||||
int blockCipherContextCBC(blockCipherContext*, uint32_t*, const uint32_t*, | ||||
int); | ||||
#ifdef __cplusplus | #ifdef __cplusplus | |||
} | } | |||
#endif | #endif | |||
#endif | #endif | |||
End of changes. 76 change blocks. | ||||
315 lines changed or deleted | 376 lines changed or added | |||
blockmode.h | blockmode.h | |||
---|---|---|---|---|
/* | /* | |||
* blockmode.h | * Copyright (c) 2000, 2002 Virtual Unlimited B.V. | |||
* | ||||
* Blockcipher operation modes, header | ||||
* | ||||
* Copyright (c) 2000 Virtual Unlimited B.V. | ||||
* | ||||
* Author: Bob Deblier <bob@virtualunlimited.com> | ||||
* | * | |||
* This library is free software; you can redistribute it and/or | * This library is free software; you can redistribute it and/or | |||
* modify it under the terms of the GNU Lesser General Public | * modify it under the terms of the GNU Lesser General Public | |||
* License as published by the Free Software Foundation; either | * License as published by the Free Software Foundation; either | |||
* version 2.1 of the License, or (at your option) any later version. | * version 2.1 of the License, or (at your option) any later version. | |||
* | * | |||
* This library is distributed in the hope that it will be useful, | * This library is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
* Lesser General Public License for more details. | * Lesser General Public License for more details. | |||
* | * | |||
* You should have received a copy of the GNU Lesser General Public | * You should have received a copy of the GNU Lesser General Public | |||
* License along with this library; if not, write to the Free Software | * License along with this library; if not, write to the Free Software | |||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 US A | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 US A | |||
* | * | |||
*/ | */ | |||
/*!\file blockmode.h | ||||
* \brief Blockcipher operation modes. | ||||
* \todo Additional modes, such as CFB and OFB. | ||||
* \author Bob Deblier <bob.deblier@pandora.be> | ||||
* \ingroup BC_m | ||||
*/ | ||||
#ifndef _BLOCKMODE_H | #ifndef _BLOCKMODE_H | |||
#define _BLOCKMODE_H | #define _BLOCKMODE_H | |||
#include "beecrypt.h" | #include "beecrypt.h" | |||
#ifdef __cplusplus | #ifdef __cplusplus | |||
extern "C" { | extern "C" { | |||
#endif | #endif | |||
BEEDLLAPI | /*!\fn int blockEncryptECB(const blockCipher* bc, blockCipherParam* bp, uin | |||
int blockEncrypt(const blockCipher*, blockCipherParam*, cipherMode, int, ui | t32_t* dst, const uint32_t* src, unsigned int nblocks) | |||
nt32*, const uint32*); | * \brief This function encrypts a number of data blocks in Electronic Code | |||
BEEDLLAPI | * Book mode. | |||
int blockDecrypt(const blockCipher*, blockCipherParam*, cipherMode, int, ui | * \param bc The blockcipher. | |||
nt32*, const uint32*); | * \param bp The cipher's parameter block. | |||
* \param dst The ciphertext data; should be aligned on a 32-bit boundary. | ||||
* \param src The cleartext data; should be aligned on a 32-bit boundary. | ||||
* \param nblocks The number of blocks to be encrypted. | ||||
* \retval 0 on success. | ||||
*/ | ||||
BEECRYPTAPI | ||||
int blockEncryptECB(const blockCipher* bc, blockCipherParam* bp, uint32_t* | ||||
dst, const uint32_t* src, unsigned int nblocks); | ||||
/*!\fn int blockDecryptECB(const blockCipher* bc, blockCipherParam* bp, uin | ||||
t32_t* dst, const uint32_t* src, unsigned int nblocks) | ||||
* \brief This function decrypts a number of data blocks in Electronic Code | ||||
* Book mode. | ||||
* \param bc The blockcipher. | ||||
* \param bp The cipher's parameter block. | ||||
* \param dst The cleartext data; should be aligned on a 32-bit boundary. | ||||
* \param src The ciphertext data; should be aligned on a 32-bit boundary. | ||||
* \param nblocks The number of blocks to be decrypted. | ||||
* \retval 0 on success. | ||||
*/ | ||||
BEECRYPTAPI | ||||
int blockDecryptECB(const blockCipher* bc, blockCipherParam* bp, uint32_t* | ||||
dst, const uint32_t* src, unsigned int nblocks); | ||||
/*!\fn int blockEncryptCBC(const blockCipher* bc, blockCipherParam* bp, uin | ||||
t32_t* dst, const uint32_t* src, unsigned int nblocks) | ||||
* \brief This function encrypts a number of data blocks in Cipher Block | ||||
* Chaining mode. | ||||
* \param bc The blockcipher. | ||||
* \param bp The cipher's parameter block. | ||||
* \param dst The ciphertext data; should be aligned on a 32-bit boundary. | ||||
* \param src The cleartext data; should be aligned on a 32-bit boundary. | ||||
* \param nblocks The number of blocks to be encrypted. | ||||
* \retval 0 on success. | ||||
*/ | ||||
BEECRYPTAPI | ||||
int blockEncryptCBC(const blockCipher* bc, blockCipherParam* bp, uint32_t* | ||||
dst, const uint32_t* src, unsigned int nblocks); | ||||
/*!\fn int blockDecryptCBC(const blockCipher* bc, blockCipherParam* bp, uin | ||||
t32_t* dst, const uint32_t* src, unsigned int nblocks) | ||||
* \brief This function decrypts a number of data blocks in Cipher Block | ||||
* Chaining mode. | ||||
* \param bc The blockcipher. | ||||
* \param bp The cipher's parameter block. | ||||
* \param dst The cleartext data; should be aligned on a 32-bit boundary. | ||||
* \param src The ciphertext data; should be aligned on a 32-bit boundary. | ||||
* \param nblocks The number of blocks to be decrypted. | ||||
* \retval 0 on success. | ||||
*/ | ||||
BEECRYPTAPI | ||||
int blockDecryptCBC(const blockCipher* bc, blockCipherParam* bp, uint32_t* | ||||
dst, const uint32_t* src, unsigned int nblocks); | ||||
#ifdef __cplusplus | #ifdef __cplusplus | |||
} | } | |||
#endif | #endif | |||
#endif | #endif | |||
End of changes. 3 change blocks. | ||||
13 lines changed or deleted | 67 lines changed or added | |||
blockpad.h | blockpad.h | |||
---|---|---|---|---|
/* | /* | |||
* blockpad.h | * Copyright (c) 2000, 2001, 2002 Virtual Unlimited B.V. | |||
* | ||||
* Blockcipher padding, header | ||||
* | ||||
* Copyright (c) 2000, 2001 Virtual Unlimited B.V. | ||||
* | ||||
* Author: Bob Deblier <bob@virtualunlimited.com> | ||||
* | * | |||
* This library is free software; you can redistribute it and/or | * This library is free software; you can redistribute it and/or | |||
* modify it under the terms of the GNU Lesser General Public | * modify it under the terms of the GNU Lesser General Public | |||
* License as published by the Free Software Foundation; either | * License as published by the Free Software Foundation; either | |||
* version 2.1 of the License, or (at your option) any later version. | * version 2.1 of the License, or (at your option) any later version. | |||
* | * | |||
* This library is distributed in the hope that it will be useful, | * This library is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
* Lesser General Public License for more details. | * Lesser General Public License for more details. | |||
* | * | |||
* You should have received a copy of the GNU Lesser General Public | * You should have received a copy of the GNU Lesser General Public | |||
* License along with this library; if not, write to the Free Software | * License along with this library; if not, write to the Free Software | |||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 US A | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 US A | |||
* | * | |||
*/ | */ | |||
/*!\file blockpad.h | ||||
* \brief Blockcipher padding algorithms. | ||||
* \author Bob Deblier <bob.deblier@pandora.be> | ||||
* \ingroup BC_m | ||||
*/ | ||||
#ifndef _BLOCKPAD_H | #ifndef _BLOCKPAD_H | |||
#define _BLOCKPAD_H | #define _BLOCKPAD_H | |||
#include "beecrypt.h" | #include "beecrypt.h" | |||
#ifdef __cplusplus | #ifdef __cplusplus | |||
extern "C" { | extern "C" { | |||
#endif | #endif | |||
BEEDLLAPI | BEECRYPTAPI | |||
memchunk* pkcs5Pad (int, memchunk*); | memchunk* pkcs5Pad (size_t, memchunk*); | |||
BEEDLLAPI | BEECRYPTAPI | |||
memchunk* pkcs5Unpad(int, memchunk*); | memchunk* pkcs5Unpad(size_t, memchunk*); | |||
BEEDLLAPI | BEECRYPTAPI | |||
memchunk* pkcs5PadCopy (int, const memchunk*); | memchunk* pkcs5PadCopy (size_t, const memchunk*); | |||
BEEDLLAPI | BEECRYPTAPI | |||
memchunk* pkcs5UnpadCopy(int, const memchunk*); | memchunk* pkcs5UnpadCopy(size_t, const memchunk*); | |||
#ifdef __cplusplus | #ifdef __cplusplus | |||
} | } | |||
#endif | #endif | |||
#endif | #endif | |||
End of changes. 4 change blocks. | ||||
15 lines changed or deleted | 15 lines changed or added | |||
blowfish.h | blowfish.h | |||
---|---|---|---|---|
/* | /* | |||
* blowfish.h | * Copyright (c) 1999, 2000, 2002 Virtual Unlimited B.V. | |||
* | ||||
* Blowfish block cipher, header | ||||
* | ||||
* Copyright (c) 1999, 2000 Virtual Unlimited B.V. | ||||
* | ||||
* Author: Bob Deblier <bob@virtualunlimited.com> | ||||
* | * | |||
* This library is free software; you can redistribute it and/or | * This library is free software; you can redistribute it and/or | |||
* modify it under the terms of the GNU Lesser General Public | * modify it under the terms of the GNU Lesser General Public | |||
* License as published by the Free Software Foundation; either | * License as published by the Free Software Foundation; either | |||
* version 2.1 of the License, or (at your option) any later version. | * version 2.1 of the License, or (at your option) any later version. | |||
* | * | |||
* This library is distributed in the hope that it will be useful, | * This library is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
* Lesser General Public License for more details. | * Lesser General Public License for more details. | |||
* | * | |||
* You should have received a copy of the GNU Lesser General Public | * You should have received a copy of the GNU Lesser General Public | |||
* License along with this library; if not, write to the Free Software | * License along with this library; if not, write to the Free Software | |||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 US A | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 US A | |||
* | * | |||
*/ | */ | |||
/*!\file blowfish.h | ||||
* \brief Blowfish block cipher. | ||||
* | ||||
* For more information on this blockcipher, see: | ||||
* "Applied Cryptography", second edition | ||||
* Bruce Schneier | ||||
* Wiley & Sons | ||||
* | ||||
* Also see http://www.counterpane.com/blowfish.html | ||||
* | ||||
* \author Bob Deblier <bob.deblier@pandora.be> | ||||
* \ingroup BC_m BC_blowfish_m | ||||
*/ | ||||
#ifndef _BLOWFISH_H | #ifndef _BLOWFISH_H | |||
#define _BLOWFISH_H | #define _BLOWFISH_H | |||
#include "beecrypt.h" | #include "beecrypt.h" | |||
#include "blowfishopt.h" | #include "blowfishopt.h" | |||
#define BLOWFISHROUNDS 16 | #define BLOWFISHROUNDS 16 | |||
#define BLOWFISHPSIZE (BLOWFISHROUNDS+2) | #define BLOWFISHPSIZE (BLOWFISHROUNDS+2) | |||
/*!\brief Holds all the parameters necessary for the Blowfish cipher. | ||||
* \ingroup BC_blowfish_m | ||||
*/ | ||||
typedef struct | typedef struct | |||
{ | { | |||
uint32 p[BLOWFISHPSIZE]; | /*!\var p | |||
uint32 s[1024]; | * \brief Holds the key expansion. | |||
uint32 fdback[2]; | */ | |||
uint32_t p[BLOWFISHPSIZE]; | ||||
/*!\var s | ||||
* \brief Holds the s-boxes. | ||||
*/ | ||||
uint32_t s[1024]; | ||||
/*!\var fdback | ||||
* \brief Buffer to be used by block chaining or feedback modes. | ||||
*/ | ||||
uint32_t fdback[2]; | ||||
} blowfishParam; | } blowfishParam; | |||
#ifdef __cplusplus | #ifdef __cplusplus | |||
extern "C" { | extern "C" { | |||
#endif | #endif | |||
extern const BEEDLLAPI blockCipher blowfish; | /*!\var blowfish | |||
* \brief Holds the full API description of the Blowfish algorithm. | ||||
*/ | ||||
extern const BEECRYPTAPI blockCipher blowfish; | ||||
BEEDLLAPI | /*!\fn int blowfishSetup(blowfishParam* bp, const byte* key, size_t keybits | |||
int blowfishSetup (blowfishParam*, const uint32*, int, cipherOperation); | , cipherOperation | |||
BEEDLLAPI | op) | |||
int blowfishSetIV (blowfishParam*, const uint32*); | * \brief The function performs the cipher's key expansion. | |||
BEEDLLAPI | * \param bp The cipher's parameter block. | |||
int blowfishEncrypt(blowfishParam*, uint32*, const uint32*); | * \param key The key value. | |||
BEEDLLAPI | * \param keybits The number of bits in the key; legal values are: 32 to 44 | |||
int blowfishDecrypt(blowfishParam*, uint32*, const uint32*); | 8, | |||
* in multiples of 8. | ||||
* \param op ENCRYPT or DECRYPT. | ||||
* \retval 0 on success. | ||||
* \retval -1 on failure. | ||||
*/ | ||||
BEECRYPTAPI | ||||
int blowfishSetup (blowfishParam*, const byte*, size_t, cipher | ||||
Operation); | ||||
BEEDLLAPI | /*!\fn int blowfishSetIV(blowfishParam* bp, const byte* iv) | |||
int blowfishECBEncrypt(blowfishParam*, int, uint32*, const uint32*); | * \brief This function sets the Initialization Vector. | |||
BEEDLLAPI | * \note This function is only useful in block chaining or feedback modes. | |||
int blowfishECBDecrypt(blowfishParam*, int, uint32*, const uint32*); | * \param bp The cipher's parameter block. | |||
* \param iv The initialization vector; may be null. | ||||
* \retval 0 on success. | ||||
*/ | ||||
BEECRYPTAPI | ||||
int blowfishSetIV (blowfishParam*, const byte*); | ||||
BEEDLLAPI | /*!\fn blowfishEncrypt(blowfishParam* bp, uint32_t* dst, const uint32_t* sr | |||
int blowfishCBCEncrypt(blowfishParam*, int, uint32*, const uint32*); | c) | |||
BEEDLLAPI | * \brief This function performs the Blowfish encryption; it encrypts one b | |||
int blowfishCBCDecrypt(blowfishParam*, int, uint32*, const uint32*); | lock | |||
* of 64 bits. | ||||
* \param bp The cipher's parameter block. | ||||
* \param dst The ciphertext; should be aligned on 32-bit boundary. | ||||
* \param src The cleartext; should be aligned on 32-bit boundary. | ||||
* \retval 0 on success. | ||||
*/ | ||||
BEECRYPTAPI | ||||
int blowfishEncrypt (blowfishParam*, uint32_t*, const uint32_t*) | ||||
; | ||||
/*!\fn blowfishDecrypt(blowfishParam* bp, uint32_t* dst, const uint32_t* sr | ||||
c) | ||||
* \brief This function performs the Blowfish decryption; it Rderypts one b | ||||
lock | ||||
* of 64 bits. | ||||
* \param bp The cipher's parameter block. | ||||
* \param dst The cleartext; should be aligned on 32-bit boundary. | ||||
* \param src The ciphertext; should be aligned on 32-bit boundary. | ||||
* \retval 0 on success. | ||||
*/ | ||||
BEECRYPTAPI | ||||
int blowfishDecrypt (blowfishParam*, uint32_t*, const uint32_t*) | ||||
; | ||||
BEECRYPTAPI | ||||
uint32_t* blowfishFeedback(blowfishParam*); | ||||
#ifdef __cplusplus | #ifdef __cplusplus | |||
} | } | |||
#endif | #endif | |||
#endif | #endif | |||
End of changes. 8 change blocks. | ||||
27 lines changed or deleted | 89 lines changed or added | |||
blowfishopt.h | blowfishopt.h | |||
---|---|---|---|---|
/* | /* | |||
* blowfishopt.h | * Copyright (c) 2000, 2002, 2003 Virtual Unlimited B.V. | |||
* | ||||
* Blowfish block cipher assembler-optimized routines, header | ||||
* | ||||
* Copyright (c) 2000 Virtual Unlimited B.V. | ||||
* | ||||
* Author: Bob Deblier <bob@virtualunlimited.com> | ||||
* | * | |||
* This library is free software; you can redistribute it and/or | * This library is free software; you can redistribute it and/or | |||
* modify it under the terms of the GNU Lesser General Public | * modify it under the terms of the GNU Lesser General Public | |||
* License as published by the Free Software Foundation; either | * License as published by the Free Software Foundation; either | |||
* version 2.1 of the License, or (at your option) any later version. | * version 2.1 of the License, or (at your option) any later version. | |||
* | * | |||
* This library is distributed in the hope that it will be useful, | * This library is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
* Lesser General Public License for more details. | * Lesser General Public License for more details. | |||
* | * | |||
* You should have received a copy of the GNU Lesser General Public | * You should have received a copy of the GNU Lesser General Public | |||
* License along with this library; if not, write to the Free Software | * License along with this library; if not, write to the Free Software | |||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 US A | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 US A | |||
* | * | |||
*/ | */ | |||
/*!\file blowfishopt.h | ||||
* \brief Blowfish block cipher, assembler-optimized routines, headers. | ||||
* \author Bob Deblier <bob.deblier@pandora.be> | ||||
* \ingroup BC_blowfish_m | ||||
*/ | ||||
#ifndef _BLOWFISHOPT_H | #ifndef _BLOWFISHOPT_H | |||
#define _BLOWFISHOPT_H | #define _BLOWFISHOPT_H | |||
#include "beecrypt.h" | #include "beecrypt.h" | |||
#include "blowfish.h" | #include "blowfish.h" | |||
#ifdef __cplusplus | #ifdef __cplusplus | |||
extern "C" { | extern "C" { | |||
#endif | #endif | |||
skipping to change at line 51 | skipping to change at line 51 | |||
# define ASM_BLOWFISHENCRYPT | # define ASM_BLOWFISHENCRYPT | |||
# define ASM_BLOWFISHDECRYPT | # define ASM_BLOWFISHDECRYPT | |||
# endif | # endif | |||
#endif | #endif | |||
#if defined(__GNUC__) | #if defined(__GNUC__) | |||
# if defined(OPTIMIZE_I586) || defined(OPTIMIZE_I686) | # if defined(OPTIMIZE_I586) || defined(OPTIMIZE_I686) | |||
# define ASM_BLOWFISHENCRYPT | # define ASM_BLOWFISHENCRYPT | |||
# define ASM_BLOWFISHDECRYPT | # define ASM_BLOWFISHDECRYPT | |||
# endif | # endif | |||
# if defined(OPTIMIZE_POWERPC) | ||||
# define ASM_BLOWFISHENCRYPT | ||||
# define ASM_BLOWFISHDECRYPT | ||||
# endif | ||||
#endif | #endif | |||
#if defined(__SUNPRO_C) || defined(__SUNPRO_CC) | #if defined(__IBMC__) | |||
#if defined(OPTIMIZE_I586) || defined(OPTIMIZE_I686) | # if defined(OPTIMIZE_POWERPC) | |||
#define ASM_BLOWFISHENCRYPT | # define ASM_BLOWFISHENCRYPT | |||
#define ASM_BLOWFISHDECRYPT | # define ASM_BLOWFISHDECRYPT | |||
# endif | ||||
#endif | ||||
#if defined(__INTEL_COMPILER) | ||||
# if defined(OPTIMIZE_I586) || defined(OPTIMIZE_I686) | ||||
# define ASM_BLOWFISHENCRYPT | ||||
# define ASM_BLOWFISHDECRYPT | ||||
# endif | ||||
#endif | #endif | |||
#if defined(__SUNPRO_C) || defined(__SUNPRO_CC) | ||||
/* nothing here yet */ | ||||
#endif | #endif | |||
#ifdef __cplusplus | #ifdef __cplusplus | |||
} | } | |||
#endif | #endif | |||
#endif | #endif | |||
End of changes. 5 change blocks. | ||||
11 lines changed or deleted | 26 lines changed or added | |||
dhaes.h | dhaes.h | |||
---|---|---|---|---|
/* | /* | |||
* dhaes.h | * Copyright (c) 2000, 2001, 2002 Virtual Unlimited, B.V. | |||
* | ||||
* DHAES, header | ||||
* | ||||
* Copyright (c) 2000, 2001 Virtual Unlimited, B.V. | ||||
* | ||||
* Author: Bob Deblier <bob@virtualunlimited.com> | ||||
* | * | |||
* This library is free software; you can redistribute it and/or | * This library is free software; you can redistribute it and/or | |||
* modify it under the terms of the GNU Lesser General Public | * modify it under the terms of the GNU Lesser General Public | |||
* License as published by the Free Software Foundation; either | * License as published by the Free Software Foundation; either | |||
* version 2.1 of the License, or (at your option) any later version. | * version 2.1 of the License, or (at your option) any later version. | |||
* | * | |||
* This library is distributed in the hope that it will be useful, | * This library is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
* Lesser General Public License for more details. | * Lesser General Public License for more details. | |||
* | * | |||
* You should have received a copy of the GNU Lesser General Public | * You should have received a copy of the GNU Lesser General Public | |||
* License along with this library; if not, write to the Free Software | * License along with this library; if not, write to the Free Software | |||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 US A | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 US A | |||
* | * | |||
*/ | */ | |||
/*!\file dhaes.h | ||||
* \brief DHAES encryption scheme. | ||||
* | ||||
* This code implements the encryption scheme from the paper: | ||||
* | ||||
* "DHAES: An Encryption Scheme Based on the Diffie-Hellman Problem" | ||||
* Michel Abdalla, Mihir Bellare, Phillip Rogaway | ||||
* September 1998 | ||||
* | ||||
* \author Bob Deblier <bob.deblier@pandora.be> | ||||
* \ingroup DL_m DL_dh_m | ||||
*/ | ||||
#ifndef _DHAES_H | #ifndef _DHAES_H | |||
#define _DHAES_H | #define _DHAES_H | |||
#include "beecrypt.h" | #include "beecrypt.h" | |||
#include "dldp.h" | #include "dldp.h" | |||
typedef struct | typedef struct | |||
{ | { | |||
const dldp_p* param; | const dldp_p* param; | |||
const hashFunction* hash; | const hashFunction* hash; | |||
const blockCipher* cipher; | const blockCipher* cipher; | |||
const keyedHashFunction* mac; | const keyedHashFunction* mac; | |||
int cipherkeybit | size_t cipherkeybits; | |||
s; | size_t mackeybits; | |||
int mackeybits; | ||||
} dhaes_pParameters; | } dhaes_pParameters; | |||
typedef struct | typedef struct | |||
{ | { | |||
dldp_p param; | dldp_p param; | |||
mp32number pub; | mpnumber pub; | |||
mp32number pri; | mpnumber pri; | |||
hashFunctionContext hash; | hashFunctionContext hash; | |||
blockCipherContext cipher; | blockCipherContext cipher; | |||
keyedHashFunctionContext mac; | keyedHashFunctionContext mac; | |||
int cipherkeybit | size_t cipherkeybits; | |||
s; | size_t mackeybits; | |||
int mackeybits; | ||||
} dhaes_pContext; | } dhaes_pContext; | |||
BEEDLLAPI | #ifdef __cplusplus | |||
extern "C" { | ||||
#endif | ||||
BEECRYPTAPI | ||||
int dhaes_pUsable(const dhaes_pParameters*); | int dhaes_pUsable(const dhaes_pParameters*); | |||
BEEDLLAPI | BEECRYPTAPI | |||
int dhaes_pContextInit (dhaes_pContext*, const dhaes_pParameters*); | int dhaes_pContextInit (dhaes_pContext*, const dhaes_pParameters*); | |||
BEEDLLAPI | BEECRYPTAPI | |||
int dhaes_pContextInitDecrypt(dhaes_pContext*, const dhaes_pParameters*, co | int dhaes_pContextInitDecrypt(dhaes_pContext*, const dhaes_pParameters*, co | |||
nst mp32number*); | nst mpnumber*); | |||
BEEDLLAPI | BEECRYPTAPI | |||
int dhaes_pContextInitEncrypt(dhaes_pContext*, const dhaes_pParameters*, co | int dhaes_pContextInitEncrypt(dhaes_pContext*, const dhaes_pParameters*, co | |||
nst mp32number*); | nst mpnumber*); | |||
BEEDLLAPI | BEECRYPTAPI | |||
int dhaes_pContextFree (dhaes_pContext*); | int dhaes_pContextFree (dhaes_pContext*); | |||
BEEDLLAPI | BEECRYPTAPI | |||
memchunk* dhaes_pContextEncrypt(dhaes_pContext*, mp32number*, m | memchunk* dhaes_pContextEncrypt(dhaes_pContext*, mpnumber*, mpn | |||
p32number*, const memchunk*, randomGeneratorContext*); | umber*, const memchunk*, randomGeneratorContext*); | |||
BEEDLLAPI | BEECRYPTAPI | |||
memchunk* dhaes_pContextDecrypt(dhaes_pContext*, const mp32number*, const m | memchunk* dhaes_pContextDecrypt(dhaes_pContext*, const mpnumber*, const mpn | |||
p32number*, const memchunk*); | umber*, const memchunk*); | |||
#ifdef __cplusplus | ||||
} | ||||
#endif | ||||
#endif | #endif | |||
End of changes. 9 change blocks. | ||||
30 lines changed or deleted | 43 lines changed or added | |||
dldp.h | dldp.h | |||
---|---|---|---|---|
/* | /* | |||
* dldp.h | * Copyright (c) 2000, 2001, 2002 Virtual Unlimited B.V. | |||
* | ||||
* Discrete Logarithm Domain Parameters, header | ||||
* | ||||
* <conformance statement for IEEE P1363 needed here> | ||||
* | ||||
* Copyright (c) 2000, 2001 Virtual Unlimited B.V. | ||||
* | ||||
* Author: Bob Deblier <bob@virtualunlimited.com> | ||||
* | * | |||
* This library is free software; you can redistribute it and/or | * This library is free software; you can redistribute it and/or | |||
* modify it under the terms of the GNU Lesser General Public | * modify it under the terms of the GNU Lesser General Public | |||
* License as published by the Free Software Foundation; either | * License as published by the Free Software Foundation; either | |||
* version 2.1 of the License, or (at your option) any later version. | * version 2.1 of the License, or (at your option) any later version. | |||
* | * | |||
* This library is distributed in the hope that it will be useful, | * This library is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
* Lesser General Public License for more details. | * Lesser General Public License for more details. | |||
* | * | |||
* You should have received a copy of the GNU Lesser General Public | * You should have received a copy of the GNU Lesser General Public | |||
* License along with this library; if not, write to the Free Software | * License along with this library; if not, write to the Free Software | |||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 US A | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 US A | |||
* | * | |||
*/ | */ | |||
/*!\file dldp.h | ||||
* \brief Discrete Logarithm domain parameters, headers. | ||||
* \author Bob Deblier <bob.deblier@pandora.be> | ||||
* \ingroup DL_m | ||||
*/ | ||||
#ifndef _DLDP_H | #ifndef _DLDP_H | |||
#define _DLDP_H | #define _DLDP_H | |||
#include "beecrypt.h" | #include "mpbarrett.h" | |||
#include "mp32barrett.h" | ||||
/* | /* | |||
* Discrete Logarithm Domain Parameters - Prime | * Discrete Logarithm Domain Parameters - Prime | |||
* | * | |||
* Standard definition where p = qr+1; in case where p=2q+1, r=2 | * Standard definition where p = qr+1; in case where p=2q+1, r=2 | |||
* | * | |||
* In IEEE P1363 naming is p = rk+1 | * In IEEE P1363 naming is p = rk+1 | |||
* | * | |||
* Hence, IEEE prime r = q and cofactor k = r | * Hence, IEEE prime r = q and cofactor k = r | |||
* | * | |||
* Make sure q is large enough to foil Pohlig-Hellman attacks | * Make sure q is large enough to foil Pohlig-Hellman attacks | |||
* See: "Handbook of Applied Cryptography", Chapter 3.6.4 | * See: "Handbook of Applied Cryptography", Chapter 3.6.4 | |||
* | * | |||
* g is either a generator of a subgroup of order q, or a generator of orde r | * g is either a generator of a subgroup of order q, or a generator of orde r | |||
* n = (p-1) | * n = (p-1) | |||
*/ | */ | |||
/*!\brief Discrete Logarithm Domain Parameters over a prime field. | ||||
* | ||||
* For the variables in this structure /f$p=qr+1/f$; if /f$p=2q+1 then r=2/ | ||||
f$. | ||||
* | ||||
* \ingroup DL_m | ||||
*/ | ||||
typedef struct | typedef struct | |||
{ | { | |||
mp32barrett p; | /*!\var p | |||
mp32barrett q; | * \brief The prime. | |||
mp32number r; | * | |||
mp32number g; | */ | |||
mp32barrett n; | mpbarrett p; | |||
/*!\var q | ||||
* \brief The cofactor. | ||||
* | ||||
* \f$q\f$ is a prime divisor of \f$p-1\f$. | ||||
*/ | ||||
mpbarrett q; | ||||
/*!\var r | ||||
* | ||||
* \f$p=qr+1\f$ | ||||
*/ | ||||
mpnumber r; | ||||
/*!\var g | ||||
* \brief The generator. | ||||
* | ||||
* \f$g\f$ is either a generator of \f$\mathds{Z}^{*}_p\f$, or a gen | ||||
erator | ||||
* of a cyclic subgroup \f$G\f$ of \f$\mathds{Z}^{*}_p\f$ of order \ | ||||
f$q\f$. | ||||
*/ | ||||
mpnumber g; | ||||
/*!\var n | ||||
* | ||||
* \f$n=p-1=qr\f$ | ||||
*/ | ||||
mpbarrett n; | ||||
} dldp_p; | } dldp_p; | |||
#ifdef __cplusplus | #ifdef __cplusplus | |||
extern "C" { | extern "C" { | |||
#endif | #endif | |||
/* | /* | |||
* Functions for setting up and copying | * Functions for setting up and copying | |||
*/ | */ | |||
BEEDLLAPI | BEECRYPTAPI | |||
int dldp_pInit(dldp_p*); | int dldp_pInit(dldp_p*); | |||
BEEDLLAPI | BEECRYPTAPI | |||
int dldp_pFree(dldp_p*); | int dldp_pFree(dldp_p*); | |||
BEEDLLAPI | BEECRYPTAPI | |||
int dldp_pCopy(dldp_p*, const dldp_p*); | int dldp_pCopy(dldp_p*, const dldp_p*); | |||
/* | /* | |||
* Functions for generating keys | * Functions for generating keys | |||
*/ | */ | |||
BEEDLLAPI | BEECRYPTAPI | |||
int dldp_pPrivate(const dldp_p*, randomGeneratorContext*, mp32number*); | int dldp_pPrivate(const dldp_p*, randomGeneratorContext*, mpnumber*); | |||
BEEDLLAPI | BEECRYPTAPI | |||
int dldp_pPublic (const dldp_p*, const mp32number*, mp32number*); | int dldp_pPublic (const dldp_p*, const mpnumber*, mpnumber*); | |||
BEEDLLAPI | BEECRYPTAPI | |||
int dldp_pPair (const dldp_p*, randomGeneratorContext*, mp32number*, mp32 | int dldp_pPair (const dldp_p*, randomGeneratorContext*, mpnumber*, mpnumb | |||
number*); | er*); | |||
/* | /* | |||
* Function for comparing domain parameters | * Function for comparing domain parameters | |||
*/ | */ | |||
BEEDLLAPI | BEECRYPTAPI | |||
int dldp_pEqual (const dldp_p*, const dldp_p*); | int dldp_pEqual (const dldp_p*, const dldp_p*); | |||
/* | /* | |||
* Functions for generating and validating dldp_pgoq variant domain paramet ers | * Functions for generating and validating dldp_pgoq variant domain paramet ers | |||
*/ | */ | |||
BEEDLLAPI | BEECRYPTAPI | |||
int dldp_pgoqMake (dldp_p*, randomGeneratorContext*, uint32, uint32, in | int dldp_pgoqMake (dldp_p*, randomGeneratorContext*, size_t, size_t, in | |||
t); | t); | |||
BEEDLLAPI | BEECRYPTAPI | |||
int dldp_pgoqMakeSafe (dldp_p*, randomGeneratorContext*, uint32); | int dldp_pgoqMakeSafe (dldp_p*, randomGeneratorContext*, size_t); | |||
BEEDLLAPI | BEECRYPTAPI | |||
int dldp_pgoqGenerator(dldp_p*, randomGeneratorContext*); | int dldp_pgoqGenerator(dldp_p*, randomGeneratorContext*); | |||
BEEDLLAPI | BEECRYPTAPI | |||
int dldp_pgoqValidate (const dldp_p*, randomGeneratorContext*, int); | int dldp_pgoqValidate (const dldp_p*, randomGeneratorContext*, int); | |||
/* | /* | |||
* Functions for generating and validating dldp_pgon variant domain paramet ers | * Functions for generating and validating dldp_pgon variant domain paramet ers | |||
*/ | */ | |||
BEEDLLAPI | BEECRYPTAPI | |||
int dldp_pgonMake (dldp_p*, randomGeneratorContext*, uint32, uint32); | int dldp_pgonMake (dldp_p*, randomGeneratorContext*, size_t, size_t); | |||
BEEDLLAPI | BEECRYPTAPI | |||
int dldp_pgonMakeSafe (dldp_p*, randomGeneratorContext*, uint32); | int dldp_pgonMakeSafe (dldp_p*, randomGeneratorContext*, size_t); | |||
BEEDLLAPI | BEECRYPTAPI | |||
int dldp_pgonGenerator(dldp_p*, randomGeneratorContext*); | int dldp_pgonGenerator(dldp_p*, randomGeneratorContext*); | |||
BEEDLLAPI | BEECRYPTAPI | |||
int dldp_pgonValidate (const dldp_p*, randomGeneratorContext*); | int dldp_pgonValidate (const dldp_p*, randomGeneratorContext*); | |||
#ifdef __cplusplus | #ifdef __cplusplus | |||
} | } | |||
#endif | #endif | |||
#endif | #endif | |||
End of changes. 14 change blocks. | ||||
42 lines changed or deleted | 70 lines changed or added | |||
dlkp.h | dlkp.h | |||
---|---|---|---|---|
/* | /* | |||
* dlkp.h | * Copyright (c) 2000, 2001, 2002 Virtual Unlimited B.V. | |||
* | ||||
* Discrete Logarithm Keypair, header | ||||
* | ||||
* <conformance statement for IEEE P1363 needed here> | ||||
* | ||||
* Copyright (c) 2000, 2001 Virtual Unlimited B.V. | ||||
* | ||||
* Author: Bob Deblier <bob@virtualunlimited.com> | ||||
* | * | |||
* This library is free software; you can redistribute it and/or | * This library is free software; you can redistribute it and/or | |||
* modify it under the terms of the GNU Lesser General Public | * modify it under the terms of the GNU Lesser General Public | |||
* License as published by the Free Software Foundation; either | * License as published by the Free Software Foundation; either | |||
* version 2.1 of the License, or (at your option) any later version. | * version 2.1 of the License, or (at your option) any later version. | |||
* | * | |||
* This library is distributed in the hope that it will be useful, | * This library is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
* Lesser General Public License for more details. | * Lesser General Public License for more details. | |||
* | * | |||
* You should have received a copy of the GNU Lesser General Public | * You should have received a copy of the GNU Lesser General Public | |||
* License along with this library; if not, write to the Free Software | * License along with this library; if not, write to the Free Software | |||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 US A | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 US A | |||
* | * | |||
*/ | */ | |||
/*!\file dlkp.h | ||||
* \brief Discrete Logarithm keypair, headers. | ||||
* \author Bob Deblier <bob.deblier@pandora.be> | ||||
* \ingroup DL_m | ||||
*/ | ||||
#ifndef _DLKP_H | #ifndef _DLKP_H | |||
#define _DLKP_H | #define _DLKP_H | |||
#include "dlpk.h" | #include "dlpk.h" | |||
/*!\ingroup DL_m | ||||
*/ | ||||
typedef struct | typedef struct | |||
{ | { | |||
dldp_p param; | dldp_p param; | |||
mp32number y; | mpnumber y; | |||
mp32number x; | mpnumber x; | |||
} dlkp_p; | } dlkp_p; | |||
#ifdef __cplusplus | #ifdef __cplusplus | |||
extern "C" { | extern "C" { | |||
#endif | #endif | |||
BEEDLLAPI | BEECRYPTAPI | |||
int dlkp_pPair(dlkp_p*, randomGeneratorContext*, const dldp_p*); | int dlkp_pPair(dlkp_p*, randomGeneratorContext*, const dldp_p*); | |||
BEEDLLAPI | BEECRYPTAPI | |||
int dlkp_pInit(dlkp_p*); | int dlkp_pInit(dlkp_p*); | |||
BEEDLLAPI | BEECRYPTAPI | |||
int dlkp_pFree(dlkp_p*); | int dlkp_pFree(dlkp_p*); | |||
BEEDLLAPI | BEECRYPTAPI | |||
int dlkp_pCopy(dlkp_p*, const dlkp_p*); | int dlkp_pCopy(dlkp_p*, const dlkp_p*); | |||
#ifdef __cplusplus | #ifdef __cplusplus | |||
} | } | |||
#endif | #endif | |||
#endif | #endif | |||
End of changes. 8 change blocks. | ||||
15 lines changed or deleted | 15 lines changed or added | |||
dlpk.h | dlpk.h | |||
---|---|---|---|---|
/* | /* | |||
* dlpk.h | * Copyright (c) 2000, 2002 Virtual Unlimited B.V. | |||
* | ||||
* Discrete Logarithm Public Key, header | ||||
* | ||||
* Copyright (c) 2000 Virtual Unlimited B.V. | ||||
* | ||||
* Author: Bob Deblier <bob@virtualunlimited.com> | ||||
* | * | |||
* This library is free software; you can redistribute it and/or | * This library is free software; you can redistribute it and/or | |||
* modify it under the terms of the GNU Lesser General Public | * modify it under the terms of the GNU Lesser General Public | |||
* License as published by the Free Software Foundation; either | * License as published by the Free Software Foundation; either | |||
* version 2.1 of the License, or (at your option) any later version. | * version 2.1 of the License, or (at your option) any later version. | |||
* | * | |||
* This library is distributed in the hope that it will be useful, | * This library is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
* Lesser General Public License for more details. | * Lesser General Public License for more details. | |||
* | * | |||
* You should have received a copy of the GNU Lesser General Public | * You should have received a copy of the GNU Lesser General Public | |||
* License along with this library; if not, write to the Free Software | * License along with this library; if not, write to the Free Software | |||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 US A | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 US A | |||
* | * | |||
*/ | */ | |||
/*!\file dlpk.h | ||||
* \brief Discrete Logarithm public key, headers. | ||||
* \author Bob Deblier <bob.deblier@pandora.be> | ||||
* \ingroup DL_m | ||||
*/ | ||||
#ifndef _DLPK_H | #ifndef _DLPK_H | |||
#define _DLPK_H | #define _DLPK_H | |||
#include "dldp.h" | #include "dldp.h" | |||
/*!\ingroup DL_m | ||||
*/ | ||||
typedef struct | typedef struct | |||
{ | { | |||
dldp_p param; | dldp_p param; | |||
mp32number y; | mpnumber y; | |||
} dlpk_p; | } dlpk_p; | |||
#ifdef __cplusplus | #ifdef __cplusplus | |||
extern "C" { | extern "C" { | |||
#endif | #endif | |||
BEEDLLAPI | BEECRYPTAPI | |||
int dlpk_pInit(dlpk_p*); | int dlpk_pInit(dlpk_p*); | |||
BEEDLLAPI | BEECRYPTAPI | |||
int dlpk_pFree(dlpk_p*); | int dlpk_pFree(dlpk_p*); | |||
BEEDLLAPI | BEECRYPTAPI | |||
int dlpk_pCopy(dlpk_p*, const dlpk_p*); | int dlpk_pCopy(dlpk_p*, const dlpk_p*); | |||
BEEDLLAPI | BEECRYPTAPI | |||
int dlpk_pEqual(const dlpk_p*, const dlpk_p*); | int dlpk_pEqual(const dlpk_p*, const dlpk_p*); | |||
BEEDLLAPI | BEECRYPTAPI | |||
int dlpk_pgoqValidate(const dlpk_p*, randomGeneratorContext*, int cofactor ); | int dlpk_pgoqValidate(const dlpk_p*, randomGeneratorContext*, int cofactor ); | |||
BEEDLLAPI | BEECRYPTAPI | |||
int dlpk_pgonValidate(const dlpk_p*, randomGeneratorContext*); | int dlpk_pgonValidate(const dlpk_p*, randomGeneratorContext*); | |||
#ifdef __cplusplus | #ifdef __cplusplus | |||
} | } | |||
#endif | #endif | |||
#endif | #endif | |||
End of changes. 10 change blocks. | ||||
14 lines changed or deleted | 16 lines changed or added | |||
dlsvdp-dh.h | dlsvdp-dh.h | |||
---|---|---|---|---|
/* | /* | |||
* dlsvdp-dh.h | * Copyright (c) 2000, 2002 Virtual Unlimited B.V. | |||
* | ||||
* Discrete Logarithm Secret Value Derivation Primitive - Diffie Hellman, h | ||||
eader | ||||
* | ||||
* Copyright (c) 2000 Virtual Unlimited B.V. | ||||
* | ||||
* Author: Bob Deblier <bob@virtualunlimited.com> | ||||
* | * | |||
* This library is free software; you can redistribute it and/or | * This library is free software; you can redistribute it and/or | |||
* modify it under the terms of the GNU Lesser General Public | * modify it under the terms of the GNU Lesser General Public | |||
* License as published by the Free Software Foundation; either | * License as published by the Free Software Foundation; either | |||
* version 2.1 of the License, or (at your option) any later version. | * version 2.1 of the License, or (at your option) any later version. | |||
* | * | |||
* This library is distributed in the hope that it will be useful, | * This library is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
* Lesser General Public License for more details. | * Lesser General Public License for more details. | |||
* | * | |||
* You should have received a copy of the GNU Lesser General Public | * You should have received a copy of the GNU Lesser General Public | |||
* License along with this library; if not, write to the Free Software | * License along with this library; if not, write to the Free Software | |||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 US A | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 US A | |||
* | * | |||
*/ | */ | |||
/*!\file dlsvdp-dh.h | ||||
* \brief Diffie-Hellman algorithm, headers. | ||||
* \author Bob Deblier <bob.deblier@pandora.be> | ||||
* \ingroup DL_m DL_dh_m | ||||
*/ | ||||
#ifndef _DLSVDP_DH_H | #ifndef _DLSVDP_DH_H | |||
#define _DLSVDP_DH_H | #define _DLSVDP_DH_H | |||
#include "dldp.h" | #include "dldp.h" | |||
#ifdef __cplusplus | #ifdef __cplusplus | |||
extern "C" { | extern "C" { | |||
#endif | #endif | |||
BEEDLLAPI | BEECRYPTAPI | |||
int dlsvdp_pDHSecret(const dldp_p*, const mp32number*, const mp32number*, m | int dlsvdp_pDHSecret(const dldp_p*, const mpnumber*, const mpnumber*, mpnum | |||
p32number*); | ber*); | |||
#ifdef __cplusplus | #ifdef __cplusplus | |||
} | } | |||
#endif | #endif | |||
#endif | #endif | |||
End of changes. 3 change blocks. | ||||
11 lines changed or deleted | 10 lines changed or added | |||
elgamal.h | elgamal.h | |||
---|---|---|---|---|
/* | /* | |||
* elgamal.h | * Copyright (c) 2000, 2001, 2002 Virtual Unlimited B.V. | |||
* | ||||
* ElGamal signature scheme, header | ||||
* | ||||
* Copyright (c) 2000, 2001 Virtual Unlimited B.V. | ||||
* | ||||
* Author: Bob Deblier <bob@virtualunlimited.com> | ||||
* | * | |||
* This library is free software; you can redistribute it and/or | * This library is free software; you can redistribute it and/or | |||
* modify it under the terms of the GNU Lesser General Public | * modify it under the terms of the GNU Lesser General Public | |||
* License as published by the Free Software Foundation; either | * License as published by the Free Software Foundation; either | |||
* version 2.1 of the License, or (at your option) any later version. | * version 2.1 of the License, or (at your option) any later version. | |||
* | * | |||
* This library is distributed in the hope that it will be useful, | * This library is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
* Lesser General Public License for more details. | * Lesser General Public License for more details. | |||
* | * | |||
* You should have received a copy of the GNU Lesser General Public | * You should have received a copy of the GNU Lesser General Public | |||
* License along with this library; if not, write to the Free Software | * License along with this library; if not, write to the Free Software | |||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 US A | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 US A | |||
* | * | |||
*/ | */ | |||
/*!\file elgamal.h | ||||
* \brief ElGamal algorithm. | ||||
* | ||||
* For more information on this algorithm, see: | ||||
* "Handbook of Applied Cryptography", | ||||
* 11.5.2: "The ElGamal signature scheme", p. 454-459 | ||||
* | ||||
* Two of the signature variants in Note 11.70 are implemented. | ||||
* | ||||
* \todo Implement ElGamal encryption and decryption. | ||||
* | ||||
* \todo Explore the possibility of using simultaneous multiple exponentiat | ||||
ion, | ||||
* as described in HAC, 14.87 (iii). | ||||
* | ||||
* \author Bob Deblier <bob.deblier@pandora.be> | ||||
* \ingroup DL_m DL_elgamal_m | ||||
*/ | ||||
#ifndef _ELGAMAL_H | #ifndef _ELGAMAL_H | |||
#define _ELGAMAL_H | #define _ELGAMAL_H | |||
#include "mp32barrett.h" | #include "mpbarrett.h" | |||
#ifdef __cplusplus | #ifdef __cplusplus | |||
extern "C" { | extern "C" { | |||
#endif | #endif | |||
BEEDLLAPI | /*!\fn int elgv1sign(const mpbarrett* p, const mpbarrett* n, const mpnumber | |||
int elgv1sign(const mp32barrett* p, const mp32barrett* n, const mp32number* | * g, | |||
g, randomGeneratorContext*, const mp32number* hm, const mp32number* x, mp3 | randomGeneratorContext* rgc, const mpnumber* hm, const mpnumber* x, mpnumbe | |||
2number* r, mp32number* s); | r* r, | |||
BEEDLLAPI | mpnumber* s) | |||
int elgv3sign(const mp32barrett* p, const mp32barrett* n, const mp32number* | * \brief This function performs raw ElGamal signing, variant 1. | |||
g, randomGeneratorContext*, const mp32number* hm, const mp32number* x, mp3 | * | |||
2number* r, mp32number* s); | * Signing equations: | |||
* | ||||
* \li \f$r=g^{k}\ \textrm{mod}\ p\f$ | ||||
* \li \f$s=k^{-1}(h(m)-xr)\ \textrm{mod}\ (p-1)\f$ | ||||
* | ||||
* \param p The prime. | ||||
* \param n The reducer mod (p-1). | ||||
* \param g The generator. | ||||
* \param rgc The pseudo-random generat | ||||
* \param hm The hash to be signed. | ||||
* \param x The private key value. | ||||
* \param r The signature's \e r value. | ||||
* \param s The signature's \e s value. | ||||
* \retval 0 on success. | ||||
* \retval -1 on failure. | ||||
*/ | ||||
BEECRYPTAPI | ||||
int elgv1sign(const mpbarrett* p, const mpbarrett* n, const mpnumber* g, ra | ||||
ndomGeneratorContext*, const mpnumber* hm, const mpnumber* x, mpnumber* r, | ||||
mpnumber* s); | ||||
BEEDLLAPI | /*!\fn int elgv1vrfy(const mpbarrett* p, const mpbarrett* n, const mpnumber | |||
int elgv1vrfy(const mp32barrett* p, const mp32barrett* n, const mp32number* | * g, const mpnumber* hm, const mpnumber* y, const mpnumber* r, const mpnumb | |||
g, const mp32number* hm, const mp32number* y, const mp32number* r, const m | er* s) | |||
p32number* s); | * \brief This function performs raw ElGamal verification, variant 1. | |||
BEEDLLAPI | * | |||
int elgv3vrfy(const mp32barrett* p, const mp32barrett* n, const mp32number* | * Verifying equations: | |||
g, const mp32number* hm, const mp32number* y, const mp32number* r, const m | * | |||
p32number* s); | * \li Check \f$0<r<p\f$ and \f$0<s<(p-1)\f$ | |||
* \li \f$v_1=y^{r}r^{s}\ \textrm{mod}\ p\f$ | ||||
* \li \f$v_2=g^{h(m)}\ \textrm{mod}\ p\f$ | ||||
* \li Check \f$v_1=v_2\f$ | ||||
* | ||||
* \param p The prime. | ||||
* \param n The reducer mod (p-1). | ||||
* \param g The generator. | ||||
* \param hm The hash to be signed. | ||||
* \param y The public key value. | ||||
* \param r The signature's \e r value. | ||||
* \param s The signature's \e s value. | ||||
* \retval 1 on success. | ||||
* \retval 0 on failure. | ||||
*/ | ||||
BEECRYPTAPI | ||||
int elgv3sign(const mpbarrett* p, const mpbarrett* n, const mpnumber* g, ra | ||||
ndomGeneratorContext*, const mpnumber* hm, const mpnumber* x, mpnumber* r, | ||||
mpnumber* s); | ||||
/*!\fn int elgv3sign(const mpbarrett* p, const mpbarrett* n, const mpnumber | ||||
* g, randomGeneratorContext* rgc, const mpnumber* hm, const mpnumber* x, mp | ||||
number* r, mpnumber* s) | ||||
* \brief This function performs raw ElGamal signing, variant 3. | ||||
* | ||||
* Signing equations: | ||||
* | ||||
* \li \f$r=g^{k}\ \textrm{mod}\ p\f$ | ||||
* \li \f$s=xr+kh(m)\ \textrm{mod}\ (p-1)\f$ | ||||
* | ||||
* \param p The prime. | ||||
* \param n The reducer mod (p-1). | ||||
* \param g The generator. | ||||
* \param rgc The pseudo-random generat | ||||
* \param hm The hash to be signed. | ||||
* \param x The private key value. | ||||
* \param r The signature's \e r value. | ||||
* \param s The signature's \e s value. | ||||
* \retval 0 on success. | ||||
* \retval -1 on failure. | ||||
*/ | ||||
BEECRYPTAPI | ||||
int elgv1vrfy(const mpbarrett* p, const mpbarrett* n, const mpnumber* g, co | ||||
nst mpnumber* hm, const mpnumber* y, const mpnumber* r, const mpnumber* s); | ||||
/*!\fn int elgv3vrfy(const mpbarrett* p, const mpbarrett* n, const mpnumber | ||||
* g, const mpnumber* hm, const mpnumber* y, const mpnumber* r, const mpnumb | ||||
er* s) | ||||
* \brief This function performs raw ElGamal verification, variant 3. | ||||
* | ||||
* Verifying equations: | ||||
* | ||||
* \li Check \f$0<r<p\f$ and \f$0<s<(p-1)\f$ | ||||
* \li \f$v_1=g^{s}\ \textrm{mod}\ p\f$ | ||||
* \li \f$v_2=y^{r}r^{h(m)}\ \textrm{mod}\ p\f$ | ||||
* \li Check \f$v_1=v_2\f$ | ||||
* | ||||
* \param p The prime. | ||||
* \param n The reducer mod (p-1). | ||||
* \param g The generator. | ||||
* \param hm The hash to be signed. | ||||
* \param y The public key value. | ||||
* \param r The signature's \e r value. | ||||
* \param s The signature's \e s value. | ||||
* \retval 1 on success. | ||||
* \retval 0 on failure. | ||||
*/ | ||||
BEECRYPTAPI | ||||
int elgv3vrfy(const mpbarrett* p, const mpbarrett* n, const mpnumber* g, co | ||||
nst mpnumber* hm, const mpnumber* y, const mpnumber* r, const mpnumber* s); | ||||
#ifdef __cplusplus | #ifdef __cplusplus | |||
} | } | |||
#endif | #endif | |||
#endif | #endif | |||
End of changes. 5 change blocks. | ||||
24 lines changed or deleted | 125 lines changed or added | |||
endianness.h | endianness.h | |||
---|---|---|---|---|
skipping to change at line 31 | skipping to change at line 31 | |||
* License along with this library; if not, write to the Free Software | * License along with this library; if not, write to the Free Software | |||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 US A | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 US A | |||
* | * | |||
*/ | */ | |||
#ifndef _ENDIANNESS_H | #ifndef _ENDIANNESS_H | |||
#define _ENDIANNESS_H | #define _ENDIANNESS_H | |||
#include "beecrypt.h" | #include "beecrypt.h" | |||
#include <stdio.h> | ||||
#ifdef __cplusplus | #ifdef __cplusplus | |||
inline int16 swap16(int16 n) | inline int16_t swap16(int16_t n) | |||
{ | { | |||
return ( ((n & 0xff) << 8) | | return ( ((n & 0xff) << 8) | | |||
((n & 0xff00) >> 8) ); | ((n & 0xff00) >> 8) ); | |||
} | } | |||
inline uint16 swapu16(uint16 n) | inline uint16_t swapu16(uint16_t n) | |||
{ | { | |||
return ( ((n & 0xffU) << 8) | | return ( ((n & 0xffU) << 8) | | |||
((n & 0xff00U) >> 8) ); | ((n & 0xff00U) >> 8) ); | |||
} | } | |||
inline int32 swap32(int32 n) | inline int32_t swap32(int32_t n) | |||
{ | { | |||
#if (SIZEOF_LONG == 4) | ||||
return ( ((n & 0xff) << 24) | | return ( ((n & 0xff) << 24) | | |||
((n & 0xff00) << 8) | | ((n & 0xff00) << 8) | | |||
((n & 0xff0000) >> 8) | | ((n & 0xff0000) >> 8) | | |||
((n & 0xff000000) >> 24) ); | ((n & 0xff000000) >> 24) ); | |||
#else | ||||
return ( ((n & 0xffL) << 24) | | ||||
((n & 0xff00L) << 8) | | ||||
((n & 0xff0000L) >> 8) | | ||||
((n & 0xff000000L) >> 24) ); | ||||
#endif | ||||
} | } | |||
inline uint32 swapu32(uint32 n) | inline uint32_t swapu32(uint32_t n) | |||
{ | { | |||
#if (SIZEOF_UNSIGNED_LONG == 4) | ||||
return ( ((n & 0xffU) << 24) | | return ( ((n & 0xffU) << 24) | | |||
((n & 0xff00U) << 8) | | ((n & 0xff00U) << 8) | | |||
((n & 0xff0000U) >> 8) | | ((n & 0xff0000U) >> 8) | | |||
((n & 0xff000000U) >> 24) ); | ((n & 0xff000000U) >> 24) ); | |||
#else | ||||
return ( ((n & 0xffUL) << 24) | | ||||
((n & 0xff00UL) << 8) | | ||||
((n & 0xff0000UL) >> 8) | | ||||
((n & 0xff000000UL) >> 24) ); | ||||
#endif | ||||
} | } | |||
inline int64 swap64(int64 n) | inline int64_t swap64(int64_t n) | |||
{ | { | |||
#if HAVE_LONG_LONG | return ( ((n & ((int64_t) 0xff) ) << 56) | | |||
return ( ((n & 0xffLL) << 56) | | ((n & ((int64_t) 0xff) << 8) << 40) | | |||
((n & 0xff00LL) << 40) | | ((n & ((int64_t) 0xff) << 16) << 24) | | |||
((n & 0xff0000LL) << 24) | | ((n & ((int64_t) 0xff) << 24) << 8) | | |||
((n & 0xff000000LL) << 8) | | ((n & ((int64_t) 0xff) << 32) >> 8) | | |||
((n & 0xff00000000LL) >> 8) | | ((n & ((int64_t) 0xff) << 40) >> 24) | | |||
((n & 0xff0000000000LL) >> 24) | | ((n & ((int64_t) 0xff) << 48) >> 40) | | |||
((n & 0xff000000000000LL) >> 40) | | ((n & ((int64_t) 0xff) << 56) >> 56) ); | |||
((n & 0xff00000000000000LL) >> 56) ); | ||||
#else | ||||
return ( ((n & 0xffL) << 56) | | ||||
((n & 0xff00L) << 40) | | ||||
((n & 0xff0000L) << 24) | | ||||
((n & 0xff000000L) << 8) | | ||||
((n & 0xff00000000L) >> 8) | | ||||
((n & 0xff0000000000L) >> 24) | | ||||
((n & 0xff000000000000L) >> 40) | | ||||
((n & 0xff00000000000000L) >> 56) ); | ||||
#endif | ||||
} | } | |||
#else | #else | |||
int16 swap16 (int16); | int16_t swap16 (int16_t); | |||
uint16 swapu16(uint16); | uint16_t swapu16(uint16_t); | |||
int32 swap32 (int32); | int32_t swap32 (int32_t); | |||
uint32 swapu32(uint32); | uint32_t swapu32(uint32_t); | |||
int64 swap64 (int64); | int64_t swap64 (int64_t); | |||
#endif | #endif | |||
#ifdef __cplusplus | #ifdef __cplusplus | |||
extern "C" { | extern "C" { | |||
#endif | #endif | |||
BEEDLLAPI | ||||
int encodeByte(javabyte, byte*); | ||||
BEEDLLAPI | ||||
int encodeShort(javashort, byte*); | ||||
BEEDLLAPI | ||||
int encodeInt(javaint, byte*); | ||||
BEEDLLAPI | ||||
int encodeLong(javalong, byte*); | ||||
BEEDLLAPI | ||||
int encodeChar(javachar, byte*); | ||||
BEEDLLAPI | ||||
int encodeFloat(javafloat, byte*); | ||||
BEEDLLAPI | ||||
int encodeDouble(javadouble, byte*); | ||||
BEEDLLAPI | ||||
int encodeInts(const javaint*, byte*, int); | ||||
BEEDLLAPI | ||||
int encodeIntsPartial(const javaint*, byte*, int); | ||||
BEEDLLAPI | ||||
int encodeChars(const javachar*, byte*, int); | ||||
BEEDLLAPI | ||||
int decodeByte(javabyte*, const byte*); | ||||
BEEDLLAPI | ||||
int decodeShort(javashort*, const byte*); | ||||
BEEDLLAPI | ||||
int decodeInt(javaint*, const byte*); | ||||
BEEDLLAPI | ||||
int decodeLong(javalong*, const byte*); | ||||
BEEDLLAPI | ||||
int decodeChar(javachar*, const byte*); | ||||
BEEDLLAPI | ||||
int decodeFloat(javafloat*, const byte*); | ||||
BEEDLLAPI | ||||
int decodeDouble(javadouble*, const byte*); | ||||
BEEDLLAPI | ||||
int decodeInts(javaint*, const byte*, int); | ||||
BEEDLLAPI | ||||
int decodeIntsPartial(javaint*, const byte*, int); | ||||
BEEDLLAPI | ||||
int decodeChars(javachar*, const byte*, int); | ||||
BEEDLLAPI | ||||
int writeByte(javabyte, FILE*); | ||||
BEEDLLAPI | ||||
int writeShort(javashort, FILE*); | ||||
BEEDLLAPI | ||||
int writeInt(javaint, FILE*); | ||||
BEEDLLAPI | ||||
int writeLong(javalong, FILE*); | ||||
BEEDLLAPI | ||||
int writeChar(javachar, FILE*); | ||||
BEEDLLAPI | ||||
int writeInts(const javaint*, FILE*, int); | ||||
BEEDLLAPI | ||||
int writeChars(const javachar*, FILE*, int); | ||||
BEEDLLAPI | ||||
int readByte(javabyte*, FILE*); | ||||
BEEDLLAPI | ||||
int readShort(javashort*, FILE*); | ||||
BEEDLLAPI | ||||
int readInt(javaint*, FILE*); | ||||
BEEDLLAPI | ||||
int readLong(javalong*, FILE*); | ||||
BEEDLLAPI | ||||
int readChar(javachar*, FILE*); | ||||
BEEDLLAPI | ||||
int readInts(javaint*, FILE*, int); | ||||
BEEDLLAPI | ||||
int readChars(javachar*, FILE*, int); | ||||
#ifdef __cplusplus | #ifdef __cplusplus | |||
} | } | |||
#endif | #endif | |||
#endif | #endif | |||
End of changes. 13 change blocks. | ||||
122 lines changed or deleted | 18 lines changed or added | |||
entropy.h | entropy.h | |||
---|---|---|---|---|
/* | /* | |||
* entropy.h | * Copyright (c) 1998, 1999, 2000, 2001, 2002 Virtual Unlimited B.V. | |||
* | ||||
* Entropy gathering routine(s) for pseudo-random generator initialization, | ||||
header | ||||
* | ||||
* Copyright (c) 1998, 1999, 2000, 2001 Virtual Unlimited B.V. | ||||
* | ||||
* Author: Bob Deblier <bob@virtualunlimited.com> | ||||
* | * | |||
* This library is free software; you can redistribute it and/or | * This library is free software; you can redistribute it and/or | |||
* modify it under the terms of the GNU Lesser General Public | * modify it under the terms of the GNU Lesser General Public | |||
* License as published by the Free Software Foundation; either | * License as published by the Free Software Foundation; either | |||
* version 2.1 of the License, or (at your option) any later version. | * version 2.1 of the License, or (at your option) any later version. | |||
* | * | |||
* This library is distributed in the hope that it will be useful, | * This library is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
* Lesser General Public License for more details. | * Lesser General Public License for more details. | |||
* | * | |||
* You should have received a copy of the GNU Lesser General Public | * You should have received a copy of the GNU Lesser General Public | |||
* License along with this library; if not, write to the Free Software | * License along with this library; if not, write to the Free Software | |||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 US A | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 US A | |||
* | * | |||
*/ | */ | |||
/*!\file entropy.h | ||||
* \brief Entropy sources, headers. | ||||
* \author Bob Deblier <bob.deblier@pandora.be> | ||||
* \ingroup ES_m ES_audio_m ES_dsp_m ES_random_m ES_urandom_m ES_tty_m | ||||
*/ | ||||
#ifndef _ENTROPY_H | #ifndef _ENTROPY_H | |||
#define _ENTROPY_H | #define _ENTROPY_H | |||
#include "beecrypt.h" | #include "beecrypt.h" | |||
#if WIN32 | #if WIN32 | |||
#include <Windows.h> | #include <Windows.h> | |||
#endif | #endif | |||
#ifdef __cplusplus | #ifdef __cplusplus | |||
extern "C" { | extern "C" { | |||
#endif | #endif | |||
#if WIN32 | #if WIN32 | |||
BEEDLLAPI | BEECRYPTAPI | |||
int entropy_provider_setup(HINSTANCE); | int entropy_provider_setup(HINSTANCE); | |||
BEEDLLAPI | BEECRYPTAPI | |||
int entropy_provider_cleanup(); | int entropy_provider_cleanup(); | |||
BEEDLLAPI | BEECRYPTAPI | |||
int entropy_wavein(uint32*, int); | int entropy_wavein(byte*, size_t); | |||
BEEDLLAPI | BEECRYPTAPI | |||
int entropy_console(uint32*, int); | int entropy_console(byte*, size_t); | |||
BEEDLLAPI | BEECRYPTAPI | |||
int entropy_wincrypt(uint32*, int); | int entropy_wincrypt(byte*, size_t); | |||
#else | #else | |||
#if HAVE_DEV_AUDIO | #if HAVE_DEV_AUDIO | |||
int entropy_dev_audio (uint32*, int); | int entropy_dev_audio (byte*, size_t); | |||
#endif | #endif | |||
#if HAVE_DEV_DSP | #if HAVE_DEV_DSP | |||
int entropy_dev_dsp (uint32*, int); | int entropy_dev_dsp (byte*, size_t); | |||
#endif | #endif | |||
#if HAVE_DEV_RANDOM | #if HAVE_DEV_RANDOM | |||
int entropy_dev_random(uint32*, int); | int entropy_dev_random (byte*, size_t); | |||
#endif | #endif | |||
#if HAVE_DEV_URANDOM | #if HAVE_DEV_URANDOM | |||
int entropy_dev_urandom(uint32*, int); | int entropy_dev_urandom(byte*, size_t); | |||
#endif | #endif | |||
#if HAVE_DEV_TTY | #if HAVE_DEV_TTY | |||
int entropy_dev_tty (uint32*, int); | int entropy_dev_tty (byte*, size_t); | |||
#endif | #endif | |||
#endif | #endif | |||
#ifdef __cplusplus | #ifdef __cplusplus | |||
} | } | |||
#endif | #endif | |||
#endif | #endif | |||
End of changes. 10 change blocks. | ||||
21 lines changed or deleted | 20 lines changed or added | |||
fips186.h | fips186.h | |||
---|---|---|---|---|
/* | /* | |||
* fips186.h | * Copyright (c) 1998, 1999, 2000, 2001, 2002 Virtual Unlimited B.V. | |||
* | ||||
* FIPS186 pseudo-random generator, with SHA-1 as H function, header | ||||
* | ||||
* Copyright (c) 1998, 1999, 2000, 2001 Virtual Unlimited B.V. | ||||
* | ||||
* Author: Bob Deblier <bob@virtualunlimited.com> | ||||
* | * | |||
* This library is free software; you can redistribute it and/or | * This library is free software; you can redistribute it and/or | |||
* modify it under the terms of the GNU Lesser General Public | * modify it under the terms of the GNU Lesser General Public | |||
* License as published by the Free Software Foundation; either | * License as published by the Free Software Foundation; either | |||
* version 2.1 of the License, or (at your option) any later version. | * version 2.1 of the License, or (at your option) any later version. | |||
* | * | |||
* This library is distributed in the hope that it will be useful, | * This library is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
* Lesser General Public License for more details. | * Lesser General Public License for more details. | |||
* | * | |||
* You should have received a copy of the GNU Lesser General Public | * You should have received a copy of the GNU Lesser General Public | |||
* License along with this library; if not, write to the Free Software | * License along with this library; if not, write to the Free Software | |||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 US A | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 US A | |||
* | * | |||
*/ | */ | |||
/*!\file fips186.h | ||||
* \brief FIPS-186 pseudo-random number generator, headers. | ||||
* \author Bob Deblier <bob.deblier@pandora.be> | ||||
* \ingroup PRNG_m PRNG_fips186_m | ||||
*/ | ||||
#ifndef _FIPS186_H | #ifndef _FIPS186_H | |||
#define _FIPS186_H | #define _FIPS186_H | |||
#include "beecrypt.h" | #include "beecrypt.h" | |||
#ifdef _REENTRANT | #ifdef _REENTRANT | |||
# if WIN32 | # if WIN32 | |||
# include <windows.h> | # include <windows.h> | |||
# include <winbase.h> | # include <winbase.h> | |||
# else | ||||
# if HAVE_SYNCH_H | ||||
# include <synch.h> | ||||
# elif HAVE_PTHREAD_H | ||||
# include <pthread.h> | ||||
# else | ||||
# error need locking mechanism | ||||
# endif | ||||
# endif | # endif | |||
#endif | #endif | |||
#include "beecrypt.h" | #include "beecrypt.h" | |||
#include "fips180.h" | #include "sha1.h" | |||
#define FIPS186_STATE_SIZE 16 | #if (MP_WBITS == 64) | |||
# define FIPS186_STATE_SIZE 8 | ||||
#elif (MP_WBITS == 32) | ||||
# define FIPS186_STATE_SIZE 16 | ||||
#else | ||||
# error | ||||
#endif | ||||
/*!\ingroup PRNG_fips186_m | ||||
*/ | ||||
typedef struct | typedef struct | |||
{ | { | |||
#ifdef _REENTRANT | #ifdef _REENTRANT | |||
# if WIN32 | # if WIN32 | |||
HANDLE lock; | HANDLE lock; | |||
# else | # else | |||
# if HAVE_SYNCH_H | bc_lock_t lock; | |||
mutex_t lock; | ||||
# elif HAVE_PTHREAD_H | ||||
pthread_mutex_t lock; | ||||
# else | ||||
# error need locking mechanism | ||||
# endif | ||||
# endif | # endif | |||
#endif | #endif | |||
sha1Param param; | sha1Param param; | |||
uint32 state[FIPS186_STATE_SIZE]; | mpw state[FIPS186_STATE_SIZE]; | |||
int digestsize; | byte digest[20]; | |||
unsigned char digestremain; | ||||
} fips186Param; | } fips186Param; | |||
#ifdef __cplusplus | #ifdef __cplusplus | |||
extern "C" { | extern "C" { | |||
#endif | #endif | |||
extern BEEDLLAPI const randomGenerator fips186prng; | extern BEECRYPTAPI const randomGenerator fips186prng; | |||
BEEDLLAPI | BEECRYPTAPI | |||
int fips186Setup (fips186Param*); | int fips186Setup (fips186Param*); | |||
BEEDLLAPI | BEECRYPTAPI | |||
int fips186Seed (fips186Param*, const uint32*, int); | int fips186Seed (fips186Param*, const byte*, size_t); | |||
BEEDLLAPI | BEECRYPTAPI | |||
int fips186Next (fips186Param*, uint32*, int); | int fips186Next (fips186Param*, byte*, size_t); | |||
BEEDLLAPI | BEECRYPTAPI | |||
int fips186Cleanup(fips186Param*); | int fips186Cleanup(fips186Param*); | |||
#ifdef __cplusplus | #ifdef __cplusplus | |||
} | } | |||
#endif | #endif | |||
#endif | #endif | |||
End of changes. 11 change blocks. | ||||
34 lines changed or deleted | 29 lines changed or added | |||
hmac.h | hmac.h | |||
---|---|---|---|---|
/* | /* | |||
* hmac.h | * Copyright (c) 1999, 2000, 2002 Virtual Unlimited B.V. | |||
* | ||||
* HMAC message authentication code, header | ||||
* | ||||
* Copyright (c) 1999, 2000 Virtual Unlimited B.V. | ||||
* | ||||
* Author: Bob Deblier <bob@virtualunlimited.com> | ||||
* | * | |||
* This library is free software; you can redistribute it and/or | * This library is free software; you can redistribute it and/or | |||
* modify it under the terms of the GNU Lesser General Public | * modify it under the terms of the GNU Lesser General Public | |||
* License as published by the Free Software Foundation; either | * License as published by the Free Software Foundation; either | |||
* version 2.1 of the License, or (at your option) any later version. | * version 2.1 of the License, or (at your option) any later version. | |||
* | * | |||
* This library is distributed in the hope that it will be useful, | * This library is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
* Lesser General Public License for more details. | * Lesser General Public License for more details. | |||
* | * | |||
* You should have received a copy of the GNU Lesser General Public | * You should have received a copy of the GNU Lesser General Public | |||
* License along with this library; if not, write to the Free Software | * License along with this library; if not, write to the Free Software | |||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 US A | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 US A | |||
* | * | |||
*/ | */ | |||
/*!\file hmac.h | ||||
* \brief HMAC algorithm, headers. | ||||
* \author Bob Deblier <bob.deblier@pandora.be> | ||||
* \ingroup HMAC_m | ||||
*/ | ||||
#ifndef _HMAC_H | #ifndef _HMAC_H | |||
#define _HMAC_H | #define _HMAC_H | |||
#include "beecrypt.h" | #include "beecrypt.h" | |||
typedef struct | /*!\ingroup HMAC_m | |||
{ | */ | |||
uint32 kxi[16]; | ||||
uint32 kxo[16]; | ||||
} hmacParam; | ||||
#ifdef __cplusplus | #ifdef __cplusplus | |||
extern "C" { | extern "C" { | |||
#endif | #endif | |||
/* not used directly as keyed hash function, but instead used as generic me thods */ | /* not used directly as keyed hash function, but instead used as generic me thods */ | |||
BEEDLLAPI | BEECRYPTAPI | |||
int hmacSetup (hmacParam*, const hashFunction*, hashFunctionParam*, const u | int hmacSetup ( byte*, byte*, const hashFunction*, hashFunctionP | |||
int32*, int); | aram*, const byte*, size_t); | |||
BEEDLLAPI | BEECRYPTAPI | |||
int hmacReset (hmacParam*, const hashFunction*, hashFunctionParam*); | int hmacReset (const byte*, const hashFunction*, hashFunctionP | |||
BEEDLLAPI | aram*); | |||
int hmacUpdate(hmacParam*, const hashFunction*, hashFunctionParam*, const b | BEECRYPTAPI | |||
yte*, int); | int hmacUpdate( const hashFunction*, hashFunctionP | |||
BEEDLLAPI | aram*, const byte*, size_t); | |||
int hmacDigest(hmacParam*, const hashFunction*, hashFunctionParam*, uint32* | BEECRYPTAPI | |||
); | int hmacDigest( const byte*, const hashFunction*, hashFunctionP | |||
aram*, byte*); | ||||
#ifdef __cplusplus | #ifdef __cplusplus | |||
} | } | |||
#endif | #endif | |||
#endif | #endif | |||
End of changes. 4 change blocks. | ||||
23 lines changed or deleted | 21 lines changed or added | |||
hmacmd5.h | hmacmd5.h | |||
---|---|---|---|---|
/* | /* | |||
* hmacmd5.h | * Copyright (c) 2000, 2001, 2002 Virtual Unlimited B.V. | |||
* | ||||
* HMAC-MD5 message authentication code, header | ||||
* | ||||
* Copyright (c) 2000, 2001 Virtual Unlimited B.V. | ||||
* | ||||
* Author: Bob Deblier <bob@virtualunlimited.com> | ||||
* | * | |||
* This library is free software; you can redistribute it and/or | * This library is free software; you can redistribute it and/or | |||
* modify it under the terms of the GNU Lesser General Public | * modify it under the terms of the GNU Lesser General Public | |||
* License as published by the Free Software Foundation; either | * License as published by the Free Software Foundation; either | |||
* version 2.1 of the License, or (at your option) any later version. | * version 2.1 of the License, or (at your option) any later version. | |||
* | * | |||
* This library is distributed in the hope that it will be useful, | * This library is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
* Lesser General Public License for more details. | * Lesser General Public License for more details. | |||
* | * | |||
* You should have received a copy of the GNU Lesser General Public | * You should have received a copy of the GNU Lesser General Public | |||
* License along with this library; if not, write to the Free Software | * License along with this library; if not, write to the Free Software | |||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 US A | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 US A | |||
* | * | |||
*/ | */ | |||
/*!\file hmacmd5.h | ||||
* \brief HMAC-MD5 message authentication code, headers. | ||||
* \author Bob Deblier <bob.deblier@pandora.be> | ||||
* \ingroup HMAC_m HMAC_md5_m | ||||
*/ | ||||
#ifndef _HMACMD5_H | #ifndef _HMACMD5_H | |||
#define _HMACMD5_H | #define _HMACMD5_H | |||
#include "hmac.h" | #include "hmac.h" | |||
#include "md5.h" | #include "md5.h" | |||
/*!\ingroup HMAC_md5_m | ||||
*/ | ||||
typedef struct | typedef struct | |||
{ | { | |||
md5Param mparam; | ||||
byte kxi[64]; | byte kxi[64]; | |||
byte kxo[64]; | byte kxo[64]; | |||
md5Param param; | ||||
} hmacmd5Param; | } hmacmd5Param; | |||
#ifdef __cplusplus | #ifdef __cplusplus | |||
extern "C" { | extern "C" { | |||
#endif | #endif | |||
extern BEEDLLAPI const keyedHashFunction hmacmd5; | extern BEECRYPTAPI const keyedHashFunction hmacmd5; | |||
BEEDLLAPI | BEECRYPTAPI | |||
int hmacmd5Setup (hmacmd5Param*, const uint32*, int); | int hmacmd5Setup (hmacmd5Param*, const byte*, size_t); | |||
BEEDLLAPI | BEECRYPTAPI | |||
int hmacmd5Reset (hmacmd5Param*); | int hmacmd5Reset (hmacmd5Param*); | |||
BEEDLLAPI | BEECRYPTAPI | |||
int hmacmd5Update(hmacmd5Param*, const byte*, int); | int hmacmd5Update(hmacmd5Param*, const byte*, size_t); | |||
BEEDLLAPI | BEECRYPTAPI | |||
int hmacmd5Digest(hmacmd5Param*, uint32*); | int hmacmd5Digest(hmacmd5Param*, byte*); | |||
#ifdef __cplusplus | #ifdef __cplusplus | |||
} | } | |||
#endif | #endif | |||
#endif | #endif | |||
End of changes. 8 change blocks. | ||||
16 lines changed or deleted | 18 lines changed or added | |||
hmacsha1.h | hmacsha1.h | |||
---|---|---|---|---|
/* | /* | |||
* hmacsha1.h | * Copyright (c) 1999, 2000, 2001, 2002 Virtual Unlimited B.V. | |||
* | ||||
* HMAC-SHA-1 message authentication code, header | ||||
* | ||||
* Copyright (c) 1999, 2000, 2001 Virtual Unlimited B.V. | ||||
* | ||||
* Author: Bob Deblier <bob@virtualunlimited.com> | ||||
* | * | |||
* This library is free software; you can redistribute it and/or | * This library is free software; you can redistribute it and/or | |||
* modify it under the terms of the GNU Lesser General Public | * modify it under the terms of the GNU Lesser General Public | |||
* License as published by the Free Software Foundation; either | * License as published by the Free Software Foundation; either | |||
* version 2.1 of the License, or (at your option) any later version. | * version 2.1 of the License, or (at your option) any later version. | |||
* | * | |||
* This library is distributed in the hope that it will be useful, | * This library is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
* Lesser General Public License for more details. | * Lesser General Public License for more details. | |||
* | * | |||
* You should have received a copy of the GNU Lesser General Public | * You should have received a copy of the GNU Lesser General Public | |||
* License along with this library; if not, write to the Free Software | * License along with this library; if not, write to the Free Software | |||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 US A | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 US A | |||
* | * | |||
*/ | */ | |||
/*!\file hmacsha1.h | ||||
* \brief HMAC-SHA-1 message authentication code, headers. | ||||
* \author Bob Deblier <bob.deblier@pandora.be> | ||||
* \ingroup HMAC_m HMAC_sha1_m | ||||
*/ | ||||
#ifndef _HMACSHA1_H | #ifndef _HMACSHA1_H | |||
#define _HMACSHA1_H | #define _HMACSHA1_H | |||
#include "hmac.h" | #include "hmac.h" | |||
#include "fips180.h" | #include "sha1.h" | |||
/*!\ingroup HMAC_sha1_m | ||||
*/ | ||||
typedef struct | typedef struct | |||
{ | { | |||
sha1Param sparam; | ||||
byte kxi[64]; | byte kxi[64]; | |||
byte kxo[64]; | byte kxo[64]; | |||
sha1Param param; | ||||
} hmacsha1Param; | } hmacsha1Param; | |||
#ifdef __cplusplus | #ifdef __cplusplus | |||
extern "C" { | extern "C" { | |||
#endif | #endif | |||
extern BEEDLLAPI const keyedHashFunction hmacsha1; | extern BEECRYPTAPI const keyedHashFunction hmacsha1; | |||
BEEDLLAPI | BEECRYPTAPI | |||
int hmacsha1Setup (hmacsha1Param*, const uint32*, int); | int hmacsha1Setup (hmacsha1Param*, const byte*, size_t); | |||
BEEDLLAPI | BEECRYPTAPI | |||
int hmacsha1Reset (hmacsha1Param*); | int hmacsha1Reset (hmacsha1Param*); | |||
BEEDLLAPI | BEECRYPTAPI | |||
int hmacsha1Update(hmacsha1Param*, const byte*, int); | int hmacsha1Update(hmacsha1Param*, const byte*, size_t); | |||
BEEDLLAPI | BEECRYPTAPI | |||
int hmacsha1Digest(hmacsha1Param*, uint32*); | int hmacsha1Digest(hmacsha1Param*, byte*); | |||
#ifdef __cplusplus | #ifdef __cplusplus | |||
} | } | |||
#endif | #endif | |||
#endif | #endif | |||
End of changes. 9 change blocks. | ||||
17 lines changed or deleted | 19 lines changed or added | |||
hmacsha256.h | hmacsha256.h | |||
---|---|---|---|---|
/* | /* | |||
* hmacsha256.h | * Copyright (c) 2000, 2001, 2002 Virtual Unlimited B.V. | |||
* | ||||
* HMAC-SHA-256 message authentication code, header | ||||
* | ||||
* Copyright (c) 2000, 2001 Virtual Unlimited B.V. | ||||
* | ||||
* Author: Bob Deblier <bob@virtualunlimited.com> | ||||
* | * | |||
* This library is free software; you can redistribute it and/or | * This library is free software; you can redistribute it and/or | |||
* modify it under the terms of the GNU Lesser General Public | * modify it under the terms of the GNU Lesser General Public | |||
* License as published by the Free Software Foundation; either | * License as published by the Free Software Foundation; either | |||
* version 2.1 of the License, or (at your option) any later version. | * version 2.1 of the License, or (at your option) any later version. | |||
* | * | |||
* This library is distributed in the hope that it will be useful, | * This library is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
* Lesser General Public License for more details. | * Lesser General Public License for more details. | |||
* | * | |||
* You should have received a copy of the GNU Lesser General Public | * You should have received a copy of the GNU Lesser General Public | |||
* License along with this library; if not, write to the Free Software | * License along with this library; if not, write to the Free Software | |||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 US A | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 US A | |||
* | * | |||
*/ | */ | |||
/*!\file hmacsha256.h | ||||
* \brief HMAC-SHA-256 message authentication code, headers. | ||||
* \author Bob Deblier <bob.deblier@pandora.be> | ||||
* \ingroup HMAC_m HMAC_sha256_m | ||||
*/ | ||||
#ifndef _HMACSHA256_H | #ifndef _HMACSHA256_H | |||
#define _HMACSHA256_H | #define _HMACSHA256_H | |||
#include "hmac.h" | #include "hmac.h" | |||
#include "sha256.h" | #include "sha256.h" | |||
/*!\ingroup HMAC_sha256_m | ||||
*/ | ||||
typedef struct | typedef struct | |||
{ | { | |||
sha256Param sparam; | ||||
byte kxi[64]; | byte kxi[64]; | |||
byte kxo[64]; | byte kxo[64]; | |||
sha256Param param; | ||||
} hmacsha256Param; | } hmacsha256Param; | |||
#ifdef __cplusplus | #ifdef __cplusplus | |||
extern "C" { | extern "C" { | |||
#endif | #endif | |||
extern BEEDLLAPI const keyedHashFunction hmacsha256; | extern BEECRYPTAPI const keyedHashFunction hmacsha256; | |||
BEEDLLAPI | BEECRYPTAPI | |||
int hmacsha256Setup (hmacsha256Param*, const uint32*, int); | int hmacsha256Setup (hmacsha256Param*, const byte*, size_t); | |||
BEEDLLAPI | BEECRYPTAPI | |||
int hmacsha256Reset (hmacsha256Param*); | int hmacsha256Reset (hmacsha256Param*); | |||
BEEDLLAPI | BEECRYPTAPI | |||
int hmacsha256Update(hmacsha256Param*, const byte*, int); | int hmacsha256Update(hmacsha256Param*, const byte*, size_t); | |||
BEEDLLAPI | BEECRYPTAPI | |||
int hmacsha256Digest(hmacsha256Param*, uint32*); | int hmacsha256Digest(hmacsha256Param*, byte*); | |||
#ifdef __cplusplus | #ifdef __cplusplus | |||
} | } | |||
#endif | #endif | |||
#endif | #endif | |||
End of changes. 8 change blocks. | ||||
16 lines changed or deleted | 18 lines changed or added | |||
md5.h | md5.h | |||
---|---|---|---|---|
/* | /* | |||
* md5.h | * Copyright (c) 2000, 2002 Virtual Unlimited B.V. | |||
* | ||||
* MD5 hash function, header | ||||
* | ||||
* Copyright (c) 2000 Virtual Unlimited B.V. | ||||
* | ||||
* Author: Bob Deblier <bob@virtualunlimited.com> | ||||
* | * | |||
* This library is free software; you can redistribute it and/or | * This library is free software; you can redistribute it and/or | |||
* modify it under the terms of the GNU Lesser General Public | * modify it under the terms of the GNU Lesser General Public | |||
* License as published by the Free Software Foundation; either | * License as published by the Free Software Foundation; either | |||
* version 2.1 of the License, or (at your option) any later version. | * version 2.1 of the License, or (at your option) any later version. | |||
* | * | |||
* This library is distributed in the hope that it will be useful, | * This library is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
* Lesser General Public License for more details. | * Lesser General Public License for more details. | |||
* | * | |||
* You should have received a copy of the GNU Lesser General Public | * You should have received a copy of the GNU Lesser General Public | |||
* License along with this library; if not, write to the Free Software | * License along with this library; if not, write to the Free Software | |||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 US A | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 US A | |||
* | * | |||
*/ | */ | |||
/*!\file md5.h | ||||
* \brief MD5 hash function. | ||||
* \author Bob Deblier <bob.deblier@pandora.be> | ||||
* \ingroup HASH_m HASH_md5_m | ||||
*/ | ||||
#ifndef _MD5_H | #ifndef _MD5_H | |||
#define _MD5_H | #define _MD5_H | |||
#include "beecrypt.h" | #include "beecrypt.h" | |||
/*!\brief Holds all the parameters necessary for the MD5 algorithm. | ||||
* \ingroup HASH_md5_h | ||||
*/ | ||||
typedef struct | typedef struct | |||
{ | { | |||
uint32 h[4]; | /*!\var h | |||
uint32 data[16]; | */ | |||
uint64 length; | uint32_t h[4]; | |||
uint8 offset; | /*!\var data | |||
*/ | ||||
uint32_t data[16]; | ||||
/*!\var length | ||||
* \brief Multi-precision integer counter for the bits that have bee | ||||
n | ||||
* processed so far. | ||||
*/ | ||||
#if (MP_WBITS == 64) | ||||
mpw length[1]; | ||||
#elif (MP_WBITS == 32) | ||||
mpw length[2]; | ||||
#else | ||||
# error | ||||
#endif | ||||
/*!\var offset | ||||
* \brief Offset into \a data; points to the place where new data will | ||||
be | ||||
* copied before it is processed. | ||||
*/ | ||||
uint32_t offset; | ||||
} md5Param; | } md5Param; | |||
#ifdef __cplusplus | #ifdef __cplusplus | |||
extern "C" { | extern "C" { | |||
#endif | #endif | |||
extern BEEDLLAPI const hashFunction md5; | /*!\var sha1 | |||
* \brief Holds the full API description of the MD5 algorithm. | ||||
*/ | ||||
extern BEECRYPTAPI const hashFunction md5; | ||||
BEEDLLAPI | /*!\fn int md5Reset(md5Param* mp) | |||
void md5Process(md5Param*); | * \brief This function resets the parameter block so that it's ready for a | |||
BEEDLLAPI | * new hash. | |||
int md5Reset (md5Param*); | * \param mp The hash function's parameter block. | |||
BEEDLLAPI | * \retval 0 on success. | |||
int md5Update (md5Param*, const byte*, int); | */ | |||
BEEDLLAPI | BEECRYPTAPI | |||
int md5Digest (md5Param*, uint32*); | void md5Process(md5Param* mp); | |||
/*!\fn int md5Reset(md5Param* mp) | ||||
* \brief This function resets the parameter block so that it's ready for a | ||||
* new hash. | ||||
* \param mp The hash function's parameter block. | ||||
* \retval 0 on success. | ||||
*/ | ||||
BEECRYPTAPI | ||||
int md5Reset (md5Param* mp); | ||||
/*!\fn int md5Update(md5Param* mp, const byte* data, size_t size) | ||||
* \brief This function should be used to pass successive blocks of data | ||||
* to be hashed. | ||||
* \param mp The hash function's parameter block. | ||||
* \param data | ||||
* \param size | ||||
* \retval 0 on success. | ||||
*/ | ||||
BEECRYPTAPI | ||||
int md5Update (md5Param* mp, const byte* data, size_t size); | ||||
/*!\fn int md5Digest(md5Param* mp, byte* digest) | ||||
* \brief This function finishes the current hash computation and copies | ||||
* the digest value into \a digest. | ||||
* \param mp The hash function's parameter block. | ||||
* \param digest The place to store the 16-byte digest. | ||||
* \retval 0 on success. | ||||
*/ | ||||
BEECRYPTAPI | ||||
int md5Digest (md5Param* mp, byte* digest); | ||||
#ifdef __cplusplus | #ifdef __cplusplus | |||
} | } | |||
#endif | #endif | |||
#endif | #endif | |||
End of changes. 6 change blocks. | ||||
20 lines changed or deleted | 76 lines changed or added | |||
memchunk.h | memchunk.h | |||
---|---|---|---|---|
/* | /* | |||
* memchunk.h | ||||
* | ||||
* Beecrypt memory block handling, header | ||||
* | ||||
* Copyright (c) 2001 Virtual Unlimited B.V. | * Copyright (c) 2001 Virtual Unlimited B.V. | |||
* | * | |||
* Author: Bob Deblier <bob@virtualunlimited.com> | ||||
* | ||||
* This library is free software; you can redistribute it and/or | * This library is free software; you can redistribute it and/or | |||
* modify it under the terms of the GNU Lesser General Public | * modify it under the terms of the GNU Lesser General Public | |||
* License as published by the Free Software Foundation; either | * License as published by the Free Software Foundation; either | |||
* version 2.1 of the License, or (at your option) any later version. | * version 2.1 of the License, or (at your option) any later version. | |||
* | * | |||
* This library is distributed in the hope that it will be useful, | * This library is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
* Lesser General Public License for more details. | * Lesser General Public License for more details. | |||
* | * | |||
* You should have received a copy of the GNU Lesser General Public | * You should have received a copy of the GNU Lesser General Public | |||
* License along with this library; if not, write to the Free Software | * License along with this library; if not, write to the Free Software | |||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 US A | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 US A | |||
*/ | */ | |||
/*!\file memchunk.h | ||||
* \author Bob Deblier <bob.deblier@pandora.be> | ||||
*/ | ||||
#ifndef _MEMCHUNK_H | #ifndef _MEMCHUNK_H | |||
#define _MEMCHUNK_H | #define _MEMCHUNK_H | |||
#ifdef HAVE_CONFIG_H | #include "beecrypt.api.h" | |||
# include "config.h" | ||||
#endif | ||||
typedef struct | typedef struct | |||
{ | { | |||
int size; | size_t size; | |||
byte* data; | byte* data; | |||
} memchunk; | } memchunk; | |||
#ifdef __cplusplus | #ifdef __cplusplus | |||
extern "C" { | extern "C" { | |||
#endif | #endif | |||
BEEDLLAPI | BEECRYPTAPI | |||
memchunk* memchunkAlloc(int); | memchunk* memchunkAlloc(size_t); | |||
BEEDLLAPI | BEECRYPTAPI | |||
void memchunkFree(memchunk*); | void memchunkFree(memchunk*); | |||
BEEDLLAPI | BEECRYPTAPI | |||
memchunk* memchunkResize(memchunk*, int); | memchunk* memchunkResize(memchunk*, size_t); | |||
BEECRYPTAPI | ||||
memchunk* memchunkClone(const memchunk*); | ||||
#ifdef __cplusplus | #ifdef __cplusplus | |||
} | } | |||
#endif | #endif | |||
#endif | #endif | |||
End of changes. 7 change blocks. | ||||
15 lines changed or deleted | 13 lines changed or added | |||
mtprng.h | mtprng.h | |||
---|---|---|---|---|
/* | /* | |||
* mtprng.h | * Copyright (c) 1998, 1999, 2000, 2003 Virtual Unlimited B.V. | |||
* | ||||
* Mersenne twister pseudo-random number generator, header | ||||
* | ||||
* Copyright (c) 1998, 1999, 2000 Virtual Unlimited B.V. | ||||
* | ||||
* Author: Bob Deblier <bob@virtualunlimited.com> | ||||
* | * | |||
* This library is free software; you can redistribute it and/or | * This library is free software; you can redistribute it and/or | |||
* modify it under the terms of the GNU Lesser General Public | * modify it under the terms of the GNU Lesser General Public | |||
* License as published by the Free Software Foundation; either | * License as published by the Free Software Foundation; either | |||
* version 2.1 of the License, or (at your option) any later version. | * version 2.1 of the License, or (at your option) any later version. | |||
* | * | |||
* This library is distributed in the hope that it will be useful, | * This library is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
* Lesser General Public License for more details. | * Lesser General Public License for more details. | |||
* | * | |||
* You should have received a copy of the GNU Lesser General Public | * You should have received a copy of the GNU Lesser General Public | |||
* License along with this library; if not, write to the Free Software | * License along with this library; if not, write to the Free Software | |||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 US A | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 US A | |||
* | * | |||
*/ | */ | |||
/*!\file mtprng.h | ||||
* \brief Mersenne Twister pseudo-random number generator, headers. | ||||
* \author Bob Deblier <bob.deblier@pandora.be> | ||||
* \ingroup PRNG_m | ||||
*/ | ||||
#ifndef _MTPRNG_H | #ifndef _MTPRNG_H | |||
#define _MTPRNG_H | #define _MTPRNG_H | |||
#include "beecrypt.h" | #include "beecrypt.h" | |||
#if WIN32 | #ifdef _REENTRANT | |||
# include <windows.h> | # if WIN32 | |||
# include <winbase.h> | # include <windows.h> | |||
#else | # include <winbase.h> | |||
# if HAVE_SYNCH_H | ||||
# include <synch.h> | ||||
# elif HAVE_PTHREAD_H | ||||
# include <pthread.h> | ||||
# else | ||||
# error need locking mechanism | ||||
# endif | # endif | |||
#endif | #endif | |||
#include "beecrypt.h" | ||||
#define N 624 | #define N 624 | |||
#define M 397 | #define M 397 | |||
#define K 0x9908B0DF | #define K 0x9908B0DFU | |||
/* | ||||
*/ | ||||
typedef struct | typedef struct | |||
{ | { | |||
#ifdef _REENTRANT | #ifdef _REENTRANT | |||
# if WIN32 | # if WIN32 | |||
HANDLE lock; | HANDLE lock; | |||
# else | # else | |||
# if HAVE_SYNCH_H | bc_lock_t lock; | |||
mutex_t lock; | ||||
# elif HAVE_PTHREAD_H | ||||
pthread_mutex_t lock; | ||||
# else | ||||
# error need locking mechanism | ||||
# endif | ||||
# endif | # endif | |||
#endif | #endif | |||
uint32 state[N+1]; | uint32_t state[N+1]; | |||
uint32 left; | uint32_t left; | |||
uint32* nextw; | uint32_t* nextw; | |||
} mtprngParam; | } mtprngParam; | |||
#ifdef __cplusplus | #ifdef __cplusplus | |||
extern "C" { | extern "C" { | |||
#endif | #endif | |||
extern BEEDLLAPI const randomGenerator mtprng; | /* | |||
*/ | ||||
extern BEECRYPTAPI const randomGenerator mtprng; | ||||
BEEDLLAPI | /* | |||
int mtprngSetup (mtprngParam*); | */ | |||
BEEDLLAPI | BEECRYPTAPI | |||
int mtprngSeed (mtprngParam*, const uint32*, int); | int mtprngSetup (mtprngParam* mp); | |||
BEEDLLAPI | ||||
int mtprngNext (mtprngParam*, uint32*, int); | /* | |||
BEEDLLAPI | */ | |||
int mtprngCleanup(mtprngParam*); | BEECRYPTAPI | |||
int mtprngSeed (mtprngParam* mp, const byte* data, size_t size); | ||||
/* | ||||
*/ | ||||
BEECRYPTAPI | ||||
int mtprngNext (mtprngParam* mp, byte* data, size_t size); | ||||
/* | ||||
*/ | ||||
BEECRYPTAPI | ||||
int mtprngCleanup(mtprngParam* mp); | ||||
#ifdef __cplusplus | #ifdef __cplusplus | |||
} | } | |||
#endif | #endif | |||
#endif | #endif | |||
End of changes. 11 change blocks. | ||||
40 lines changed or deleted | 41 lines changed or added | |||
rsa.h | rsa.h | |||
---|---|---|---|---|
/* | /* | |||
* rsa.h | * Copyright (c) 2000, 2002 Virtual Unlimited B.V. | |||
* | ||||
* RSA encryption & signature scheme, header | ||||
* | ||||
* Copyright (c) 2000 Virtual Unlimited B.V. | ||||
* | ||||
* Author: Bob Deblier <bob@virtualunlimited.com> | ||||
* | * | |||
* This library is free software; you can redistribute it and/or | * This library is free software; you can redistribute it and/or | |||
* modify it under the terms of the GNU Lesser General Public | * modify it under the terms of the GNU Lesser General Public | |||
* License as published by the Free Software Foundation; either | * License as published by the Free Software Foundation; either | |||
* version 2.1 of the License, or (at your option) any later version. | * version 2.1 of the License, or (at your option) any later version. | |||
* | * | |||
* This library is distributed in the hope that it will be useful, | * This library is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
* Lesser General Public License for more details. | * Lesser General Public License for more details. | |||
* | * | |||
* You should have received a copy of the GNU Lesser General Public | * You should have received a copy of the GNU Lesser General Public | |||
* License along with this library; if not, write to the Free Software | * License along with this library; if not, write to the Free Software | |||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 US A | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 US A | |||
* | * | |||
*/ | */ | |||
/*!\file rsa.h | ||||
* \brief RSA algorithm. | ||||
* \author Bob Deblier <bob.deblier@pandora.be> | ||||
* \ingroup IF_m IF_rsa_m | ||||
*/ | ||||
#ifndef _RSA_H | #ifndef _RSA_H | |||
#define _RSA_H | #define _RSA_H | |||
#include "rsakp.h" | #include "rsakp.h" | |||
#ifdef __cplusplus | #ifdef __cplusplus | |||
extern "C" { | extern "C" { | |||
#endif | #endif | |||
BEEDLLAPI | /*!\fn int rsapub(const rsapk* pk, const mpnumber* m, mpnumber* c) | |||
int rsapri (const rsakp* kp, const mp32number* m, mp32number* c); | * \brief This function performs a raw RSA public key operation. | |||
BEEDLLAPI | * | |||
int rsapricrt(const rsakp* kp, const mp32number* m, mp32number* c); | * This function can be used for encryption and verifying. | |||
* | ||||
* It performs the following operation: | ||||
* \li \f$c=m^{e}\ \textrm{mod}\ n\f$ | ||||
* | ||||
* \param pk The RSA public key. | ||||
* \param m The message. | ||||
* \param c The ciphertext. | ||||
* \retval 0 on success. | ||||
* \retval -1 on failure. | ||||
*/ | ||||
BEECRYPTAPI | ||||
int rsapub (const rsapk* pk, const mpnumber* m, mpnumber* c); | ||||
BEEDLLAPI | /*!\fn int rsapri(const rsakp* kp, const mpnumber* c, mpnumber* m) | |||
int rsavrfy (const rsapk* pk, const mp32number* m, const mp32number* c); | * \brief This function performs a raw RSA private key operation. | |||
* | ||||
* This function can be used for decryption and signing. | ||||
* | ||||
* It performs the operation: | ||||
* \li \f$m=c^{d}\ \textrm{mod}\ n\f$ | ||||
* | ||||
* \param kp The RSA keypair. | ||||
* \param c The ciphertext. | ||||
* \param m The message. | ||||
* \retval 0 on success. | ||||
* \retval -1 on failure. | ||||
*/ | ||||
BEECRYPTAPI | ||||
int rsapri (const rsakp* kp, const mpnumber* c, mpnumber* m); | ||||
/*!\fn int rsapricrt(const rsakp* kp, const mpnumber* c, mpnumber* m) | ||||
* \brief This function performs a raw RSA private key operation, with | ||||
* application of the Chinese Remainder Theorem. | ||||
* | ||||
* It performs the operation: | ||||
* \li \f$j_1=c^{d_1}\ \textrm{mod}\ p\f$ | ||||
* \li \f$j_2=c^{d_2}\ \textrm{mod}\ q\f$ | ||||
* \li \f$h=c \cdot (j_1-j_2)\ \textrm{mod}\ p\f$ | ||||
* \li \f$m=j_2+hq\f$ | ||||
* | ||||
* \param kp The RSA keypair. | ||||
* \param c The ciphertext. | ||||
* \param m The message. | ||||
* \retval 0 on success. | ||||
* \retval -1 on failure. | ||||
*/ | ||||
BEECRYPTAPI | ||||
int rsapricrt(const rsakp* kp, const mpnumber* c, mpnumber* m); | ||||
/*!\fn int rsavrfy(const rsapk* pk, const mpnumber* m, const mpnumber* c) | ||||
* \brief This function performs a raw RSA verification. | ||||
* | ||||
* It verifies if ciphertext \a c was encrypted from cleartext \a m | ||||
* with the private key matching the given public key \a pk. | ||||
* | ||||
* \param pk The public key. | ||||
* \param m The cleartext message. | ||||
* \param c The ciphertext message. | ||||
* \retval 1 on success. | ||||
* \retval 0 on failure. | ||||
*/ | ||||
BEECRYPTAPI | ||||
int rsavrfy (const rsapk* pk, const mpnumber* m, const mpnumber* c); | ||||
#ifdef __cplusplus | #ifdef __cplusplus | |||
} | } | |||
#endif | #endif | |||
#endif | #endif | |||
End of changes. 4 change blocks. | ||||
13 lines changed or deleted | 73 lines changed or added | |||
rsakp.h | rsakp.h | |||
---|---|---|---|---|
/* | /* | |||
* rsakp.h | * Copyright (c) 2000, 2001, 2002 Virtual Unlimited B.V. | |||
* | ||||
* RSA Keypair, header | ||||
* | ||||
* <conformance statement for IEEE P1363 needed here> | ||||
* | ||||
* Copyright (c) 2000, 2001 Virtual Unlimited B.V. | ||||
* | ||||
* Author: Bob Deblier <bob@virtualunlimited.com> | ||||
* | * | |||
* This library is free software; you can redistribute it and/or | * This library is free software; you can redistribute it and/or | |||
* modify it under the terms of the GNU Lesser General Public | * modify it under the terms of the GNU Lesser General Public | |||
* License as published by the Free Software Foundation; either | * License as published by the Free Software Foundation; either | |||
* version 2.1 of the License, or (at your option) any later version. | * version 2.1 of the License, or (at your option) any later version. | |||
* | * | |||
* This library is distributed in the hope that it will be useful, | * This library is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
* Lesser General Public License for more details. | * Lesser General Public License for more details. | |||
* | * | |||
* You should have received a copy of the GNU Lesser General Public | * You should have received a copy of the GNU Lesser General Public | |||
* License along with this library; if not, write to the Free Software | * License along with this library; if not, write to the Free Software | |||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 US A | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 US A | |||
* | * | |||
*/ | */ | |||
/*!\file rsakp.h | ||||
* \brief RSA keypair, headers. | ||||
* \author Bob Deblier <bob.deblier@pandora.be> | ||||
* \ingroup IF_m IF_rsa_m | ||||
*/ | ||||
#ifndef _RSAKP_H | #ifndef _RSAKP_H | |||
#define _RSAKP_H | #define _RSAKP_H | |||
#include "rsapk.h" | #include "rsapk.h" | |||
/*!\brief RSA keypair. | ||||
* \ingroup IF_rsa_m | ||||
*/ | ||||
typedef struct | typedef struct | |||
{ | { | |||
mp32barrett n; | /*!\var n | |||
mp32number e; | * \brief The modulus. | |||
mp32number d; | * | |||
mp32barrett p; | * \f$n=pq\f$ | |||
mp32barrett q; | */ | |||
mp32number d1; | mpbarrett n; | |||
mp32number d2; | /*!\var e | |||
mp32number c; | * \brief The public exponent. | |||
*/ | ||||
mpnumber e; | ||||
/*!\var d | ||||
* \brief The private exponent. | ||||
*/ | ||||
mpnumber d; | ||||
/*!\var p | ||||
* \brief The first prime factor of the modulus. | ||||
*/ | ||||
mpbarrett p; | ||||
/*!\var q | ||||
* \brief The second prime factor of the modulus. | ||||
*/ | ||||
mpbarrett q; | ||||
/*!\var d1 | ||||
* | ||||
* \f$d_1=d\ \textrm{mod}\ (p-1)\f$ | ||||
*/ | ||||
mpnumber d1; | ||||
/*!\var d2 | ||||
* | ||||
* \f$d_2=d\ \textrm{mod}\ (q-1)\f$ | ||||
*/ | ||||
mpnumber d2; | ||||
/*!\var q | ||||
* | ||||
* \f$c=q^{-1}\ \textrm{mod}\ p\f$ | ||||
*/ | ||||
mpnumber c; | ||||
} rsakp; | } rsakp; | |||
#ifdef __cplusplus | #ifdef __cplusplus | |||
extern "C" { | extern "C" { | |||
#endif | #endif | |||
BEEDLLAPI | BEECRYPTAPI | |||
int rsakpMake(rsakp*, randomGeneratorContext*, int); | int rsakpMake(rsakp*, randomGeneratorContext*, int); | |||
BEEDLLAPI | BEECRYPTAPI | |||
int rsakpInit(rsakp*); | int rsakpInit(rsakp*); | |||
BEEDLLAPI | BEECRYPTAPI | |||
int rsakpFree(rsakp*); | int rsakpFree(rsakp*); | |||
BEEDLLAPI | BEECRYPTAPI | |||
int rsakpCopy(rsakp*, const rsakp*); | int rsakpCopy(rsakp*, const rsakp*); | |||
#ifdef __cplusplus | #ifdef __cplusplus | |||
} | } | |||
#endif | #endif | |||
#endif | #endif | |||
End of changes. 8 change blocks. | ||||
21 lines changed or deleted | 51 lines changed or added | |||
rsapk.h | rsapk.h | |||
---|---|---|---|---|
/* | /* | |||
* rsapk.h | * Copyright (c) 2000, 2002 Virtual Unlimited B.V. | |||
* | ||||
* RSA Public Key, header | ||||
* | ||||
* Copyright (c) 2000 Virtual Unlimited B.V. | ||||
* | ||||
* Author: Bob Deblier <bob@virtualunlimited.com> | ||||
* | * | |||
* This library is free software; you can redistribute it and/or | * This library is free software; you can redistribute it and/or | |||
* modify it under the terms of the GNU Lesser General Public | * modify it under the terms of the GNU Lesser General Public | |||
* License as published by the Free Software Foundation; either | * License as published by the Free Software Foundation; either | |||
* version 2.1 of the License, or (at your option) any later version. | * version 2.1 of the License, or (at your option) any later version. | |||
* | * | |||
* This library is distributed in the hope that it will be useful, | * This library is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
* Lesser General Public License for more details. | * Lesser General Public License for more details. | |||
* | * | |||
* You should have received a copy of the GNU Lesser General Public | * You should have received a copy of the GNU Lesser General Public | |||
* License along with this library; if not, write to the Free Software | * License along with this library; if not, write to the Free Software | |||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 US A | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 US A | |||
* | * | |||
*/ | */ | |||
/*!\file rsapk.h | ||||
* \brief RSA public key, headers. | ||||
* \author Bob Deblier <bob.deblier@pandora.be> | ||||
* \ingroup IF_m IF_rsa_m | ||||
*/ | ||||
#ifndef _RSAPK_H | #ifndef _RSAPK_H | |||
#define _RSAPK_H | #define _RSAPK_H | |||
#include "mp32barrett.h" | #include "mpbarrett.h" | |||
typedef struct | typedef struct | |||
{ | { | |||
mp32barrett n; | mpbarrett n; | |||
mp32number e; | mpnumber e; | |||
} rsapk; | } rsapk; | |||
#ifdef __cplusplus | #ifdef __cplusplus | |||
extern "C" { | extern "C" { | |||
#endif | #endif | |||
BEEDLLAPI | BEECRYPTAPI | |||
int rsapkInit(rsapk*); | int rsapkInit(rsapk*); | |||
BEEDLLAPI | BEECRYPTAPI | |||
int rsapkFree(rsapk*); | int rsapkFree(rsapk*); | |||
BEEDLLAPI | BEECRYPTAPI | |||
int rsapkCopy(rsapk*, const rsapk*); | int rsapkCopy(rsapk*, const rsapk*); | |||
#ifdef __cplusplus | #ifdef __cplusplus | |||
} | } | |||
#endif | #endif | |||
#endif | #endif | |||
End of changes. 7 change blocks. | ||||
13 lines changed or deleted | 13 lines changed or added | |||
sha256.h | sha256.h | |||
---|---|---|---|---|
/* | /* | |||
* sha256.h | * Copyright (c) 2000, 2001, 2002 Virtual Unlimited B.V. | |||
* | ||||
* SHA-256 hash function, header | ||||
* | ||||
* Copyright (c) 2000, 2001 Virtual Unlimited B.V. | ||||
* | ||||
* Author: Bob Deblier <bob@virtualunlimited.com> | ||||
* | * | |||
* This library is free software; you can redistribute it and/or | * This library is free software; you can redistribute it and/or | |||
* modify it under the terms of the GNU Lesser General Public | * modify it under the terms of the GNU Lesser General Public | |||
* License as published by the Free Software Foundation; either | * License as published by the Free Software Foundation; either | |||
* version 2.1 of the License, or (at your option) any later version. | * version 2.1 of the License, or (at your option) any later version. | |||
* | * | |||
* This library is distributed in the hope that it will be useful, | * This library is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
* Lesser General Public License for more details. | * Lesser General Public License for more details. | |||
* | * | |||
* You should have received a copy of the GNU Lesser General Public | * You should have received a copy of the GNU Lesser General Public | |||
* License along with this library; if not, write to the Free Software | * License along with this library; if not, write to the Free Software | |||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 US A | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 US A | |||
* | * | |||
*/ | */ | |||
/*!\file sha256.h | ||||
* \brief SHA-256 hash function, headers. | ||||
* \author Bob Deblier <bob.deblier@pandora.be> | ||||
* \ingroup HASH_m HASH_sha256_m | ||||
*/ | ||||
#ifndef _SHA256_H | #ifndef _SHA256_H | |||
#define _SHA256_H | #define _SHA256_H | |||
#include "beecrypt.h" | #include "beecrypt.h" | |||
/*!\brief Holds all the parameters necessary for the SHA-256 algorithm. | ||||
* \ingroup HASH_sha256_m | ||||
*/ | ||||
typedef struct | typedef struct | |||
{ | { | |||
uint32 h[8]; | /*!\var h | |||
uint32 data[64]; | */ | |||
uint64 length; | uint32_t h[8]; | |||
uint8 offset; | /*!\var data | |||
*/ | ||||
uint32_t data[64]; | ||||
/*!\var length | ||||
* \brief Multi-precision integer counter for the bits that have bee | ||||
n | ||||
* processed so far. | ||||
*/ | ||||
#if (MP_WBITS == 64) | ||||
mpw length[1]; | ||||
#elif (MP_WBITS == 32) | ||||
mpw length[2]; | ||||
#else | ||||
# error | ||||
#endif | ||||
/*!\var offset | ||||
* \brief Offset into \a data; points to the place where new data wi | ||||
ll be | ||||
* copied before it is processed. | ||||
*/ | ||||
uint32_t offset; | ||||
} sha256Param; | } sha256Param; | |||
#ifdef __cplusplus | #ifdef __cplusplus | |||
extern "C" { | extern "C" { | |||
#endif | #endif | |||
extern BEEDLLAPI const hashFunction sha256; | /*!\var sha256 | |||
* \brief Holds the full API description of the SHA-256 algorithm. | ||||
*/ | ||||
extern BEECRYPTAPI const hashFunction sha256; | ||||
BEEDLLAPI | /*!\fn void sha256Process(sha256Param* sp) | |||
void sha256Process(sha256Param*); | * \brief This function performs the core of the SHA-256 hash algorithm; it | |||
BEEDLLAPI | * processes a block of 64 bytes. | |||
int sha256Reset (sha256Param*); | * \param sp The hash function's parameter block. | |||
BEEDLLAPI | */ | |||
int sha256Update (sha256Param*, const byte*, int); | BEECRYPTAPI | |||
BEEDLLAPI | void sha256Process(sha256Param* sp); | |||
int sha256Digest (sha256Param*, uint32*); | ||||
/*!\fn int sha256Reset(sha256Param* sp) | ||||
* \brief This function resets the parameter block so that it's ready for a | ||||
* new hash. | ||||
* \param sp The hash function's parameter block. | ||||
* \retval 0 on success. | ||||
*/ | ||||
BEECRYPTAPI | ||||
int sha256Reset (sha256Param* sp); | ||||
/*!\fn int sha256Update(sha256Param* sp, const byte* data, size_t size) | ||||
* \brief This function should be used to pass successive blocks of data | ||||
* to be hashed. | ||||
* \param sp The hash function's parameter block. | ||||
* \param data | ||||
* \param size | ||||
* \retval 0 on success. | ||||
*/ | ||||
BEECRYPTAPI | ||||
int sha256Update (sha256Param* sp, const byte* data, size_t size); | ||||
/*!\fn int sha256Digest(sha256Param* sp, byte* digest) | ||||
* \brief This function finishes the current hash computation and copies | ||||
* the digest value into \a digest. | ||||
* \param sp The hash function's parameter block. | ||||
* \param digest The place to store the 32-byte digest. | ||||
* \retval 0 on success. | ||||
*/ | ||||
BEECRYPTAPI | ||||
int sha256Digest (sha256Param* sp, byte* digest); | ||||
#ifdef __cplusplus | #ifdef __cplusplus | |||
} | } | |||
#endif | #endif | |||
#endif | #endif | |||
End of changes. 6 change blocks. | ||||
20 lines changed or deleted | 75 lines changed or added | |||
timestamp.h | timestamp.h | |||
---|---|---|---|---|
skipping to change at line 37 | skipping to change at line 37 | |||
#define _TIMESTAMP_H | #define _TIMESTAMP_H | |||
#include "beecrypt.h" | #include "beecrypt.h" | |||
#if HAVE_LONG_LONG | #if HAVE_LONG_LONG | |||
# define ONE_SECOND 1000LL | # define ONE_SECOND 1000LL | |||
# define ONE_MINUTE 60000LL | # define ONE_MINUTE 60000LL | |||
# define ONE_HOUR 3600000LL | # define ONE_HOUR 3600000LL | |||
# define ONE_DAY 86400000LL | # define ONE_DAY 86400000LL | |||
# define ONE_WEEK 604800000LL | # define ONE_WEEK 604800000LL | |||
# define ONE_YEAR 31536000000LL | ||||
#else | #else | |||
# define ONE_SECOND 1000L | # define ONE_SECOND 1000L | |||
# define ONE_MINUTE 60000L | # define ONE_MINUTE 60000L | |||
# define ONE_HOUR 3600000L | # define ONE_HOUR 3600000L | |||
# define ONE_DAY 86400000L | # define ONE_DAY 86400000L | |||
# define ONE_WEEK 604800000L | # define ONE_WEEK 604800000L | |||
# define ONE_YEAR 31536000000L | ||||
#endif | #endif | |||
#ifdef __cplusplus | #ifdef __cplusplus | |||
extern "C" { | extern "C" { | |||
#endif | #endif | |||
BEEDLLAPI | BEECRYPTAPI | |||
javalong timestamp(); | javalong timestamp(void); | |||
#ifdef __cplusplus | #ifdef __cplusplus | |||
} | } | |||
#endif | #endif | |||
#endif | #endif | |||
End of changes. 3 change blocks. | ||||
2 lines changed or deleted | 4 lines changed or added | |||