added libtomcrypt-1.01
This commit is contained in:
committed by
Steffen Jaeckel
parent
bfc2f5b078
commit
6ac9952498
@@ -44,7 +44,7 @@ extern "C" {
|
||||
|
||||
/* detect 64-bit mode if possible */
|
||||
#if defined(__x86_64__)
|
||||
#if !(defined(MP_64BIT) || defined(MP_31BIT) || defined(MP_16BIT) || defined(MP_8BIT))
|
||||
#if !(defined(MP_64BIT) && defined(MP_16BIT) && defined(MP_8BIT))
|
||||
#define MP_64BIT
|
||||
#endif
|
||||
#endif
|
||||
@@ -112,7 +112,7 @@ extern "C" {
|
||||
#else
|
||||
/* prototypes for our heap functions */
|
||||
extern void *XMALLOC(size_t n);
|
||||
extern void *REALLOC(void *p, size_t n);
|
||||
extern void *XREALLOC(void *p, size_t n);
|
||||
extern void *XCALLOC(size_t n, size_t s);
|
||||
extern void XFREE(void *p);
|
||||
#endif
|
||||
@@ -147,7 +147,6 @@ extern "C" {
|
||||
/* Primality generation flags */
|
||||
#define LTM_PRIME_BBS 0x0001 /* BBS style prime */
|
||||
#define LTM_PRIME_SAFE 0x0002 /* Safe prime (p-1)/2 == prime */
|
||||
#define LTM_PRIME_2MSB_OFF 0x0004 /* force 2nd MSB to 0 */
|
||||
#define LTM_PRIME_2MSB_ON 0x0008 /* force 2nd MSB to 1 */
|
||||
|
||||
typedef int mp_err;
|
||||
@@ -429,6 +428,15 @@ int mp_reduce_2k_setup(mp_int *a, mp_digit *d);
|
||||
/* reduces a modulo b where b is of the form 2**p - k [0 <= a] */
|
||||
int mp_reduce_2k(mp_int *a, mp_int *n, mp_digit d);
|
||||
|
||||
/* returns true if a can be reduced with mp_reduce_2k_l */
|
||||
int mp_reduce_is_2k_l(mp_int *a);
|
||||
|
||||
/* determines k value for 2k reduction */
|
||||
int mp_reduce_2k_setup_l(mp_int *a, mp_int *d);
|
||||
|
||||
/* reduces a modulo b where b is of the form 2**p - k [0 <= a] */
|
||||
int mp_reduce_2k_l(mp_int *a, mp_int *n, mp_int *d);
|
||||
|
||||
/* d = a**b (mod c) */
|
||||
int mp_exptmod(mp_int *a, mp_int *b, mp_int *c, mp_int *d);
|
||||
|
||||
@@ -509,14 +517,16 @@ int mp_prime_random_ex(mp_int *a, int t, int size, int flags, ltm_prime_callback
|
||||
int mp_count_bits(mp_int *a);
|
||||
|
||||
int mp_unsigned_bin_size(mp_int *a);
|
||||
int mp_read_unsigned_bin(mp_int *a, unsigned char *b, int c);
|
||||
int mp_read_unsigned_bin(mp_int *a, const unsigned char *b, int c);
|
||||
int mp_to_unsigned_bin(mp_int *a, unsigned char *b);
|
||||
int mp_to_unsigned_bin_n (mp_int * a, unsigned char *b, unsigned long *outlen);
|
||||
|
||||
int mp_signed_bin_size(mp_int *a);
|
||||
int mp_read_signed_bin(mp_int *a, unsigned char *b, int c);
|
||||
int mp_to_signed_bin(mp_int *a, unsigned char *b);
|
||||
int mp_read_signed_bin(mp_int *a, const unsigned char *b, int c);
|
||||
int mp_to_signed_bin(mp_int *a, unsigned char *b);
|
||||
int mp_to_signed_bin_n (mp_int * a, unsigned char *b, unsigned long *outlen);
|
||||
|
||||
int mp_read_radix(mp_int *a, char *str, int radix);
|
||||
int mp_read_radix(mp_int *a, const char *str, int radix);
|
||||
int mp_toradix(mp_int *a, char *str, int radix);
|
||||
int mp_toradix_n(mp_int * a, char *str, int radix, int maxlen);
|
||||
int mp_radix_size(mp_int *a, int radix, int *size);
|
||||
@@ -554,7 +564,7 @@ int fast_mp_invmod(mp_int *a, mp_int *b, mp_int *c);
|
||||
int mp_invmod_slow (mp_int * a, mp_int * b, mp_int * c);
|
||||
int fast_mp_montgomery_reduce(mp_int *a, mp_int *m, mp_digit mp);
|
||||
int mp_exptmod_fast(mp_int *G, mp_int *X, mp_int *P, mp_int *Y, int mode);
|
||||
int s_mp_exptmod (mp_int * G, mp_int * X, mp_int * P, mp_int * Y);
|
||||
int s_mp_exptmod (mp_int * G, mp_int * X, mp_int * P, mp_int * Y, int mode);
|
||||
void bn_reverse(unsigned char *s, int len);
|
||||
|
||||
extern const char *mp_s_rmap;
|
||||
|
||||
@@ -16,8 +16,8 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
/* version */
|
||||
#define CRYPT 0x0100
|
||||
#define SCRYPT "1.00"
|
||||
#define CRYPT 0x0101
|
||||
#define SCRYPT "1.01"
|
||||
|
||||
/* max size of either a cipher/hash block or symmetric key [largest of the two] */
|
||||
#define MAXBLOCKSIZE 128
|
||||
@@ -66,6 +66,7 @@ enum {
|
||||
#include <tomcrypt_macros.h>
|
||||
#include <tomcrypt_cipher.h>
|
||||
#include <tomcrypt_hash.h>
|
||||
#include <tomcrypt_mac.h>
|
||||
#include <tomcrypt_prng.h>
|
||||
#include <tomcrypt_pk.h>
|
||||
#include <tomcrypt_misc.h>
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
/* you can change how memory allocation works ... */
|
||||
void *XMALLOC(size_t n);
|
||||
void *REALLOC(void *p, size_t n);
|
||||
void *XREALLOC(void *p, size_t n);
|
||||
void *XCALLOC(size_t n, size_t s);
|
||||
void XFREE(void *p);
|
||||
|
||||
@@ -34,6 +34,8 @@ int XMEMCMP(const void *s1, const void *s2, size_t n);
|
||||
#if defined(INTEL_CC) || (defined(_MSC_VER) && defined(WIN32)) || (defined(__GNUC__) && (defined(__DJGPP__) || defined(__CYGWIN__) || defined(__MINGW32__) || defined(__i386__)))
|
||||
#define ENDIAN_LITTLE
|
||||
#define ENDIAN_32BITWORD
|
||||
#define LTC_FAST
|
||||
#define LTC_FAST_TYPE unsigned long
|
||||
#endif
|
||||
|
||||
/* detects MIPS R5900 processors (PS2) */
|
||||
@@ -46,6 +48,26 @@ int XMEMCMP(const void *s1, const void *s2, size_t n);
|
||||
#if defined(__x86_64__)
|
||||
#define ENDIAN_LITTLE
|
||||
#define ENDIAN_64BITWORD
|
||||
#define LTC_FAST
|
||||
#define LTC_FAST_TYPE unsigned long
|
||||
#endif
|
||||
|
||||
#ifdef LTC_NO_FAST
|
||||
#ifdef LTC_FAST
|
||||
#undef LTC_FAST
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* No asm is a quick way to disable anything "not portable" */
|
||||
#ifdef LTC_NO_ASM
|
||||
#undef ENDIAN_LITTLE
|
||||
#undef ENDIAN_BIG
|
||||
#undef ENDIAN_32BITWORD
|
||||
#undef ENDIAN_64BITWORD
|
||||
#undef LTC_FAST
|
||||
#undef LTC_FAST_TYPE
|
||||
#define LTC_NO_ROLC
|
||||
#define LTC_NO_BSWAP
|
||||
#endif
|
||||
|
||||
/* #define ENDIAN_LITTLE */
|
||||
|
||||
@@ -164,6 +164,7 @@ typedef union Symmetric_key {
|
||||
#ifdef ANUBIS
|
||||
struct anubis_key anubis;
|
||||
#endif
|
||||
void *data;
|
||||
} symmetric_key;
|
||||
|
||||
/* A block cipher ECB structure */
|
||||
@@ -274,11 +275,109 @@ extern struct ltc_cipher_descriptor {
|
||||
@return CRYPT_OK if successful, CRYPT_NOP if self-testing has been disabled
|
||||
*/
|
||||
int (*test)(void);
|
||||
|
||||
/** Terminate the context
|
||||
@param skey The scheduled key
|
||||
*/
|
||||
void (*done)(symmetric_key *skey);
|
||||
|
||||
/** Determine a key size
|
||||
@param keysize [in/out] The size of the key desired and the suggested size
|
||||
@return CRYPT_OK if successful
|
||||
*/
|
||||
int (*keysize)(int *keysize);
|
||||
|
||||
/** Accelerators **/
|
||||
/** Accelerated ECB encryption
|
||||
@param pt Plaintext
|
||||
@param ct Ciphertext
|
||||
@param blocks The number of complete blocks to process
|
||||
@param skey The scheduled key context
|
||||
*/
|
||||
void (*accel_ecb_encrypt)(const unsigned char *pt, unsigned char *ct, unsigned long blocks, symmetric_key *skey);
|
||||
|
||||
/** Accelerated ECB decryption
|
||||
@param pt Plaintext
|
||||
@param ct Ciphertext
|
||||
@param blocks The number of complete blocks to process
|
||||
@param skey The scheduled key context
|
||||
*/
|
||||
void (*accel_ecb_decrypt)(const unsigned char *ct, unsigned char *pt, unsigned long blocks, symmetric_key *skey);
|
||||
|
||||
/** Accelerated CBC encryption
|
||||
@param pt Plaintext
|
||||
@param ct Ciphertext
|
||||
@param blocks The number of complete blocks to process
|
||||
@param IV The initial value (input/output)
|
||||
@param skey The scheduled key context
|
||||
*/
|
||||
void (*accel_cbc_encrypt)(const unsigned char *pt, unsigned char *ct, unsigned long blocks, unsigned char *IV, symmetric_key *skey);
|
||||
|
||||
/** Accelerated CBC decryption
|
||||
@param pt Plaintext
|
||||
@param ct Ciphertext
|
||||
@param blocks The number of complete blocks to process
|
||||
@param IV The initial value (input/output)
|
||||
@param skey The scheduled key context
|
||||
*/
|
||||
void (*accel_cbc_decrypt)(const unsigned char *ct, unsigned char *pt, unsigned long blocks, unsigned char *IV, symmetric_key *skey);
|
||||
|
||||
/** Accelerated CTR encryption
|
||||
@param pt Plaintext
|
||||
@param ct Ciphertext
|
||||
@param blocks The number of complete blocks to process
|
||||
@param IV The initial value (input/output)
|
||||
@param mode little or big endian counter (mode=0 or mode=1)
|
||||
@param skey The scheduled key context
|
||||
*/
|
||||
void (*accel_ctr_encrypt)(const unsigned char *pt, unsigned char *ct, unsigned long blocks, unsigned char *IV, int mode, symmetric_key *skey);
|
||||
|
||||
/** Accelerated CCM packet (one-shot)
|
||||
@param key The secret key to use
|
||||
@param keylen The length of the secret key (octets)
|
||||
@param nonce The session nonce [use once]
|
||||
@param noncelen The length of the nonce
|
||||
@param header The header for the session
|
||||
@param headerlen The length of the header (octets)
|
||||
@param pt [out] The plaintext
|
||||
@param ptlen The length of the plaintext (octets)
|
||||
@param ct [out] The ciphertext
|
||||
@param tag [out] The destination tag
|
||||
@param taglen [in/out] The max size and resulting size of the authentication tag
|
||||
@param direction Encrypt or Decrypt direction (0 or 1)
|
||||
@return CRYPT_OK if successful
|
||||
*/
|
||||
void (*accel_ccm_memory)(
|
||||
const unsigned char *key, unsigned long keylen,
|
||||
const unsigned char *nonce, unsigned long noncelen,
|
||||
const unsigned char *header, unsigned long headerlen,
|
||||
unsigned char *pt, unsigned long ptlen,
|
||||
unsigned char *ct,
|
||||
unsigned char *tag, unsigned long *taglen,
|
||||
int direction);
|
||||
|
||||
/** Accelerated GCM packet (one shot)
|
||||
@param key The secret key
|
||||
@param keylen The length of the secret key
|
||||
@param IV The initial vector
|
||||
@param IVlen The length of the initial vector
|
||||
@param adata The additional authentication data (header)
|
||||
@param adatalen The length of the adata
|
||||
@param pt The plaintext
|
||||
@param ptlen The length of the plaintext (ciphertext length is the same)
|
||||
@param ct The ciphertext
|
||||
@param tag [out] The MAC tag
|
||||
@param taglen [in/out] The MAC tag length
|
||||
@param direction Encrypt or Decrypt mode (GCM_ENCRYPT or GCM_DECRYPT)
|
||||
*/
|
||||
void (*accel_gcm_memory)(
|
||||
const unsigned char *key, unsigned long keylen,
|
||||
const unsigned char *IV, unsigned long IVlen,
|
||||
const unsigned char *adata, unsigned long adatalen,
|
||||
unsigned char *pt, unsigned long ptlen,
|
||||
unsigned char *ct,
|
||||
unsigned char *tag, unsigned long *taglen,
|
||||
int direction);
|
||||
} cipher_descriptor[];
|
||||
|
||||
#ifdef BLOWFISH
|
||||
@@ -286,6 +385,7 @@ int blowfish_setup(const unsigned char *key, int keylen, int num_rounds, symmetr
|
||||
void blowfish_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);
|
||||
void blowfish_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);
|
||||
int blowfish_test(void);
|
||||
void blowfish_done(symmetric_key *skey);
|
||||
int blowfish_keysize(int *keysize);
|
||||
extern const struct ltc_cipher_descriptor blowfish_desc;
|
||||
#endif
|
||||
@@ -295,6 +395,7 @@ int rc5_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_ke
|
||||
void rc5_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);
|
||||
void rc5_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);
|
||||
int rc5_test(void);
|
||||
void rc5_done(symmetric_key *skey);
|
||||
int rc5_keysize(int *keysize);
|
||||
extern const struct ltc_cipher_descriptor rc5_desc;
|
||||
#endif
|
||||
@@ -304,6 +405,7 @@ int rc6_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_ke
|
||||
void rc6_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);
|
||||
void rc6_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);
|
||||
int rc6_test(void);
|
||||
void rc6_done(symmetric_key *skey);
|
||||
int rc6_keysize(int *keysize);
|
||||
extern const struct ltc_cipher_descriptor rc6_desc;
|
||||
#endif
|
||||
@@ -313,6 +415,7 @@ int rc2_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_ke
|
||||
void rc2_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);
|
||||
void rc2_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);
|
||||
int rc2_test(void);
|
||||
void rc2_done(symmetric_key *skey);
|
||||
int rc2_keysize(int *keysize);
|
||||
extern const struct ltc_cipher_descriptor rc2_desc;
|
||||
#endif
|
||||
@@ -322,6 +425,7 @@ int saferp_setup(const unsigned char *key, int keylen, int num_rounds, symmetric
|
||||
void saferp_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);
|
||||
void saferp_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);
|
||||
int saferp_test(void);
|
||||
void saferp_done(symmetric_key *skey);
|
||||
int saferp_keysize(int *keysize);
|
||||
extern const struct ltc_cipher_descriptor saferp_desc;
|
||||
#endif
|
||||
@@ -336,6 +440,7 @@ void safer_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key
|
||||
int safer_k64_test(void);
|
||||
int safer_sk64_test(void);
|
||||
int safer_sk128_test(void);
|
||||
void safer_done(symmetric_key *skey);
|
||||
int safer_64_keysize(int *keysize);
|
||||
int safer_128_keysize(int *keysize);
|
||||
extern const struct ltc_cipher_descriptor safer_k64_desc, safer_k128_desc, safer_sk64_desc, safer_sk128_desc;
|
||||
@@ -348,6 +453,7 @@ extern const struct ltc_cipher_descriptor safer_k64_desc, safer_k128_desc, safer
|
||||
#define aes_ecb_encrypt rijndael_ecb_encrypt
|
||||
#define aes_ecb_decrypt rijndael_ecb_decrypt
|
||||
#define aes_test rijndael_test
|
||||
#define aes_done rijndael_done
|
||||
#define aes_keysize rijndael_keysize
|
||||
|
||||
#define aes_enc_setup rijndael_enc_setup
|
||||
@@ -358,9 +464,11 @@ int rijndael_setup(const unsigned char *key, int keylen, int num_rounds, symmetr
|
||||
void rijndael_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);
|
||||
void rijndael_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);
|
||||
int rijndael_test(void);
|
||||
void rijndael_done(symmetric_key *skey);
|
||||
int rijndael_keysize(int *keysize);
|
||||
int rijndael_enc_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
|
||||
void rijndael_enc_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);
|
||||
void rijndael_enc_done(symmetric_key *skey);
|
||||
int rijndael_enc_keysize(int *keysize);
|
||||
extern const struct ltc_cipher_descriptor rijndael_desc, aes_desc;
|
||||
extern const struct ltc_cipher_descriptor rijndael_enc_desc, aes_enc_desc;
|
||||
@@ -371,6 +479,7 @@ int xtea_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_k
|
||||
void xtea_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);
|
||||
void xtea_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);
|
||||
int xtea_test(void);
|
||||
void xtea_done(symmetric_key *skey);
|
||||
int xtea_keysize(int *keysize);
|
||||
extern const struct ltc_cipher_descriptor xtea_desc;
|
||||
#endif
|
||||
@@ -380,6 +489,7 @@ int twofish_setup(const unsigned char *key, int keylen, int num_rounds, symmetri
|
||||
void twofish_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);
|
||||
void twofish_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);
|
||||
int twofish_test(void);
|
||||
void twofish_done(symmetric_key *skey);
|
||||
int twofish_keysize(int *keysize);
|
||||
extern const struct ltc_cipher_descriptor twofish_desc;
|
||||
#endif
|
||||
@@ -389,11 +499,13 @@ int des_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_ke
|
||||
void des_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);
|
||||
void des_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);
|
||||
int des_test(void);
|
||||
void des_done(symmetric_key *skey);
|
||||
int des_keysize(int *keysize);
|
||||
int des3_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
|
||||
void des3_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);
|
||||
void des3_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);
|
||||
int des3_test(void);
|
||||
void des3_done(symmetric_key *skey);
|
||||
int des3_keysize(int *keysize);
|
||||
extern const struct ltc_cipher_descriptor des_desc, des3_desc;
|
||||
#endif
|
||||
@@ -403,6 +515,7 @@ int cast5_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_
|
||||
void cast5_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);
|
||||
void cast5_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);
|
||||
int cast5_test(void);
|
||||
void cast5_done(symmetric_key *skey);
|
||||
int cast5_keysize(int *keysize);
|
||||
extern const struct ltc_cipher_descriptor cast5_desc;
|
||||
#endif
|
||||
@@ -412,6 +525,7 @@ int noekeon_setup(const unsigned char *key, int keylen, int num_rounds, symmetri
|
||||
void noekeon_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);
|
||||
void noekeon_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);
|
||||
int noekeon_test(void);
|
||||
void noekeon_done(symmetric_key *skey);
|
||||
int noekeon_keysize(int *keysize);
|
||||
extern const struct ltc_cipher_descriptor noekeon_desc;
|
||||
#endif
|
||||
@@ -421,6 +535,7 @@ int skipjack_setup(const unsigned char *key, int keylen, int num_rounds, symmetr
|
||||
void skipjack_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);
|
||||
void skipjack_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);
|
||||
int skipjack_test(void);
|
||||
void skipjack_done(symmetric_key *skey);
|
||||
int skipjack_keysize(int *keysize);
|
||||
extern const struct ltc_cipher_descriptor skipjack_desc;
|
||||
#endif
|
||||
@@ -430,6 +545,7 @@ int khazad_setup(const unsigned char *key, int keylen, int num_rounds, symmetric
|
||||
void khazad_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);
|
||||
void khazad_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);
|
||||
int khazad_test(void);
|
||||
void khazad_done(symmetric_key *skey);
|
||||
int khazad_keysize(int *keysize);
|
||||
extern const struct ltc_cipher_descriptor khazad_desc;
|
||||
#endif
|
||||
@@ -439,6 +555,7 @@ int anubis_setup(const unsigned char *key, int keylen, int num_rounds, symmetric
|
||||
void anubis_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);
|
||||
void anubis_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);
|
||||
int anubis_test(void);
|
||||
void anubis_done(symmetric_key *skey);
|
||||
int anubis_keysize(int *keysize);
|
||||
extern const struct ltc_cipher_descriptor anubis_desc;
|
||||
#endif
|
||||
@@ -446,8 +563,9 @@ extern const struct ltc_cipher_descriptor anubis_desc;
|
||||
#ifdef ECB
|
||||
int ecb_start(int cipher, const unsigned char *key,
|
||||
int keylen, int num_rounds, symmetric_ECB *ecb);
|
||||
int ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_ECB *ecb);
|
||||
int ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_ECB *ecb);
|
||||
int ecb_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, symmetric_ECB *ecb);
|
||||
int ecb_decrypt(const unsigned char *ct, unsigned char *pt, unsigned long len, symmetric_ECB *ecb);
|
||||
int ecb_done(symmetric_ECB *ecb);
|
||||
#endif
|
||||
|
||||
#ifdef CFB
|
||||
@@ -457,6 +575,7 @@ int cfb_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, s
|
||||
int cfb_decrypt(const unsigned char *ct, unsigned char *pt, unsigned long len, symmetric_CFB *cfb);
|
||||
int cfb_getiv(unsigned char *IV, unsigned long *len, symmetric_CFB *cfb);
|
||||
int cfb_setiv(const unsigned char *IV, unsigned long len, symmetric_CFB *cfb);
|
||||
int cfb_done(symmetric_CFB *cfb);
|
||||
#endif
|
||||
|
||||
#ifdef OFB
|
||||
@@ -466,15 +585,17 @@ int ofb_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, s
|
||||
int ofb_decrypt(const unsigned char *ct, unsigned char *pt, unsigned long len, symmetric_OFB *ofb);
|
||||
int ofb_getiv(unsigned char *IV, unsigned long *len, symmetric_OFB *ofb);
|
||||
int ofb_setiv(const unsigned char *IV, unsigned long len, symmetric_OFB *ofb);
|
||||
int ofb_done(symmetric_OFB *ofb);
|
||||
#endif
|
||||
|
||||
#ifdef CBC
|
||||
int cbc_start(int cipher, const unsigned char *IV, const unsigned char *key,
|
||||
int keylen, int num_rounds, symmetric_CBC *cbc);
|
||||
int cbc_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_CBC *cbc);
|
||||
int cbc_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_CBC *cbc);
|
||||
int cbc_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, symmetric_CBC *cbc);
|
||||
int cbc_decrypt(const unsigned char *ct, unsigned char *pt, unsigned long len, symmetric_CBC *cbc);
|
||||
int cbc_getiv(unsigned char *IV, unsigned long *len, symmetric_CBC *cbc);
|
||||
int cbc_setiv(const unsigned char *IV, unsigned long len, symmetric_CBC *cbc);
|
||||
int cbc_done(symmetric_CBC *cbc);
|
||||
#endif
|
||||
|
||||
#ifdef CTR
|
||||
@@ -484,6 +605,7 @@ int ctr_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, s
|
||||
int ctr_decrypt(const unsigned char *ct, unsigned char *pt, unsigned long len, symmetric_CTR *ctr);
|
||||
int ctr_getiv(unsigned char *IV, unsigned long *len, symmetric_CTR *ctr);
|
||||
int ctr_setiv(const unsigned char *IV, unsigned long len, symmetric_CTR *ctr);
|
||||
int ctr_done(symmetric_CTR *ctr);
|
||||
#endif
|
||||
|
||||
int find_cipher(const char *name);
|
||||
|
||||
@@ -17,19 +17,25 @@
|
||||
#define XCLOCKS_PER_SEC CLOCKS_PER_SEC
|
||||
|
||||
/* Use small code where possible */
|
||||
// #define LTC_SMALL_CODE
|
||||
/* #define LTC_SMALL_CODE */
|
||||
|
||||
/* Enable self-test test vector checking */
|
||||
#define LTC_TEST
|
||||
|
||||
/* clean the stack of functions which put private information on stack */
|
||||
// #define LTC_CLEAN_STACK
|
||||
/* #define LTC_CLEAN_STACK */
|
||||
|
||||
/* disable all file related functions */
|
||||
// #define LTC_NO_FILE
|
||||
/* #define LTC_NO_FILE */
|
||||
|
||||
/* disable all forms of ASM */
|
||||
// #define LTC_NO_ASM
|
||||
/* #define LTC_NO_ASM */
|
||||
|
||||
/* disable FAST mode */
|
||||
/* #define LTC_NO_FAST */
|
||||
|
||||
/* disable BSWAP on x86 */
|
||||
/* #define LTC_NO_BSWAP */
|
||||
|
||||
/* ---> Symmetric Block Ciphers <--- */
|
||||
#define BLOWFISH
|
||||
@@ -43,17 +49,14 @@
|
||||
* (saves 4KB of ram), _ALL_TABLES enables all tables during setup */
|
||||
#define TWOFISH
|
||||
#define TWOFISH_TABLES
|
||||
// #define TWOFISH_ALL_TABLES
|
||||
// #define TWOFISH_SMALL
|
||||
/* #define TWOFISH_ALL_TABLES */
|
||||
/* #define TWOFISH_SMALL */
|
||||
/* DES includes EDE triple-DES */
|
||||
#define DES
|
||||
#define CAST5
|
||||
#define NOEKEON
|
||||
#define SKIPJACK
|
||||
/* SAFER code isn't public domain. It appears to be free to use
|
||||
* but has been disabled by default to avoid any such problems
|
||||
*/
|
||||
//#define SAFER
|
||||
#define SAFER
|
||||
#define KHAZAD
|
||||
#define ANUBIS
|
||||
#define ANUBIS_TWEAK
|
||||
@@ -85,6 +88,11 @@
|
||||
#define HMAC
|
||||
#define OMAC
|
||||
#define PMAC
|
||||
#define PELICAN
|
||||
|
||||
#if defined(PELICAN) && !defined(RIJNDAEL)
|
||||
#error Pelican-MAC requires RIJNDAEL
|
||||
#endif
|
||||
|
||||
/* ---> Encrypt + Authenticate Modes <--- */
|
||||
#define EAX_MODE
|
||||
@@ -93,6 +101,11 @@
|
||||
#endif
|
||||
|
||||
#define OCB_MODE
|
||||
#define CCM_MODE
|
||||
|
||||
#define GCM_MODE
|
||||
/* Use 64KiB tables */
|
||||
#define GCM_TABLES
|
||||
|
||||
/* Various tidbits of modern neatoness */
|
||||
#define BASE64
|
||||
@@ -100,8 +113,8 @@
|
||||
/* --> Pseudo Random Number Generators <--- */
|
||||
/* Yarrow */
|
||||
#define YARROW
|
||||
// which descriptor of AES to use?
|
||||
// 0 = rijndael_enc 1 = aes_enc, 2 = rijndael [full], 3 = aes [full]
|
||||
/* which descriptor of AES to use? */
|
||||
/* 0 = rijndael_enc 1 = aes_enc, 2 = rijndael [full], 3 = aes [full] */
|
||||
#define YARROW_AES 0
|
||||
|
||||
#if defined(YARROW) && !defined(CTR)
|
||||
|
||||
+1
-195
@@ -120,6 +120,7 @@ typedef union Hash_state {
|
||||
#ifdef RIPEMD160
|
||||
struct rmd160_state rmd160;
|
||||
#endif
|
||||
void *data;
|
||||
} hash_state;
|
||||
|
||||
extern struct ltc_hash_descriptor {
|
||||
@@ -321,198 +322,3 @@ int func_name (hash_state * md, const unsigned char *in, unsigned long inlen)
|
||||
} \
|
||||
return CRYPT_OK; \
|
||||
}
|
||||
|
||||
#ifdef HMAC
|
||||
typedef struct Hmac_state {
|
||||
hash_state md;
|
||||
int hash;
|
||||
hash_state hashstate;
|
||||
unsigned char *key;
|
||||
} hmac_state;
|
||||
|
||||
int hmac_init(hmac_state *hmac, int hash, const unsigned char *key, unsigned long keylen);
|
||||
int hmac_process(hmac_state *hmac, const unsigned char *in, unsigned long inlen);
|
||||
int hmac_done(hmac_state *hmac, unsigned char *out, unsigned long *outlen);
|
||||
int hmac_test(void);
|
||||
int hmac_memory(int hash,
|
||||
const unsigned char *key, unsigned long keylen,
|
||||
const unsigned char *in, unsigned long inlen,
|
||||
unsigned char *out, unsigned long *outlen);
|
||||
int hmac_memory_multi(int hash,
|
||||
const unsigned char *key, unsigned long keylen,
|
||||
unsigned char *out, unsigned long *outlen,
|
||||
const unsigned char *in, unsigned long inlen, ...);
|
||||
int hmac_file(int hash, const char *fname, const unsigned char *key,
|
||||
unsigned long keylen,
|
||||
unsigned char *dst, unsigned long *dstlen);
|
||||
#endif
|
||||
|
||||
#ifdef OMAC
|
||||
|
||||
typedef struct {
|
||||
int cipher_idx,
|
||||
buflen,
|
||||
blklen;
|
||||
unsigned char block[MAXBLOCKSIZE],
|
||||
prev[MAXBLOCKSIZE],
|
||||
Lu[2][MAXBLOCKSIZE];
|
||||
symmetric_key key;
|
||||
} omac_state;
|
||||
|
||||
int omac_init(omac_state *omac, int cipher, const unsigned char *key, unsigned long keylen);
|
||||
int omac_process(omac_state *omac, const unsigned char *in, unsigned long inlen);
|
||||
int omac_done(omac_state *omac, unsigned char *out, unsigned long *outlen);
|
||||
int omac_memory(int cipher,
|
||||
const unsigned char *key, unsigned long keylen,
|
||||
const unsigned char *in, unsigned long inlen,
|
||||
unsigned char *out, unsigned long *outlen);
|
||||
int omac_memory_multi(int cipher,
|
||||
const unsigned char *key, unsigned long keylen,
|
||||
unsigned char *out, unsigned long *outlen,
|
||||
const unsigned char *in, unsigned long inlen, ...);
|
||||
int omac_file(int cipher,
|
||||
const unsigned char *key, unsigned long keylen,
|
||||
const char *filename,
|
||||
unsigned char *out, unsigned long *outlen);
|
||||
int omac_test(void);
|
||||
#endif /* OMAC */
|
||||
|
||||
#ifdef PMAC
|
||||
|
||||
typedef struct {
|
||||
unsigned char Ls[32][MAXBLOCKSIZE], /* L shifted by i bits to the left */
|
||||
Li[MAXBLOCKSIZE], /* value of Li [current value, we calc from previous recall] */
|
||||
Lr[MAXBLOCKSIZE], /* L * x^-1 */
|
||||
block[MAXBLOCKSIZE], /* currently accumulated block */
|
||||
checksum[MAXBLOCKSIZE]; /* current checksum */
|
||||
|
||||
symmetric_key key; /* scheduled key for cipher */
|
||||
unsigned long block_index; /* index # for current block */
|
||||
int cipher_idx, /* cipher idx */
|
||||
block_len, /* length of block */
|
||||
buflen; /* number of bytes in the buffer */
|
||||
} pmac_state;
|
||||
|
||||
int pmac_init(pmac_state *pmac, int cipher, const unsigned char *key, unsigned long keylen);
|
||||
int pmac_process(pmac_state *pmac, const unsigned char *in, unsigned long inlen);
|
||||
int pmac_done(pmac_state *pmac, unsigned char *out, unsigned long *outlen);
|
||||
|
||||
int pmac_memory(int cipher,
|
||||
const unsigned char *key, unsigned long keylen,
|
||||
const unsigned char *msg, unsigned long msglen,
|
||||
unsigned char *out, unsigned long *outlen);
|
||||
|
||||
int pmac_memory_multi(int cipher,
|
||||
const unsigned char *key, unsigned long keylen,
|
||||
unsigned char *out, unsigned long *outlen,
|
||||
const unsigned char *in, unsigned long inlen, ...);
|
||||
|
||||
int pmac_file(int cipher,
|
||||
const unsigned char *key, unsigned long keylen,
|
||||
const char *filename,
|
||||
unsigned char *out, unsigned long *outlen);
|
||||
|
||||
int pmac_test(void);
|
||||
|
||||
/* internal functions */
|
||||
int pmac_ntz(unsigned long x);
|
||||
void pmac_shift_xor(pmac_state *pmac);
|
||||
|
||||
#endif /* PMAC */
|
||||
|
||||
#ifdef EAX_MODE
|
||||
|
||||
#if !(defined(OMAC) && defined(CTR))
|
||||
#error EAX_MODE requires OMAC and CTR
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
unsigned char N[MAXBLOCKSIZE];
|
||||
symmetric_CTR ctr;
|
||||
omac_state headeromac, ctomac;
|
||||
} eax_state;
|
||||
|
||||
int eax_init(eax_state *eax, int cipher, const unsigned char *key, unsigned long keylen,
|
||||
const unsigned char *nonce, unsigned long noncelen,
|
||||
const unsigned char *header, unsigned long headerlen);
|
||||
|
||||
int eax_encrypt(eax_state *eax, const unsigned char *pt, unsigned char *ct, unsigned long length);
|
||||
int eax_decrypt(eax_state *eax, const unsigned char *ct, unsigned char *pt, unsigned long length);
|
||||
int eax_addheader(eax_state *eax, const unsigned char *header, unsigned long length);
|
||||
int eax_done(eax_state *eax, unsigned char *tag, unsigned long *taglen);
|
||||
|
||||
int eax_encrypt_authenticate_memory(int cipher,
|
||||
const unsigned char *key, unsigned long keylen,
|
||||
const unsigned char *nonce, unsigned long noncelen,
|
||||
const unsigned char *header, unsigned long headerlen,
|
||||
const unsigned char *pt, unsigned long ptlen,
|
||||
unsigned char *ct,
|
||||
unsigned char *tag, unsigned long *taglen);
|
||||
|
||||
int eax_decrypt_verify_memory(int cipher,
|
||||
const unsigned char *key, unsigned long keylen,
|
||||
const unsigned char *nonce, unsigned long noncelen,
|
||||
const unsigned char *header, unsigned long headerlen,
|
||||
const unsigned char *ct, unsigned long ctlen,
|
||||
unsigned char *pt,
|
||||
unsigned char *tag, unsigned long taglen,
|
||||
int *stat);
|
||||
|
||||
int eax_test(void);
|
||||
#endif /* EAX MODE */
|
||||
|
||||
#ifdef OCB_MODE
|
||||
typedef struct {
|
||||
unsigned char L[MAXBLOCKSIZE], /* L value */
|
||||
Ls[32][MAXBLOCKSIZE], /* L shifted by i bits to the left */
|
||||
Li[MAXBLOCKSIZE], /* value of Li [current value, we calc from previous recall] */
|
||||
Lr[MAXBLOCKSIZE], /* L * x^-1 */
|
||||
R[MAXBLOCKSIZE], /* R value */
|
||||
checksum[MAXBLOCKSIZE]; /* current checksum */
|
||||
|
||||
symmetric_key key; /* scheduled key for cipher */
|
||||
unsigned long block_index; /* index # for current block */
|
||||
int cipher, /* cipher idx */
|
||||
block_len; /* length of block */
|
||||
} ocb_state;
|
||||
|
||||
int ocb_init(ocb_state *ocb, int cipher,
|
||||
const unsigned char *key, unsigned long keylen, const unsigned char *nonce);
|
||||
|
||||
int ocb_encrypt(ocb_state *ocb, const unsigned char *pt, unsigned char *ct);
|
||||
int ocb_decrypt(ocb_state *ocb, const unsigned char *ct, unsigned char *pt);
|
||||
|
||||
int ocb_done_encrypt(ocb_state *ocb,
|
||||
const unsigned char *pt, unsigned long ptlen,
|
||||
unsigned char *ct,
|
||||
unsigned char *tag, unsigned long *taglen);
|
||||
|
||||
int ocb_done_decrypt(ocb_state *ocb,
|
||||
const unsigned char *ct, unsigned long ctlen,
|
||||
unsigned char *pt,
|
||||
const unsigned char *tag, unsigned long taglen, int *stat);
|
||||
|
||||
int ocb_encrypt_authenticate_memory(int cipher,
|
||||
const unsigned char *key, unsigned long keylen,
|
||||
const unsigned char *nonce,
|
||||
const unsigned char *pt, unsigned long ptlen,
|
||||
unsigned char *ct,
|
||||
unsigned char *tag, unsigned long *taglen);
|
||||
|
||||
int ocb_decrypt_verify_memory(int cipher,
|
||||
const unsigned char *key, unsigned long keylen,
|
||||
const unsigned char *nonce,
|
||||
const unsigned char *ct, unsigned long ctlen,
|
||||
unsigned char *pt,
|
||||
const unsigned char *tag, unsigned long taglen,
|
||||
int *stat);
|
||||
|
||||
int ocb_test(void);
|
||||
|
||||
/* internal functions */
|
||||
void ocb_shift_xor(ocb_state *ocb, unsigned char *Z);
|
||||
int ocb_ntz(unsigned long x);
|
||||
int s_ocb_done(ocb_state *ocb, const unsigned char *pt, unsigned long ptlen,
|
||||
unsigned char *ct, unsigned char *tag, unsigned long *taglen, int mode);
|
||||
|
||||
#endif /* OCB_MODE */
|
||||
|
||||
@@ -0,0 +1,297 @@
|
||||
#ifdef HMAC
|
||||
typedef struct Hmac_state {
|
||||
hash_state md;
|
||||
int hash;
|
||||
hash_state hashstate;
|
||||
unsigned char *key;
|
||||
} hmac_state;
|
||||
|
||||
int hmac_init(hmac_state *hmac, int hash, const unsigned char *key, unsigned long keylen);
|
||||
int hmac_process(hmac_state *hmac, const unsigned char *in, unsigned long inlen);
|
||||
int hmac_done(hmac_state *hmac, unsigned char *out, unsigned long *outlen);
|
||||
int hmac_test(void);
|
||||
int hmac_memory(int hash,
|
||||
const unsigned char *key, unsigned long keylen,
|
||||
const unsigned char *in, unsigned long inlen,
|
||||
unsigned char *out, unsigned long *outlen);
|
||||
int hmac_memory_multi(int hash,
|
||||
const unsigned char *key, unsigned long keylen,
|
||||
unsigned char *out, unsigned long *outlen,
|
||||
const unsigned char *in, unsigned long inlen, ...);
|
||||
int hmac_file(int hash, const char *fname, const unsigned char *key,
|
||||
unsigned long keylen,
|
||||
unsigned char *dst, unsigned long *dstlen);
|
||||
#endif
|
||||
|
||||
#ifdef OMAC
|
||||
|
||||
typedef struct {
|
||||
int cipher_idx,
|
||||
buflen,
|
||||
blklen;
|
||||
unsigned char block[MAXBLOCKSIZE],
|
||||
prev[MAXBLOCKSIZE],
|
||||
Lu[2][MAXBLOCKSIZE];
|
||||
symmetric_key key;
|
||||
} omac_state;
|
||||
|
||||
int omac_init(omac_state *omac, int cipher, const unsigned char *key, unsigned long keylen);
|
||||
int omac_process(omac_state *omac, const unsigned char *in, unsigned long inlen);
|
||||
int omac_done(omac_state *omac, unsigned char *out, unsigned long *outlen);
|
||||
int omac_memory(int cipher,
|
||||
const unsigned char *key, unsigned long keylen,
|
||||
const unsigned char *in, unsigned long inlen,
|
||||
unsigned char *out, unsigned long *outlen);
|
||||
int omac_memory_multi(int cipher,
|
||||
const unsigned char *key, unsigned long keylen,
|
||||
unsigned char *out, unsigned long *outlen,
|
||||
const unsigned char *in, unsigned long inlen, ...);
|
||||
int omac_file(int cipher,
|
||||
const unsigned char *key, unsigned long keylen,
|
||||
const char *filename,
|
||||
unsigned char *out, unsigned long *outlen);
|
||||
int omac_test(void);
|
||||
#endif /* OMAC */
|
||||
|
||||
#ifdef PMAC
|
||||
|
||||
typedef struct {
|
||||
unsigned char Ls[32][MAXBLOCKSIZE], /* L shifted by i bits to the left */
|
||||
Li[MAXBLOCKSIZE], /* value of Li [current value, we calc from previous recall] */
|
||||
Lr[MAXBLOCKSIZE], /* L * x^-1 */
|
||||
block[MAXBLOCKSIZE], /* currently accumulated block */
|
||||
checksum[MAXBLOCKSIZE]; /* current checksum */
|
||||
|
||||
symmetric_key key; /* scheduled key for cipher */
|
||||
unsigned long block_index; /* index # for current block */
|
||||
int cipher_idx, /* cipher idx */
|
||||
block_len, /* length of block */
|
||||
buflen; /* number of bytes in the buffer */
|
||||
} pmac_state;
|
||||
|
||||
int pmac_init(pmac_state *pmac, int cipher, const unsigned char *key, unsigned long keylen);
|
||||
int pmac_process(pmac_state *pmac, const unsigned char *in, unsigned long inlen);
|
||||
int pmac_done(pmac_state *pmac, unsigned char *out, unsigned long *outlen);
|
||||
|
||||
int pmac_memory(int cipher,
|
||||
const unsigned char *key, unsigned long keylen,
|
||||
const unsigned char *msg, unsigned long msglen,
|
||||
unsigned char *out, unsigned long *outlen);
|
||||
|
||||
int pmac_memory_multi(int cipher,
|
||||
const unsigned char *key, unsigned long keylen,
|
||||
unsigned char *out, unsigned long *outlen,
|
||||
const unsigned char *in, unsigned long inlen, ...);
|
||||
|
||||
int pmac_file(int cipher,
|
||||
const unsigned char *key, unsigned long keylen,
|
||||
const char *filename,
|
||||
unsigned char *out, unsigned long *outlen);
|
||||
|
||||
int pmac_test(void);
|
||||
|
||||
/* internal functions */
|
||||
int pmac_ntz(unsigned long x);
|
||||
void pmac_shift_xor(pmac_state *pmac);
|
||||
|
||||
#endif /* PMAC */
|
||||
|
||||
#ifdef EAX_MODE
|
||||
|
||||
#if !(defined(OMAC) && defined(CTR))
|
||||
#error EAX_MODE requires OMAC and CTR
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
unsigned char N[MAXBLOCKSIZE];
|
||||
symmetric_CTR ctr;
|
||||
omac_state headeromac, ctomac;
|
||||
} eax_state;
|
||||
|
||||
int eax_init(eax_state *eax, int cipher, const unsigned char *key, unsigned long keylen,
|
||||
const unsigned char *nonce, unsigned long noncelen,
|
||||
const unsigned char *header, unsigned long headerlen);
|
||||
|
||||
int eax_encrypt(eax_state *eax, const unsigned char *pt, unsigned char *ct, unsigned long length);
|
||||
int eax_decrypt(eax_state *eax, const unsigned char *ct, unsigned char *pt, unsigned long length);
|
||||
int eax_addheader(eax_state *eax, const unsigned char *header, unsigned long length);
|
||||
int eax_done(eax_state *eax, unsigned char *tag, unsigned long *taglen);
|
||||
|
||||
int eax_encrypt_authenticate_memory(int cipher,
|
||||
const unsigned char *key, unsigned long keylen,
|
||||
const unsigned char *nonce, unsigned long noncelen,
|
||||
const unsigned char *header, unsigned long headerlen,
|
||||
const unsigned char *pt, unsigned long ptlen,
|
||||
unsigned char *ct,
|
||||
unsigned char *tag, unsigned long *taglen);
|
||||
|
||||
int eax_decrypt_verify_memory(int cipher,
|
||||
const unsigned char *key, unsigned long keylen,
|
||||
const unsigned char *nonce, unsigned long noncelen,
|
||||
const unsigned char *header, unsigned long headerlen,
|
||||
const unsigned char *ct, unsigned long ctlen,
|
||||
unsigned char *pt,
|
||||
unsigned char *tag, unsigned long taglen,
|
||||
int *stat);
|
||||
|
||||
int eax_test(void);
|
||||
#endif /* EAX MODE */
|
||||
|
||||
#ifdef OCB_MODE
|
||||
typedef struct {
|
||||
unsigned char L[MAXBLOCKSIZE], /* L value */
|
||||
Ls[32][MAXBLOCKSIZE], /* L shifted by i bits to the left */
|
||||
Li[MAXBLOCKSIZE], /* value of Li [current value, we calc from previous recall] */
|
||||
Lr[MAXBLOCKSIZE], /* L * x^-1 */
|
||||
R[MAXBLOCKSIZE], /* R value */
|
||||
checksum[MAXBLOCKSIZE]; /* current checksum */
|
||||
|
||||
symmetric_key key; /* scheduled key for cipher */
|
||||
unsigned long block_index; /* index # for current block */
|
||||
int cipher, /* cipher idx */
|
||||
block_len; /* length of block */
|
||||
} ocb_state;
|
||||
|
||||
int ocb_init(ocb_state *ocb, int cipher,
|
||||
const unsigned char *key, unsigned long keylen, const unsigned char *nonce);
|
||||
|
||||
int ocb_encrypt(ocb_state *ocb, const unsigned char *pt, unsigned char *ct);
|
||||
int ocb_decrypt(ocb_state *ocb, const unsigned char *ct, unsigned char *pt);
|
||||
|
||||
int ocb_done_encrypt(ocb_state *ocb,
|
||||
const unsigned char *pt, unsigned long ptlen,
|
||||
unsigned char *ct,
|
||||
unsigned char *tag, unsigned long *taglen);
|
||||
|
||||
int ocb_done_decrypt(ocb_state *ocb,
|
||||
const unsigned char *ct, unsigned long ctlen,
|
||||
unsigned char *pt,
|
||||
const unsigned char *tag, unsigned long taglen, int *stat);
|
||||
|
||||
int ocb_encrypt_authenticate_memory(int cipher,
|
||||
const unsigned char *key, unsigned long keylen,
|
||||
const unsigned char *nonce,
|
||||
const unsigned char *pt, unsigned long ptlen,
|
||||
unsigned char *ct,
|
||||
unsigned char *tag, unsigned long *taglen);
|
||||
|
||||
int ocb_decrypt_verify_memory(int cipher,
|
||||
const unsigned char *key, unsigned long keylen,
|
||||
const unsigned char *nonce,
|
||||
const unsigned char *ct, unsigned long ctlen,
|
||||
unsigned char *pt,
|
||||
const unsigned char *tag, unsigned long taglen,
|
||||
int *stat);
|
||||
|
||||
int ocb_test(void);
|
||||
|
||||
/* internal functions */
|
||||
void ocb_shift_xor(ocb_state *ocb, unsigned char *Z);
|
||||
int ocb_ntz(unsigned long x);
|
||||
int s_ocb_done(ocb_state *ocb, const unsigned char *pt, unsigned long ptlen,
|
||||
unsigned char *ct, unsigned char *tag, unsigned long *taglen, int mode);
|
||||
|
||||
#endif /* OCB_MODE */
|
||||
|
||||
#ifdef CCM_MODE
|
||||
|
||||
#define CCM_ENCRYPT 0
|
||||
#define CCM_DECRYPT 1
|
||||
|
||||
int ccm_memory(int cipher,
|
||||
const unsigned char *key, unsigned long keylen,
|
||||
const unsigned char *nonce, unsigned long noncelen,
|
||||
const unsigned char *header, unsigned long headerlen,
|
||||
unsigned char *pt, unsigned long ptlen,
|
||||
unsigned char *ct,
|
||||
unsigned char *tag, unsigned long *taglen,
|
||||
int direction);
|
||||
|
||||
int ccm_test(void);
|
||||
|
||||
#endif /* CCM_MODE */
|
||||
|
||||
#ifdef GCM_MODE
|
||||
|
||||
#define GCM_ENCRYPT 0
|
||||
#define GCM_DECRYPT 1
|
||||
|
||||
#define GCM_MODE_IV 0
|
||||
#define GCM_MODE_AAD 1
|
||||
#define GCM_MODE_TEXT 2
|
||||
|
||||
typedef struct {
|
||||
symmetric_key K;
|
||||
unsigned char H[16], /* multiplier */
|
||||
X[16], /* accumulator */
|
||||
Y[16], /* counter */
|
||||
Y_0[16], /* initial counter */
|
||||
buf[16]; /* buffer for stuff */
|
||||
|
||||
int cipher, /* which cipher */
|
||||
ivmode, /* Which mode is the IV in? */
|
||||
mode, /* mode the GCM code is in */
|
||||
buflen; /* length of data in buf */
|
||||
|
||||
ulong64 totlen, /* 64-bit counter used for IV and AAD */
|
||||
pttotlen; /* 64-bit counter for the PT */
|
||||
|
||||
#ifdef GCM_TABLES
|
||||
unsigned char PC[16][256][16]; /* 16 tables of 8x128 */
|
||||
#endif
|
||||
|
||||
} gcm_state;
|
||||
|
||||
void gcm_gf_mult(const unsigned char *a, const unsigned char *b, unsigned char *c);
|
||||
void gcm_mult_h(gcm_state *gcm, unsigned char *I);
|
||||
|
||||
int gcm_init(gcm_state *gcm, int cipher,
|
||||
const unsigned char *key, int keylen);
|
||||
|
||||
int gcm_reset(gcm_state *gcm);
|
||||
|
||||
int gcm_add_iv(gcm_state *gcm,
|
||||
const unsigned char *IV, unsigned long IVlen);
|
||||
|
||||
int gcm_add_aad(gcm_state *gcm,
|
||||
const unsigned char *adata, unsigned long adatalen);
|
||||
|
||||
int gcm_process(gcm_state *gcm,
|
||||
unsigned char *pt, unsigned long ptlen,
|
||||
unsigned char *ct,
|
||||
int direction);
|
||||
|
||||
int gcm_done(gcm_state *gcm,
|
||||
unsigned char *tag, unsigned long *taglen);
|
||||
|
||||
int gcm_memory( int cipher,
|
||||
const unsigned char *key, unsigned long keylen,
|
||||
const unsigned char *IV, unsigned long IVlen,
|
||||
const unsigned char *adata, unsigned long adatalen,
|
||||
unsigned char *pt, unsigned long ptlen,
|
||||
unsigned char *ct,
|
||||
unsigned char *tag, unsigned long *taglen,
|
||||
int direction);
|
||||
int gcm_test(void);
|
||||
|
||||
#endif /* GCM_MODE */
|
||||
|
||||
#ifdef PELICAN
|
||||
|
||||
typedef struct pelican_state
|
||||
{
|
||||
symmetric_key K;
|
||||
unsigned char state[16];
|
||||
int buflen;
|
||||
} pelican_state;
|
||||
|
||||
int pelican_init(pelican_state *pelmac, const unsigned char *key, unsigned long keylen);
|
||||
int pelican_process(pelican_state *pelmac, const unsigned char *in, unsigned long inlen);
|
||||
int pelican_done(pelican_state *pelmac, unsigned char *out);
|
||||
int pelican_test(void);
|
||||
|
||||
int pelican_memory(const unsigned char *key, unsigned long keylen,
|
||||
const unsigned char *in, unsigned long inlen,
|
||||
unsigned char *out);
|
||||
|
||||
#endif
|
||||
@@ -67,6 +67,23 @@
|
||||
|
||||
#ifdef ENDIAN_LITTLE
|
||||
|
||||
#if !defined(LTC_NO_BSWAP) && (defined(INTEL_CC) || (defined(__GNUC__) && (defined(__DJGPP__) || defined(__CYGWIN__) || defined(__MINGW32__) || defined(__i386__) || defined(__x86_64__))))
|
||||
|
||||
#define STORE32H(x, y) \
|
||||
asm __volatile__ ( \
|
||||
"bswapl %0 \n\t" \
|
||||
"movl %0,(%2)\n\t" \
|
||||
"bswapl %0 \n\t" \
|
||||
:"=r"(x):"0"(x), "r"(y));
|
||||
|
||||
#define LOAD32H(x, y) \
|
||||
asm __volatile__ ( \
|
||||
"movl (%2),%0\n\t" \
|
||||
"bswapl %0\n\t" \
|
||||
:"=r"(x): "0"(x), "r"(y));
|
||||
|
||||
#else
|
||||
|
||||
#define STORE32H(x, y) \
|
||||
{ (y)[0] = (unsigned char)(((x)>>24)&255); (y)[1] = (unsigned char)(((x)>>16)&255); \
|
||||
(y)[2] = (unsigned char)(((x)>>8)&255); (y)[3] = (unsigned char)((x)&255); }
|
||||
@@ -77,6 +94,27 @@
|
||||
((unsigned long)((y)[2] & 255)<<8) | \
|
||||
((unsigned long)((y)[3] & 255)); }
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/* x86_64 processor */
|
||||
#if !defined(LTC_NO_BSWAP) && (defined(__GNUC__) && defined(__x86_64__))
|
||||
|
||||
#define STORE64H(x, y) \
|
||||
asm __volatile__ ( \
|
||||
"bswapq %0 \n\t" \
|
||||
"movq %0,(%2)\n\t" \
|
||||
"bswapq %0 \n\t" \
|
||||
:"=r"(x):"0"(x), "r"(y):"0");
|
||||
|
||||
#define LOAD64H(x, y) \
|
||||
asm __volatile__ ( \
|
||||
"movq (%2),%0\n\t" \
|
||||
"bswapq %0\n\t" \
|
||||
:"=r"(x): "0"(x), "r"(y));
|
||||
|
||||
#else
|
||||
|
||||
#define STORE64H(x, y) \
|
||||
{ (y)[0] = (unsigned char)(((x)>>56)&255); (y)[1] = (unsigned char)(((x)>>48)&255); \
|
||||
(y)[2] = (unsigned char)(((x)>>40)&255); (y)[3] = (unsigned char)(((x)>>32)&255); \
|
||||
@@ -89,6 +127,8 @@
|
||||
(((ulong64)((y)[4] & 255))<<24)|(((ulong64)((y)[5] & 255))<<16) | \
|
||||
(((ulong64)((y)[6] & 255))<<8)|(((ulong64)((y)[7] & 255))); }
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef ENDIAN_32BITWORD
|
||||
|
||||
#define STORE32L(x, y) \
|
||||
@@ -295,8 +335,8 @@ static inline unsigned long ROR64c(unsigned long word, const int i)
|
||||
|
||||
#else /* LTC_NO_ROLC */
|
||||
|
||||
#define ROL64c ROL
|
||||
#define ROR64c ROR
|
||||
#define ROL64c ROL64
|
||||
#define ROR64c ROR64
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -193,7 +193,7 @@ int dh_verify_hash(const unsigned char *sig, unsigned long siglen,
|
||||
/* ---- ECC Routines ---- */
|
||||
#ifdef MECC
|
||||
typedef struct {
|
||||
mp_int x, y;
|
||||
mp_int x, y, z;
|
||||
} ecc_point;
|
||||
|
||||
typedef struct {
|
||||
|
||||
@@ -90,8 +90,11 @@
|
||||
#define BN_MP_READ_UNSIGNED_BIN_C
|
||||
#define BN_MP_REDUCE_C
|
||||
#define BN_MP_REDUCE_2K_C
|
||||
#define BN_MP_REDUCE_2K_L_C
|
||||
#define BN_MP_REDUCE_2K_SETUP_C
|
||||
#define BN_MP_REDUCE_2K_SETUP_L_C
|
||||
#define BN_MP_REDUCE_IS_2K_C
|
||||
#define BN_MP_REDUCE_IS_2K_L_C
|
||||
#define BN_MP_REDUCE_SETUP_C
|
||||
#define BN_MP_RSHD_C
|
||||
#define BN_MP_SET_C
|
||||
@@ -105,7 +108,9 @@
|
||||
#define BN_MP_SUB_D_C
|
||||
#define BN_MP_SUBMOD_C
|
||||
#define BN_MP_TO_SIGNED_BIN_C
|
||||
#define BN_MP_TO_SIGNED_BIN_N_C
|
||||
#define BN_MP_TO_UNSIGNED_BIN_C
|
||||
#define BN_MP_TO_UNSIGNED_BIN_N_C
|
||||
#define BN_MP_TOOM_MUL_C
|
||||
#define BN_MP_TOOM_SQR_C
|
||||
#define BN_MP_TORADIX_C
|
||||
@@ -132,7 +137,7 @@
|
||||
#define BN_MP_ISEVEN_C
|
||||
#define BN_MP_INIT_MULTI_C
|
||||
#define BN_MP_COPY_C
|
||||
#define BN_MP_ABS_C
|
||||
#define BN_MP_MOD_C
|
||||
#define BN_MP_SET_C
|
||||
#define BN_MP_DIV_2_C
|
||||
#define BN_MP_ISODD_C
|
||||
@@ -324,11 +329,12 @@
|
||||
#define BN_MP_CLEAR_C
|
||||
#define BN_MP_ABS_C
|
||||
#define BN_MP_CLEAR_MULTI_C
|
||||
#define BN_MP_REDUCE_IS_2K_L_C
|
||||
#define BN_S_MP_EXPTMOD_C
|
||||
#define BN_MP_DR_IS_MODULUS_C
|
||||
#define BN_MP_REDUCE_IS_2K_C
|
||||
#define BN_MP_ISODD_C
|
||||
#define BN_MP_EXPTMOD_FAST_C
|
||||
#define BN_S_MP_EXPTMOD_C
|
||||
#endif
|
||||
|
||||
#if defined(BN_MP_EXPTMOD_FAST_C)
|
||||
@@ -360,6 +366,7 @@
|
||||
#define BN_MP_DIV_C
|
||||
#define BN_MP_MUL_C
|
||||
#define BN_MP_SUB_C
|
||||
#define BN_MP_NEG_C
|
||||
#define BN_MP_EXCH_C
|
||||
#define BN_MP_CLEAR_MULTI_C
|
||||
#endif
|
||||
@@ -434,6 +441,7 @@
|
||||
#if defined(BN_MP_INVMOD_SLOW_C)
|
||||
#define BN_MP_ISZERO_C
|
||||
#define BN_MP_INIT_MULTI_C
|
||||
#define BN_MP_MOD_C
|
||||
#define BN_MP_COPY_C
|
||||
#define BN_MP_ISEVEN_C
|
||||
#define BN_MP_SET_C
|
||||
@@ -659,9 +667,9 @@
|
||||
#endif
|
||||
|
||||
#if defined(BN_MP_RADIX_SIZE_C)
|
||||
#define BN_MP_ISZERO_C
|
||||
#define BN_MP_COUNT_BITS_C
|
||||
#define BN_MP_INIT_COPY_C
|
||||
#define BN_MP_ISZERO_C
|
||||
#define BN_MP_DIV_D_C
|
||||
#define BN_MP_CLEAR_C
|
||||
#endif
|
||||
@@ -700,8 +708,8 @@
|
||||
#define BN_MP_INIT_COPY_C
|
||||
#define BN_MP_RSHD_C
|
||||
#define BN_MP_MUL_C
|
||||
#define BN_FAST_S_MP_MUL_HIGH_DIGS_C
|
||||
#define BN_S_MP_MUL_HIGH_DIGS_C
|
||||
#define BN_FAST_S_MP_MUL_HIGH_DIGS_C
|
||||
#define BN_MP_MOD_2D_C
|
||||
#define BN_S_MP_MUL_DIGS_C
|
||||
#define BN_MP_SUB_C
|
||||
@@ -725,6 +733,17 @@
|
||||
#define BN_MP_CLEAR_C
|
||||
#endif
|
||||
|
||||
#if defined(BN_MP_REDUCE_2K_L_C)
|
||||
#define BN_MP_INIT_C
|
||||
#define BN_MP_COUNT_BITS_C
|
||||
#define BN_MP_DIV_2D_C
|
||||
#define BN_MP_MUL_C
|
||||
#define BN_S_MP_ADD_C
|
||||
#define BN_MP_CMP_MAG_C
|
||||
#define BN_S_MP_SUB_C
|
||||
#define BN_MP_CLEAR_C
|
||||
#endif
|
||||
|
||||
#if defined(BN_MP_REDUCE_2K_SETUP_C)
|
||||
#define BN_MP_INIT_C
|
||||
#define BN_MP_COUNT_BITS_C
|
||||
@@ -733,11 +752,22 @@
|
||||
#define BN_S_MP_SUB_C
|
||||
#endif
|
||||
|
||||
#if defined(BN_MP_REDUCE_2K_SETUP_L_C)
|
||||
#define BN_MP_INIT_C
|
||||
#define BN_MP_2EXPT_C
|
||||
#define BN_MP_COUNT_BITS_C
|
||||
#define BN_S_MP_SUB_C
|
||||
#define BN_MP_CLEAR_C
|
||||
#endif
|
||||
|
||||
#if defined(BN_MP_REDUCE_IS_2K_C)
|
||||
#define BN_MP_REDUCE_2K_C
|
||||
#define BN_MP_COUNT_BITS_C
|
||||
#endif
|
||||
|
||||
#if defined(BN_MP_REDUCE_IS_2K_L_C)
|
||||
#endif
|
||||
|
||||
#if defined(BN_MP_REDUCE_SETUP_C)
|
||||
#define BN_MP_2EXPT_C
|
||||
#define BN_MP_DIV_C
|
||||
@@ -815,6 +845,11 @@
|
||||
#define BN_MP_TO_UNSIGNED_BIN_C
|
||||
#endif
|
||||
|
||||
#if defined(BN_MP_TO_SIGNED_BIN_N_C)
|
||||
#define BN_MP_SIGNED_BIN_SIZE_C
|
||||
#define BN_MP_TO_SIGNED_BIN_C
|
||||
#endif
|
||||
|
||||
#if defined(BN_MP_TO_UNSIGNED_BIN_C)
|
||||
#define BN_MP_INIT_COPY_C
|
||||
#define BN_MP_ISZERO_C
|
||||
@@ -822,6 +857,11 @@
|
||||
#define BN_MP_CLEAR_C
|
||||
#endif
|
||||
|
||||
#if defined(BN_MP_TO_UNSIGNED_BIN_N_C)
|
||||
#define BN_MP_UNSIGNED_BIN_SIZE_C
|
||||
#define BN_MP_TO_UNSIGNED_BIN_C
|
||||
#endif
|
||||
|
||||
#if defined(BN_MP_TOOM_MUL_C)
|
||||
#define BN_MP_INIT_MULTI_C
|
||||
#define BN_MP_MOD_2D_C
|
||||
@@ -902,10 +942,12 @@
|
||||
#define BN_MP_INIT_C
|
||||
#define BN_MP_CLEAR_C
|
||||
#define BN_MP_REDUCE_SETUP_C
|
||||
#define BN_MP_REDUCE_C
|
||||
#define BN_MP_REDUCE_2K_SETUP_L_C
|
||||
#define BN_MP_REDUCE_2K_L_C
|
||||
#define BN_MP_MOD_C
|
||||
#define BN_MP_COPY_C
|
||||
#define BN_MP_SQR_C
|
||||
#define BN_MP_REDUCE_C
|
||||
#define BN_MP_MUL_C
|
||||
#define BN_MP_SET_C
|
||||
#define BN_MP_EXCH_C
|
||||
|
||||
@@ -7,7 +7,9 @@
|
||||
// #define SC_RSA_1
|
||||
|
||||
/* For reference.... On an Athlon64 optimizing for speed...
|
||||
|
||||
LTM's mpi.o with all functions [striped] is 142KiB in size.
|
||||
|
||||
*/
|
||||
|
||||
/* Works for RSA only, mpi.o is 68KiB */
|
||||
@@ -32,7 +34,7 @@
|
||||
#define BN_PRIME_TAB_C
|
||||
|
||||
/* other modifiers */
|
||||
#define BN_MP_DIV_SMALL /* Slower division, not critical */
|
||||
#define BN_MP_DIV_SMALL /* Slower division, not critical */
|
||||
|
||||
/* here we are on the last pass so we turn things off. The functions classes are still there
|
||||
* but we remove them specifically from the build. This also invokes tweaks in functions
|
||||
|
||||
Reference in New Issue
Block a user