added libtomcrypt-1.14

This commit is contained in:
Tom St Denis
2006-08-30 23:30:00 +00:00
committed by Steffen Jaeckel
parent 1eed98f629
commit 479cc9c261
64 changed files with 240 additions and 124 deletions
-1
View File
@@ -308,7 +308,6 @@ int ECB_ENC(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
LOAD32H(s2, pt + 8); s2 ^= rk[2];
LOAD32H(s3, pt + 12); s3 ^= rk[3];
#ifdef LTC_SMALL_CODE
for (r = 0; ; r++) {
+9 -2
View File
@@ -117,6 +117,11 @@ int ccm_memory(int cipher,
L = 15 - noncelen;
}
/* decrease noncelen to match L */
if ((noncelen + L) > 15) {
noncelen = 15 - L;
}
/* allocate mem for the symmetric key */
if (uskey == NULL) {
skey = XMALLOC(sizeof(*skey));
@@ -308,8 +313,10 @@ int ccm_memory(int cipher,
}
}
/* setup CTR for the TAG */
ctr[14] = ctr[15] = 0x00;
/* setup CTR for the TAG (zero the count) */
for (y = 15; y > 15 - L; y--) {
ctr[y] = 0x00;
}
if ((err = cipher_descriptor[cipher].ecb_encrypt(ctr, CTRPAD, skey)) != CRYPT_OK) {
goto error;
}
+18 -2
View File
@@ -43,6 +43,7 @@ int gcm_memory( int cipher,
unsigned char *tag, unsigned long *taglen,
int direction)
{
void *orig;
gcm_state *gcm;
int err;
@@ -63,11 +64,26 @@ int gcm_memory( int cipher,
}
gcm = XMALLOC(sizeof(*gcm));
#ifndef GCM_TABLES_SSE2
orig = gcm = XMALLOC(sizeof(*gcm));
#else
orig = gcm = XMALLOC(sizeof(*gcm) + 16);
#endif
if (gcm == NULL) {
return CRYPT_MEM;
}
/* Force GCM to be on a multiple of 16 so we can use 128-bit aligned operations
* note that we only modify gcm and keep orig intact. This code is not portable
* but again it's only for SSE2 anyways, so who cares?
*/
#ifdef GCM_TABLES_SSE2
if ((unsigned long)gcm & 15) {
gcm = (gcm_state *)((unsigned long)gcm + (16 - ((unsigned long)gcm & 15)));
}
#endif
if ((err = gcm_init(gcm, cipher, key, keylen)) != CRYPT_OK) {
goto LTC_ERR;
}
@@ -82,7 +98,7 @@ int gcm_memory( int cipher,
}
err = gcm_done(gcm, tag, taglen);
LTC_ERR:
XFREE(gcm);
XFREE(orig);
return err;
}
#endif
+9 -1
View File
@@ -26,6 +26,13 @@ void gcm_mult_h(gcm_state *gcm, unsigned char *I)
unsigned char T[16];
#ifdef GCM_TABLES
int x, y;
#ifdef GCM_TABLES_SSE2
asm("movdqa (%0),%%xmm0"::"r"(&gcm->PC[0][I[0]][0]));
for (x = 1; x < 16; x++) {
asm("pxor (%0),%%xmm0"::"r"(&gcm->PC[x][I[x]][0]));
}
asm("movdqa %%xmm0,(%0)"::"r"(&T));
#else
XMEMCPY(T, &gcm->PC[0][I[0]][0], 16);
for (x = 1; x < 16; x++) {
#ifdef LTC_FAST
@@ -36,8 +43,9 @@ void gcm_mult_h(gcm_state *gcm, unsigned char *I)
for (y = 0; y < 16; y++) {
T[y] ^= gcm->PC[x][I[x]][y];
}
#endif
#endif /* LTC_FAST */
}
#endif /* GCM_TABLES_SSE2 */
#else
gcm_gf_mult(gcm->H, I, T);
#endif
+4 -4
View File
@@ -59,7 +59,7 @@ int gcm_process(gcm_state *gcm,
/* increment counter */
for (y = 15; y >= 12; y--) {
if (++gcm->Y[y]) { break; }
if (++gcm->Y[y] & 255) { break; }
}
/* encrypt the counter */
if ((err = cipher_descriptor[gcm->cipher].ecb_encrypt(gcm->Y, gcm->buf, &gcm->K)) != CRYPT_OK) {
@@ -89,7 +89,7 @@ int gcm_process(gcm_state *gcm,
gcm_mult_h(gcm, gcm->X);
/* increment counter */
for (y = 15; y >= 12; y--) {
if (++gcm->Y[y]) { break; }
if (++gcm->Y[y] & 255) { break; }
}
if ((err = cipher_descriptor[gcm->cipher].ecb_encrypt(gcm->Y, gcm->buf, &gcm->K)) != CRYPT_OK) {
return err;
@@ -107,7 +107,7 @@ int gcm_process(gcm_state *gcm,
gcm_mult_h(gcm, gcm->X);
/* increment counter */
for (y = 15; y >= 12; y--) {
if (++gcm->Y[y]) { break; }
if (++gcm->Y[y] & 255) { break; }
}
if ((err = cipher_descriptor[gcm->cipher].ecb_encrypt(gcm->Y, gcm->buf, &gcm->K)) != CRYPT_OK) {
return err;
@@ -125,7 +125,7 @@ int gcm_process(gcm_state *gcm,
/* increment counter */
for (y = 15; y >= 12; y--) {
if (++gcm->Y[y]) { break; }
if (++gcm->Y[y] & 255) { break; }
}
if ((err = cipher_descriptor[gcm->cipher].ecb_encrypt(gcm->Y, gcm->buf, &gcm->K)) != CRYPT_OK) {
return err;
+1 -1
View File
@@ -37,7 +37,7 @@ const struct ltc_hash_descriptor sha256_desc =
#ifdef LTC_SMALL_CODE
/* the K array */
static const unsigned long K[64] = {
static const ulong32 K[64] = {
0x428a2f98UL, 0x71374491UL, 0xb5c0fbcfUL, 0xe9b5dba5UL, 0x3956c25bUL,
0x59f111f1UL, 0x923f82a4UL, 0xab1c5ed5UL, 0xd807aa98UL, 0x12835b01UL,
0x243185beUL, 0x550c7dc3UL, 0x72be5d74UL, 0x80deb1feUL, 0x9bdc06a7UL,
+2 -2
View File
@@ -16,8 +16,8 @@ extern "C" {
#endif
/* version */
#define CRYPT 0x0113
#define SCRYPT "1.13"
#define CRYPT 0x0114
#define SCRYPT "1.14"
/* max size of either a cipher/hash block or symmetric key [largest of the two] */
#define MAXBLOCKSIZE 128
+2 -2
View File
@@ -27,8 +27,8 @@ void crypt_argchk(char *v, char *s, int d);
#elif ARGTYPE == 4
#define LTC_ARGCHK(x) return CRYPT_INVALID_ARG;
#define LTC_ARGCHKVD(x) return;
#define LTC_ARGCHK(x) if (!(x)) return CRYPT_INVALID_ARG;
#define LTC_ARGCHKVD(x) if (!(x)) return;
#endif
+13 -12
View File
@@ -167,7 +167,7 @@ typedef union Symmetric_key {
void *data;
} symmetric_key;
#ifdef ECB
#ifdef LTC_ECB_MODE
/** A block cipher ECB structure */
typedef struct {
/** The index of the cipher chosen */
@@ -179,7 +179,7 @@ typedef struct {
} symmetric_ECB;
#endif
#ifdef CFB
#ifdef LTC_CFB_MODE
/** A block cipher CFB structure */
typedef struct {
/** The index of the cipher chosen */
@@ -197,7 +197,7 @@ typedef struct {
} symmetric_CFB;
#endif
#ifdef OFB
#ifdef LTC_OFB_MODE
/** A block cipher OFB structure */
typedef struct {
/** The index of the cipher chosen */
@@ -213,7 +213,7 @@ typedef struct {
} symmetric_OFB;
#endif
#ifdef CBC
#ifdef LTC_CBC_MODE
/** A block cipher CBC structure */
typedef struct {
/** The index of the cipher chosen */
@@ -228,7 +228,7 @@ typedef struct {
#endif
#ifdef CTR
#ifdef LTC_CTR_MODE
/** A block cipher CTR structure */
typedef struct {
/** The index of the cipher chosen */
@@ -249,7 +249,7 @@ typedef struct {
#endif
#ifdef LRW_MODE
#ifdef LTC_LRW_MODE
/** A LRW structure */
typedef struct {
/** The index of the cipher chosen (must be a 128-bit block cipher) */
@@ -649,7 +649,7 @@ int anubis_keysize(int *keysize);
extern const struct ltc_cipher_descriptor anubis_desc;
#endif
#ifdef ECB
#ifdef LTC_ECB_MODE
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, unsigned long len, symmetric_ECB *ecb);
@@ -657,7 +657,7 @@ int ecb_decrypt(const unsigned char *ct, unsigned char *pt, unsigned long len, s
int ecb_done(symmetric_ECB *ecb);
#endif
#ifdef CFB
#ifdef LTC_CFB_MODE
int cfb_start(int cipher, const unsigned char *IV, const unsigned char *key,
int keylen, int num_rounds, symmetric_CFB *cfb);
int cfb_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, symmetric_CFB *cfb);
@@ -667,7 +667,7 @@ int cfb_setiv(const unsigned char *IV, unsigned long len, symmetric_CFB *cfb);
int cfb_done(symmetric_CFB *cfb);
#endif
#ifdef OFB
#ifdef LTC_OFB_MODE
int ofb_start(int cipher, const unsigned char *IV, const unsigned char *key,
int keylen, int num_rounds, symmetric_OFB *ofb);
int ofb_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, symmetric_OFB *ofb);
@@ -677,7 +677,7 @@ int ofb_setiv(const unsigned char *IV, unsigned long len, symmetric_OFB *ofb);
int ofb_done(symmetric_OFB *ofb);
#endif
#ifdef CBC
#ifdef LTC_CBC_MODE
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, unsigned long len, symmetric_CBC *cbc);
@@ -687,7 +687,7 @@ int cbc_setiv(const unsigned char *IV, unsigned long len, symmetric_CBC *cbc);
int cbc_done(symmetric_CBC *cbc);
#endif
#ifdef CTR
#ifdef LTC_CTR_MODE
#define CTR_COUNTER_LITTLE_ENDIAN 0
#define CTR_COUNTER_BIG_ENDIAN 1
@@ -704,7 +704,7 @@ int ctr_setiv(const unsigned char *IV, unsigned long len, symmetric_CTR *ctr);
int ctr_done(symmetric_CTR *ctr);
#endif
#ifdef LRW_MODE
#ifdef LTC_LRW_MODE
#define LRW_ENCRYPT 0
#define LRW_DECRYPT 1
@@ -736,6 +736,7 @@ int f8_decrypt(const unsigned char *ct, unsigned char *pt, unsigned long len, sy
int f8_getiv(unsigned char *IV, unsigned long *len, symmetric_F8 *f8);
int f8_setiv(const unsigned char *IV, unsigned long len, symmetric_F8 *f8);
int f8_done(symmetric_F8 *f8);
int f8_test_mode(void);
#endif
+17 -15
View File
@@ -45,9 +45,9 @@
#define CAST5
#define LTC_NO_MODES
#define ECB
#define CBC
#define CTR
#define LTC_ECB_MODE
#define LTC_CBC_MODE
#define LTC_CTR_MODE
#define LTC_NO_HASHES
#define SHA1
@@ -55,7 +55,6 @@
#define SHA384
#define SHA256
#define SHA224
#define WHIRLPOOL
#define LTC_NO_MACS
#define HMAC
@@ -72,8 +71,6 @@
#define MRSA
#define MECC
#endif
/* Use small code where possible */
/* #define LTC_SMALL_CODE */
@@ -134,17 +131,17 @@
/* ---> Block Cipher Modes of Operation <--- */
#ifndef LTC_NO_MODES
#define CFB
#define OFB
#define ECB
#define CBC
#define CTR
#define LTC_CFB_MODE
#define LTC_OFB_MODE
#define LTC_ECB_MODE
#define LTC_CBC_MODE
#define LTC_CTR_MODE
/* F8 chaining mode */
#define LTC_F8_MODE
/* LRW mode */
#define LRW_MODE
#define LTC_LRW_MODE
#ifndef LTC_NO_TABLES
/* like GCM mode this will enable 16 8x128 tables [64KB] that make
* seeking very fast.
@@ -188,7 +185,7 @@
/* ---> Encrypt + Authenticate Modes <--- */
#define EAX_MODE
#if defined(EAX_MODE) && !(defined(CTR) && defined(OMAC))
#if defined(EAX_MODE) && !(defined(LTC_CTR_MODE) && defined(OMAC))
#error EAX_MODE requires CTR and OMAC mode
#endif
@@ -201,6 +198,11 @@
#define GCM_TABLES
#endif
/* USE SSE2? requires GCC works on x86_32 and x86_64*/
#ifdef GCM_TABLES
/* #define GCM_TABLES_SSE2 */
#endif
#endif /* LTC_NO_MACS */
/* Various tidbits of modern neatoness */
@@ -215,8 +217,8 @@
/* 0 = rijndael_enc 1 = aes_enc, 2 = rijndael [full], 3 = aes [full] */
#define YARROW_AES 0
#if defined(YARROW) && !defined(CTR)
#error YARROW requires CTR chaining mode to be defined!
#if defined(YARROW) && !defined(LTC_CTR_MODE)
#error YARROW requires LTC_CTR_MODE chaining mode to be defined!
#endif
/* a PRNG that simply reads from an available system source */
+6 -3
View File
@@ -98,7 +98,7 @@ void pmac_shift_xor(pmac_state *pmac);
#ifdef EAX_MODE
#if !(defined(OMAC) && defined(CTR))
#if !(defined(OMAC) && defined(LTC_CTR_MODE))
#error EAX_MODE requires OMAC and CTR
#endif
@@ -248,9 +248,12 @@ typedef struct {
pttotlen; /* 64-bit counter for the PT */
#ifdef GCM_TABLES
unsigned char PC[16][256][16]; /* 16 tables of 8x128 */
unsigned char PC[16][256][16] /* 16 tables of 8x128 */
#ifdef GCM_TABLES_SSE2
__attribute__ ((aligned (16)))
#endif
;
#endif
} gcm_state;
void gcm_mult_h(gcm_state *gcm, unsigned char *I);
+1 -1
View File
@@ -55,7 +55,7 @@ int hmac_test(void)
3. Test Cases for HMAC-SHA-1
test_case = 1
key = 0x0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b
key = 0x0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c
key_len = 20
data = "Hi Ther 20
digest = 0x4c1a03424b55e07fe7f27be1d58bb9324a9a5a04
+5 -5
View File
@@ -153,19 +153,19 @@ const char *crypt_build_settings =
#endif
"\nBlock Chaining Modes:\n"
#if defined(CFB)
#if defined(LTC_CFB_MODE)
" CFB\n"
#endif
#if defined(OFB)
#if defined(LTC_OFB_MODE)
" OFB\n"
#endif
#if defined(ECB)
#if defined(LTC_ECB_MODE)
" ECB\n"
#endif
#if defined(CBC)
#if defined(LTC_CBC_MODE)
" CBC\n"
#endif
#if defined(CTR)
#if defined(LTC_CTR_MODE)
" CTR\n"
#endif
#if defined(LRW_MODE)
+1 -1
View File
@@ -16,7 +16,7 @@
*/
#ifdef CBC
#ifdef LTC_CBC_MODE
/**
CBC decrypt
+1 -1
View File
@@ -15,7 +15,7 @@
CBC implementation, finish chain, Tom St Denis
*/
#ifdef CBC
#ifdef LTC_CBC_MODE
/** Terminate the chain
@param cbc The CBC chain to terminate
+1 -1
View File
@@ -16,7 +16,7 @@
*/
#ifdef CBC
#ifdef LTC_CBC_MODE
/**
CBC encrypt
+1 -1
View File
@@ -15,7 +15,7 @@
CBC implementation, get IV, Tom St Denis
*/
#ifdef CBC
#ifdef LTC_CBC_MODE
/**
Get the current initial vector
+1 -1
View File
@@ -16,7 +16,7 @@
*/
#ifdef CBC
#ifdef LTC_CBC_MODE
/**
Set an initial vector
+1 -1
View File
@@ -15,7 +15,7 @@
CBC implementation, start chain, Tom St Denis
*/
#ifdef CBC
#ifdef LTC_CBC_MODE
/**
Initialize a CBC context
+1 -1
View File
@@ -15,7 +15,7 @@
CFB implementation, decrypt data, Tom St Denis
*/
#ifdef CFB
#ifdef LTC_CFB_MODE
/**
CFB decrypt
+1 -1
View File
@@ -15,7 +15,7 @@
CFB implementation, finish chain, Tom St Denis
*/
#ifdef CFB
#ifdef LTC_CFB_MODE
/** Terminate the chain
@param cfb The CFB chain to terminate
+1 -1
View File
@@ -15,7 +15,7 @@
CFB implementation, encrypt data, Tom St Denis
*/
#ifdef CFB
#ifdef LTC_CFB_MODE
/**
CFB encrypt
+1 -1
View File
@@ -15,7 +15,7 @@
CFB implementation, get IV, Tom St Denis
*/
#ifdef CFB
#ifdef LTC_CFB_MODE
/**
Get the current initial vector
+2 -1
View File
@@ -14,7 +14,8 @@
@file cfb_setiv.c
CFB implementation, set IV, Tom St Denis
*/
#ifdef CFB
#ifdef LTC_CFB_MODE
/**
Set an initial vector
+1 -1
View File
@@ -16,7 +16,7 @@
*/
#ifdef CFB
#ifdef LTC_CFB_MODE
/**
Initialize a CFB context
+1 -1
View File
@@ -15,7 +15,7 @@
CTR implementation, decrypt data, Tom St Denis
*/
#ifdef CTR
#ifdef LTC_CTR_MODE
/**
CTR decrypt
+1 -1
View File
@@ -15,7 +15,7 @@
CTR implementation, finish chain, Tom St Denis
*/
#ifdef CTR
#ifdef LTC_CTR_MODE
/** Terminate the chain
@param ctr The CTR chain to terminate
+1 -1
View File
@@ -16,7 +16,7 @@
*/
#ifdef CTR
#ifdef LTC_CTR_MODE
/**
CTR encrypt
+1 -1
View File
@@ -15,7 +15,7 @@
CTR implementation, get IV, Tom St Denis
*/
#ifdef CTR
#ifdef LTC_CTR_MODE
/**
Get the current initial vector
+1 -1
View File
@@ -15,7 +15,7 @@
CTR implementation, set IV, Tom St Denis
*/
#ifdef CTR
#ifdef LTC_CTR_MODE
/**
Set an initial vector
+1 -1
View File
@@ -16,7 +16,7 @@
*/
#ifdef CTR
#ifdef LTC_CTR_MODE
/**
Initialize a CTR context
+1 -1
View File
@@ -15,7 +15,7 @@
ECB implementation, decrypt a block, Tom St Denis
*/
#ifdef ECB
#ifdef LTC_ECB_MODE
/**
ECB decrypt
+1 -1
View File
@@ -15,7 +15,7 @@
ECB implementation, finish chain, Tom St Denis
*/
#ifdef ECB
#ifdef LTC_ECB_MODE
/** Terminate the chain
@param ecb The ECB chain to terminate
+1 -1
View File
@@ -15,7 +15,7 @@
ECB implementation, encrypt a block, Tom St Denis
*/
#ifdef ECB
#ifdef LTC_ECB_MODE
/**
ECB encrypt
+1 -1
View File
@@ -16,7 +16,7 @@
*/
#ifdef ECB
#ifdef LTC_ECB_MODE
/**
Initialize a ECB context
+1
View File
@@ -54,6 +54,7 @@ int f8_start( int cipher, const unsigned char *IV,
f8->padlen = f8->blocklen;
/* now get key ^ salt_key [extend salt_ket with 0x55 as required to match length] */
zeromem(tkey, sizeof(tkey));
for (x = 0; x < keylen && x < (int)sizeof(tkey); x++) {
tkey[x] = key[x];
}
+1 -1
View File
@@ -15,7 +15,7 @@
LRW_MODE implementation, Decrypt blocks, Tom St Denis
*/
#ifdef LRW_MODE
#ifdef LTC_LRW_MODE
/**
LRW decrypt blocks
+1 -1
View File
@@ -15,7 +15,7 @@
LRW_MODE implementation, Free resources, Tom St Denis
*/
#ifdef LRW_MODE
#ifdef LTC_LRW_MODE
/**
Terminate a LRW state
+1 -1
View File
@@ -15,7 +15,7 @@
LRW_MODE implementation, Encrypt blocks, Tom St Denis
*/
#ifdef LRW_MODE
#ifdef LTC_LRW_MODE
/**
LRW encrypt blocks
+1 -1
View File
@@ -15,7 +15,7 @@
LRW_MODE implementation, Retrieve the current IV, Tom St Denis
*/
#ifdef LRW_MODE
#ifdef LTC_LRW_MODE
/**
Get the IV for LRW
+1 -1
View File
@@ -15,7 +15,7 @@
LRW_MODE implementation, Encrypt/decrypt blocks, Tom St Denis
*/
#ifdef LRW_MODE
#ifdef LTC_LRW_MODE
/**
Process blocks with LRW, since decrypt/encrypt are largely the same they share this code.
+1 -1
View File
@@ -15,7 +15,7 @@
LRW_MODE implementation, Set the current IV, Tom St Denis
*/
#ifdef LRW_MODE
#ifdef LTC_LRW_MODE
/**
Set the IV for LRW
+1 -1
View File
@@ -15,7 +15,7 @@
LRW_MODE implementation, start mode, Tom St Denis
*/
#ifdef LRW_MODE
#ifdef LTC_LRW_MODE
/**
Initialize the LRW context
+1 -1
View File
@@ -15,7 +15,7 @@
LRW_MODE implementation, test LRW, Tom St Denis
*/
#ifdef LRW_MODE
#ifdef LTC_LRW_MODE
/**
Test LRW against specs
+1 -1
View File
@@ -15,7 +15,7 @@
OFB implementation, decrypt data, Tom St Denis
*/
#ifdef OFB
#ifdef LTC_OFB_MODE
/**
OFB decrypt
+1 -1
View File
@@ -15,7 +15,7 @@
OFB implementation, finish chain, Tom St Denis
*/
#ifdef OFB
#ifdef LTC_OFB_MODE
/** Terminate the chain
@param ofb The OFB chain to terminate
+1 -1
View File
@@ -15,7 +15,7 @@
OFB implementation, encrypt data, Tom St Denis
*/
#ifdef OFB
#ifdef LTC_OFB_MODE
/**
OFB encrypt
+1 -1
View File
@@ -15,7 +15,7 @@
OFB implementation, get IV, Tom St Denis
*/
#ifdef OFB
#ifdef LTC_OFB_MODE
/**
Get the current initial vector
+1 -1
View File
@@ -15,7 +15,7 @@
OFB implementation, set IV, Tom St Denis
*/
#ifdef OFB
#ifdef LTC_OFB_MODE
/**
Set an initial vector
+1 -1
View File
@@ -16,7 +16,7 @@
*/
#ifdef OFB
#ifdef LTC_OFB_MODE
/**
Initialize a OFB context
@@ -218,6 +218,12 @@ int der_decode_sequence_ex(const unsigned char *in, unsigned long inlen,
case LTC_ASN1_SETOF:
case LTC_ASN1_SEQUENCE:
/* detect if we have the right type */
if ((type == LTC_ASN1_SETOF && (in[x] & 0x3F) != 0x31) || (type == LTC_ASN1_SEQUENCE && (in[x] & 0x3F) != 0x30)) {
err = CRYPT_INVALID_PACKET;
goto LBL_ERR;
}
z = inlen;
if ((err = der_decode_sequence(in + x, z, data, size)) != CRYPT_OK) {
if (!ordered) { continue; }