mirror of
https://github.com/clearml/dropbear
synced 2025-06-26 18:17:32 +00:00
propagate from branch 'au.asn.ucc.matt.ltc.dropbear' (head 2af22fb4e878750b88f80f90d439b316d229796f)
to branch 'au.asn.ucc.matt.dropbear' (head 02c413252c90e9de8e03d91e9939dde3029f5c0a) --HG-- extra : convert_revision : 52ccb0ad0587a62bc64aecb939adbb76546aac16
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
*/
|
||||
|
||||
/* AES implementation by Tom St Denis
|
||||
@@ -50,7 +50,7 @@ const struct ltc_cipher_descriptor rijndael_desc =
|
||||
6,
|
||||
16, 32, 16, 10,
|
||||
SETUP, ECB_ENC, ECB_DEC, ECB_TEST, ECB_DONE, ECB_KS,
|
||||
NULL, NULL, NULL, NULL, NULL, NULL, NULL
|
||||
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
|
||||
};
|
||||
#endif
|
||||
|
||||
@@ -60,7 +60,7 @@ const struct ltc_cipher_descriptor aes_desc =
|
||||
6,
|
||||
16, 32, 16, 10,
|
||||
SETUP, ECB_ENC, ECB_DEC, ECB_TEST, ECB_DONE, ECB_KS,
|
||||
NULL, NULL, NULL, NULL, NULL, NULL, NULL
|
||||
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
|
||||
};
|
||||
|
||||
#else
|
||||
@@ -76,7 +76,7 @@ const struct ltc_cipher_descriptor rijndael_enc_desc =
|
||||
6,
|
||||
16, 32, 16, 10,
|
||||
SETUP, ECB_ENC, NULL, NULL, ECB_DONE, ECB_KS,
|
||||
NULL, NULL, NULL, NULL, NULL, NULL, NULL
|
||||
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
|
||||
};
|
||||
|
||||
const struct ltc_cipher_descriptor aes_enc_desc =
|
||||
@@ -85,7 +85,7 @@ const struct ltc_cipher_descriptor aes_enc_desc =
|
||||
6,
|
||||
16, 32, 16, 10,
|
||||
SETUP, ECB_ENC, NULL, NULL, ECB_DONE, ECB_KS,
|
||||
NULL, NULL, NULL, NULL, NULL, NULL, NULL
|
||||
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -283,11 +283,12 @@ int SETUP(const unsigned char *key, int keylen, int num_rounds, symmetric_key *s
|
||||
@param pt The input plaintext (16 bytes)
|
||||
@param ct The output ciphertext (16 bytes)
|
||||
@param skey The key as scheduled
|
||||
@return CRYPT_OK if successful
|
||||
*/
|
||||
#ifdef LTC_CLEAN_STACK
|
||||
static void _rijndael_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
|
||||
static int _rijndael_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
|
||||
#else
|
||||
void ECB_ENC(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
|
||||
int ECB_ENC(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
|
||||
#endif
|
||||
{
|
||||
ulong32 s0, s1, s2, s3, t0, t1, t2, t3, *rk;
|
||||
@@ -309,7 +310,6 @@ void 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++) {
|
||||
@@ -442,13 +442,16 @@ void ECB_ENC(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
|
||||
(Te4_0[byte(t2, 0)]) ^
|
||||
rk[3];
|
||||
STORE32H(s3, ct+12);
|
||||
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
#ifdef LTC_CLEAN_STACK
|
||||
void ECB_ENC(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
|
||||
int ECB_ENC(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
|
||||
{
|
||||
_rijndael_ecb_encrypt(pt, ct, skey);
|
||||
int err = _rijndael_ecb_encrypt(pt, ct, skey);
|
||||
burn_stack(sizeof(unsigned long)*8 + sizeof(unsigned long*) + sizeof(int)*2);
|
||||
return err;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -459,11 +462,12 @@ void ECB_ENC(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
|
||||
@param ct The input ciphertext (16 bytes)
|
||||
@param pt The output plaintext (16 bytes)
|
||||
@param skey The key as scheduled
|
||||
@return CRYPT_OK if successful
|
||||
*/
|
||||
#ifdef LTC_CLEAN_STACK
|
||||
static void _rijndael_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
|
||||
static int _rijndael_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
|
||||
#else
|
||||
void ECB_DEC(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
|
||||
int ECB_DEC(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
|
||||
#endif
|
||||
{
|
||||
ulong32 s0, s1, s2, s3, t0, t1, t2, t3, *rk;
|
||||
@@ -617,14 +621,17 @@ void ECB_DEC(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
|
||||
(Td4[byte(t0, 0)] & 0x000000ff) ^
|
||||
rk[3];
|
||||
STORE32H(s3, pt+12);
|
||||
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
|
||||
#ifdef LTC_CLEAN_STACK
|
||||
void ECB_DEC(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
|
||||
int ECB_DEC(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
|
||||
{
|
||||
_rijndael_ecb_decrypt(ct, pt, skey);
|
||||
int err = _rijndael_ecb_decrypt(ct, pt, skey);
|
||||
burn_stack(sizeof(unsigned long)*8 + sizeof(unsigned long*) + sizeof(int)*2);
|
||||
return err;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -683,10 +690,10 @@ int ECB_TEST(void)
|
||||
|
||||
rijndael_ecb_encrypt(tests[i].pt, tmp[0], &key);
|
||||
rijndael_ecb_decrypt(tmp[0], tmp[1], &key);
|
||||
if (memcmp(tmp[0], tests[i].ct, 16) || memcmp(tmp[1], tests[i].pt, 16)) {
|
||||
if (XMEMCMP(tmp[0], tests[i].ct, 16) || XMEMCMP(tmp[1], tests[i].pt, 16)) {
|
||||
#if 0
|
||||
printf("\n\nTest %d failed\n", i);
|
||||
if (memcmp(tmp[0], tests[i].ct, 16)) {
|
||||
if (XMEMCMP(tmp[0], tests[i].ct, 16)) {
|
||||
printf("CT: ");
|
||||
for (i = 0; i < 16; i++) {
|
||||
printf("%02x ", tmp[0][i]);
|
||||
@@ -751,5 +758,5 @@ int ECB_KS(int *keysize)
|
||||
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/ciphers/aes/aes.c,v $ */
|
||||
/* $Revision: 1.8 $ */
|
||||
/* $Date: 2005/05/05 14:35:58 $ */
|
||||
/* $Revision: 1.14 $ */
|
||||
/* $Date: 2006/11/08 23:01:06 $ */
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
*/
|
||||
/* The precomputed tables for AES */
|
||||
/*
|
||||
@@ -94,6 +94,7 @@ static const ulong32 TE0[256] = {
|
||||
0x7bb0b0cbUL, 0xa85454fcUL, 0x6dbbbbd6UL, 0x2c16163aUL,
|
||||
};
|
||||
|
||||
#ifndef PELI_TAB
|
||||
static const ulong32 Te4[256] = {
|
||||
0x63636363UL, 0x7c7c7c7cUL, 0x77777777UL, 0x7b7b7b7bUL,
|
||||
0xf2f2f2f2UL, 0x6b6b6b6bUL, 0x6f6f6f6fUL, 0xc5c5c5c5UL,
|
||||
@@ -160,6 +161,7 @@ static const ulong32 Te4[256] = {
|
||||
0x41414141UL, 0x99999999UL, 0x2d2d2d2dUL, 0x0f0f0f0fUL,
|
||||
0xb0b0b0b0UL, 0x54545454UL, 0xbbbbbbbbUL, 0x16161616UL,
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifndef ENCRYPT_ONLY
|
||||
|
||||
@@ -528,6 +530,7 @@ static const ulong32 TE3[256] = {
|
||||
0xb0b0cb7bUL, 0x5454fca8UL, 0xbbbbd66dUL, 0x16163a2cUL,
|
||||
};
|
||||
|
||||
#ifndef PELI_TAB
|
||||
static const ulong32 Te4_0[] = {
|
||||
0x00000063UL, 0x0000007cUL, 0x00000077UL, 0x0000007bUL, 0x000000f2UL, 0x0000006bUL, 0x0000006fUL, 0x000000c5UL,
|
||||
0x00000030UL, 0x00000001UL, 0x00000067UL, 0x0000002bUL, 0x000000feUL, 0x000000d7UL, 0x000000abUL, 0x00000076UL,
|
||||
@@ -667,6 +670,7 @@ static const ulong32 Te4_3[] = {
|
||||
0x8c000000UL, 0xa1000000UL, 0x89000000UL, 0x0d000000UL, 0xbf000000UL, 0xe6000000UL, 0x42000000UL, 0x68000000UL,
|
||||
0x41000000UL, 0x99000000UL, 0x2d000000UL, 0x0f000000UL, 0xb0000000UL, 0x54000000UL, 0xbb000000UL, 0x16000000UL
|
||||
};
|
||||
#endif /* pelimac */
|
||||
|
||||
#ifndef ENCRYPT_ONLY
|
||||
|
||||
@@ -1020,5 +1024,5 @@ static const ulong32 rcon[] = {
|
||||
};
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/ciphers/aes/aes_tab.c,v $ */
|
||||
/* $Revision: 1.3 $ */
|
||||
/* $Date: 2005/05/05 14:35:58 $ */
|
||||
/* $Revision: 1.5 $ */
|
||||
/* $Date: 2006/04/02 13:19:09 $ */
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -6,7 +6,7 @@
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
*/
|
||||
/**
|
||||
@file blowfish.c
|
||||
@@ -27,7 +27,7 @@ const struct ltc_cipher_descriptor blowfish_desc =
|
||||
&blowfish_test,
|
||||
&blowfish_done,
|
||||
&blowfish_keysize,
|
||||
NULL, NULL, NULL, NULL, NULL, NULL, NULL
|
||||
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
|
||||
};
|
||||
|
||||
static const ulong32 ORIG_P[16 + 2] = {
|
||||
@@ -385,11 +385,12 @@ int blowfish_setup(const unsigned char *key, int keylen, int num_rounds,
|
||||
@param pt The input plaintext (8 bytes)
|
||||
@param ct The output ciphertext (8 bytes)
|
||||
@param skey The key as scheduled
|
||||
@return CRYPT_OK if successful
|
||||
*/
|
||||
#ifdef LTC_CLEAN_STACK
|
||||
static void _blowfish_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
|
||||
static int _blowfish_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
|
||||
#else
|
||||
void blowfish_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
|
||||
int blowfish_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
|
||||
#endif
|
||||
{
|
||||
ulong32 L, R;
|
||||
@@ -428,13 +429,16 @@ void blowfish_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_
|
||||
/* store */
|
||||
STORE32H(R, &ct[0]);
|
||||
STORE32H(L, &ct[4]);
|
||||
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
#ifdef LTC_CLEAN_STACK
|
||||
void blowfish_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
|
||||
int blowfish_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
|
||||
{
|
||||
_blowfish_ecb_encrypt(pt, ct, skey);
|
||||
int err = _blowfish_ecb_encrypt(pt, ct, skey);
|
||||
burn_stack(sizeof(ulong32) * 2 + sizeof(int));
|
||||
return err;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -443,11 +447,12 @@ void blowfish_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_
|
||||
@param ct The input ciphertext (8 bytes)
|
||||
@param pt The output plaintext (8 bytes)
|
||||
@param skey The key as scheduled
|
||||
@return CRYPT_OK if successful
|
||||
*/
|
||||
#ifdef LTC_CLEAN_STACK
|
||||
static void _blowfish_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
|
||||
static int _blowfish_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
|
||||
#else
|
||||
void blowfish_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
|
||||
int blowfish_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
|
||||
#endif
|
||||
{
|
||||
ulong32 L, R;
|
||||
@@ -486,13 +491,15 @@ void blowfish_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_
|
||||
/* store */
|
||||
STORE32H(L, &pt[0]);
|
||||
STORE32H(R, &pt[4]);
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
#ifdef LTC_CLEAN_STACK
|
||||
void blowfish_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
|
||||
int blowfish_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
|
||||
{
|
||||
_blowfish_ecb_decrypt(ct, pt, skey);
|
||||
int err = _blowfish_ecb_decrypt(ct, pt, skey);
|
||||
burn_stack(sizeof(ulong32) * 2 + sizeof(int));
|
||||
return err;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -541,7 +548,7 @@ int blowfish_test(void)
|
||||
blowfish_ecb_decrypt(tmp[0], tmp[1], &key);
|
||||
|
||||
/* compare */
|
||||
if ((memcmp(tmp[0], tests[x].ct, 8) != 0) || (memcmp(tmp[1], tests[x].pt, 8) != 0)) {
|
||||
if ((XMEMCMP(tmp[0], tests[x].ct, 8) != 0) || (XMEMCMP(tmp[1], tests[x].pt, 8) != 0)) {
|
||||
return CRYPT_FAIL_TESTVECTOR;
|
||||
}
|
||||
|
||||
@@ -583,5 +590,5 @@ int blowfish_keysize(int *keysize)
|
||||
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/ciphers/blowfish.c,v $ */
|
||||
/* $Revision: 1.7 $ */
|
||||
/* $Date: 2005/05/05 14:35:58 $ */
|
||||
/* $Revision: 1.12 $ */
|
||||
/* $Date: 2006/11/08 23:01:06 $ */
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -27,7 +27,7 @@ const struct ltc_cipher_descriptor cast5_desc = {
|
||||
&cast5_test,
|
||||
&cast5_done,
|
||||
&cast5_keysize,
|
||||
NULL, NULL, NULL, NULL, NULL, NULL, NULL
|
||||
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
|
||||
};
|
||||
|
||||
static const ulong32 S1[256] = {
|
||||
@@ -536,9 +536,9 @@ INLINE static ulong32 FIII(ulong32 R, ulong32 Km, ulong32 Kr)
|
||||
@param skey The key as scheduled
|
||||
*/
|
||||
#ifdef LTC_CLEAN_STACK
|
||||
static void _cast5_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
|
||||
static int _cast5_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
|
||||
#else
|
||||
void cast5_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
|
||||
int cast5_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
|
||||
#endif
|
||||
{
|
||||
ulong32 R, L;
|
||||
@@ -569,14 +569,16 @@ void cast5_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key
|
||||
}
|
||||
STORE32H(R,&ct[0]);
|
||||
STORE32H(L,&ct[4]);
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
|
||||
#ifdef LTC_CLEAN_STACK
|
||||
void cast5_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
|
||||
int cast5_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
|
||||
{
|
||||
_cast5_ecb_encrypt(pt,ct,skey);
|
||||
int err =_cast5_ecb_encrypt(pt,ct,skey);
|
||||
burn_stack(sizeof(ulong32)*3);
|
||||
return err;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -587,9 +589,9 @@ void cast5_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key
|
||||
@param skey The key as scheduled
|
||||
*/
|
||||
#ifdef LTC_CLEAN_STACK
|
||||
static void _cast5_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
|
||||
static int _cast5_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
|
||||
#else
|
||||
void cast5_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
|
||||
int cast5_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
|
||||
#endif
|
||||
{
|
||||
ulong32 R, L;
|
||||
@@ -620,13 +622,16 @@ void cast5_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key
|
||||
L ^= FI(R, skey->cast5.K[0], skey->cast5.K[16]);
|
||||
STORE32H(L,&pt[0]);
|
||||
STORE32H(R,&pt[4]);
|
||||
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
#ifdef LTC_CLEAN_STACK
|
||||
void cast5_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
|
||||
int cast5_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
|
||||
{
|
||||
_cast5_ecb_decrypt(ct,pt,skey);
|
||||
int err = _cast5_ecb_decrypt(ct,pt,skey);
|
||||
burn_stack(sizeof(ulong32)*3);
|
||||
return err;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -671,7 +676,7 @@ int cast5_test(void)
|
||||
}
|
||||
cast5_ecb_encrypt(tests[i].pt, tmp[0], &key);
|
||||
cast5_ecb_decrypt(tmp[0], tmp[1], &key);
|
||||
if ((memcmp(tmp[0], tests[i].ct, 8) != 0) || (memcmp(tmp[1], tests[i].pt, 8) != 0)) {
|
||||
if ((XMEMCMP(tmp[0], tests[i].ct, 8) != 0) || (XMEMCMP(tmp[1], tests[i].pt, 8) != 0)) {
|
||||
return CRYPT_FAIL_TESTVECTOR;
|
||||
}
|
||||
/* now see if we can encrypt all zero bytes 1000 times, decrypt and come back where we started */
|
||||
@@ -711,5 +716,5 @@ int cast5_keysize(int *keysize)
|
||||
#endif
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/ciphers/cast5.c,v $ */
|
||||
/* $Revision: 1.7 $ */
|
||||
/* $Date: 2005/05/05 14:35:58 $ */
|
||||
/* $Revision: 1.12 $ */
|
||||
/* $Date: 2006/11/08 23:01:06 $ */
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
@@ -32,7 +32,7 @@ const struct ltc_cipher_descriptor des_desc =
|
||||
&des_test,
|
||||
&des_done,
|
||||
&des_keysize,
|
||||
NULL, NULL, NULL, NULL, NULL, NULL, NULL
|
||||
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
|
||||
};
|
||||
#endif
|
||||
|
||||
@@ -47,7 +47,7 @@ const struct ltc_cipher_descriptor des3_desc =
|
||||
&des3_test,
|
||||
&des3_done,
|
||||
&des3_keysize,
|
||||
NULL, NULL, NULL, NULL, NULL, NULL, NULL
|
||||
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
|
||||
};
|
||||
|
||||
static const ulong32 bytebit[8] =
|
||||
@@ -1587,8 +1587,9 @@ int des3_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_k
|
||||
@param pt The input plaintext (8 bytes)
|
||||
@param ct The output ciphertext (8 bytes)
|
||||
@param skey The key as scheduled
|
||||
@return CRYPT_OK if successful
|
||||
*/
|
||||
void des_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
|
||||
int des_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
|
||||
{
|
||||
ulong32 work[2];
|
||||
LTC_ARGCHK(pt != NULL);
|
||||
@@ -1599,6 +1600,7 @@ void des_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *
|
||||
desfunc(work, skey->des.ek);
|
||||
STORE32H(work[0],ct+0);
|
||||
STORE32H(work[1],ct+4);
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1606,8 +1608,9 @@ void des_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *
|
||||
@param ct The input ciphertext (8 bytes)
|
||||
@param pt The output plaintext (8 bytes)
|
||||
@param skey The key as scheduled
|
||||
@return CRYPT_OK if successful
|
||||
*/
|
||||
void des_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
|
||||
int des_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
|
||||
{
|
||||
ulong32 work[2];
|
||||
LTC_ARGCHK(pt != NULL);
|
||||
@@ -1617,7 +1620,8 @@ void des_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *
|
||||
LOAD32H(work[1], ct+4);
|
||||
desfunc(work, skey->des.dk);
|
||||
STORE32H(work[0],pt+0);
|
||||
STORE32H(work[1],pt+4);
|
||||
STORE32H(work[1],pt+4);
|
||||
return CRYPT_OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -1626,8 +1630,9 @@ void des_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *
|
||||
@param pt The input plaintext (8 bytes)
|
||||
@param ct The output ciphertext (8 bytes)
|
||||
@param skey The key as scheduled
|
||||
@return CRYPT_OK if successful
|
||||
*/
|
||||
void des3_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
|
||||
int des3_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
|
||||
{
|
||||
ulong32 work[2];
|
||||
|
||||
@@ -1641,6 +1646,7 @@ void des3_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key
|
||||
desfunc(work, skey->des3.ek[2]);
|
||||
STORE32H(work[0],ct+0);
|
||||
STORE32H(work[1],ct+4);
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1648,8 +1654,9 @@ void des3_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key
|
||||
@param ct The input ciphertext (8 bytes)
|
||||
@param pt The output plaintext (8 bytes)
|
||||
@param skey The key as scheduled
|
||||
@return CRYPT_OK if successful
|
||||
*/
|
||||
void des3_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
|
||||
int des3_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
|
||||
{
|
||||
ulong32 work[2];
|
||||
LTC_ARGCHK(pt != NULL);
|
||||
@@ -1662,6 +1669,7 @@ void des3_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key
|
||||
desfunc(work, skey->des3.dk[2]);
|
||||
STORE32H(work[0],pt+0);
|
||||
STORE32H(work[1],pt+4);
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
#if 0
|
||||
@@ -1797,7 +1805,7 @@ int des_test(void)
|
||||
des_ecb_decrypt(cases[i].txt, tmp, &des);
|
||||
}
|
||||
|
||||
if (memcmp(cases[i].out, tmp, sizeof(tmp)) != 0) {
|
||||
if (XMEMCMP(cases[i].out, tmp, sizeof(tmp)) != 0) {
|
||||
return CRYPT_FAIL_TESTVECTOR;
|
||||
}
|
||||
|
||||
@@ -1841,7 +1849,7 @@ int des3_test(void)
|
||||
des3_ecb_encrypt(pt, ct, &skey);
|
||||
des3_ecb_decrypt(ct, tmp, &skey);
|
||||
|
||||
if (memcmp(pt, tmp, 8) != 0) {
|
||||
if (XMEMCMP(pt, tmp, 8) != 0) {
|
||||
return CRYPT_FAIL_TESTVECTOR;
|
||||
}
|
||||
|
||||
@@ -1902,5 +1910,5 @@ int des3_keysize(int *keysize)
|
||||
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/ciphers/des.c,v $ */
|
||||
/* $Revision: 1.8 $ */
|
||||
/* $Date: 2005/05/05 14:35:58 $ */
|
||||
/* $Revision: 1.13 $ */
|
||||
/* $Date: 2006/11/08 23:01:06 $ */
|
||||
|
||||
318
libtomcrypt/src/ciphers/kasumi.c
Normal file
318
libtomcrypt/src/ciphers/kasumi.c
Normal file
@@ -0,0 +1,318 @@
|
||||
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
|
||||
*
|
||||
* LibTomCrypt is a library that provides various cryptographic
|
||||
* algorithms in a highly modular and flexible manner.
|
||||
*
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
*/
|
||||
|
||||
/**
|
||||
@file kasumi.c
|
||||
Implementation of the 3GPP Kasumi block cipher
|
||||
Derived from the 3GPP standard source code
|
||||
*/
|
||||
|
||||
#include "tomcrypt.h"
|
||||
|
||||
#ifdef LTC_KASUMI
|
||||
|
||||
typedef unsigned u16;
|
||||
|
||||
#define ROL16(x, y) ((((x)<<(y)) | ((x)>>(16-(y)))) & 0xFFFF)
|
||||
|
||||
const struct ltc_cipher_descriptor kasumi_desc = {
|
||||
"kasumi",
|
||||
21,
|
||||
16, 16, 8, 8,
|
||||
&kasumi_setup,
|
||||
&kasumi_ecb_encrypt,
|
||||
&kasumi_ecb_decrypt,
|
||||
&kasumi_test,
|
||||
&kasumi_done,
|
||||
&kasumi_keysize,
|
||||
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
|
||||
};
|
||||
|
||||
static u16 FI( u16 in, u16 subkey )
|
||||
{
|
||||
u16 nine, seven;
|
||||
static const u16 S7[128] = {
|
||||
54, 50, 62, 56, 22, 34, 94, 96, 38, 6, 63, 93, 2, 18,123, 33,
|
||||
55,113, 39,114, 21, 67, 65, 12, 47, 73, 46, 27, 25,111,124, 81,
|
||||
53, 9,121, 79, 52, 60, 58, 48,101,127, 40,120,104, 70, 71, 43,
|
||||
20,122, 72, 61, 23,109, 13,100, 77, 1, 16, 7, 82, 10,105, 98,
|
||||
117,116, 76, 11, 89,106, 0,125,118, 99, 86, 69, 30, 57,126, 87,
|
||||
112, 51, 17, 5, 95, 14, 90, 84, 91, 8, 35,103, 32, 97, 28, 66,
|
||||
102, 31, 26, 45, 75, 4, 85, 92, 37, 74, 80, 49, 68, 29,115, 44,
|
||||
64,107,108, 24,110, 83, 36, 78, 42, 19, 15, 41, 88,119, 59, 3 };
|
||||
static const u16 S9[512] = {
|
||||
167,239,161,379,391,334, 9,338, 38,226, 48,358,452,385, 90,397,
|
||||
183,253,147,331,415,340, 51,362,306,500,262, 82,216,159,356,177,
|
||||
175,241,489, 37,206, 17, 0,333, 44,254,378, 58,143,220, 81,400,
|
||||
95, 3,315,245, 54,235,218,405,472,264,172,494,371,290,399, 76,
|
||||
165,197,395,121,257,480,423,212,240, 28,462,176,406,507,288,223,
|
||||
501,407,249,265, 89,186,221,428,164, 74,440,196,458,421,350,163,
|
||||
232,158,134,354, 13,250,491,142,191, 69,193,425,152,227,366,135,
|
||||
344,300,276,242,437,320,113,278, 11,243, 87,317, 36, 93,496, 27,
|
||||
487,446,482, 41, 68,156,457,131,326,403,339, 20, 39,115,442,124,
|
||||
475,384,508, 53,112,170,479,151,126,169, 73,268,279,321,168,364,
|
||||
363,292, 46,499,393,327,324, 24,456,267,157,460,488,426,309,229,
|
||||
439,506,208,271,349,401,434,236, 16,209,359, 52, 56,120,199,277,
|
||||
465,416,252,287,246, 6, 83,305,420,345,153,502, 65, 61,244,282,
|
||||
173,222,418, 67,386,368,261,101,476,291,195,430, 49, 79,166,330,
|
||||
280,383,373,128,382,408,155,495,367,388,274,107,459,417, 62,454,
|
||||
132,225,203,316,234, 14,301, 91,503,286,424,211,347,307,140,374,
|
||||
35,103,125,427, 19,214,453,146,498,314,444,230,256,329,198,285,
|
||||
50,116, 78,410, 10,205,510,171,231, 45,139,467, 29, 86,505, 32,
|
||||
72, 26,342,150,313,490,431,238,411,325,149,473, 40,119,174,355,
|
||||
185,233,389, 71,448,273,372, 55,110,178,322, 12,469,392,369,190,
|
||||
1,109,375,137,181, 88, 75,308,260,484, 98,272,370,275,412,111,
|
||||
336,318, 4,504,492,259,304, 77,337,435, 21,357,303,332,483, 18,
|
||||
47, 85, 25,497,474,289,100,269,296,478,270,106, 31,104,433, 84,
|
||||
414,486,394, 96, 99,154,511,148,413,361,409,255,162,215,302,201,
|
||||
266,351,343,144,441,365,108,298,251, 34,182,509,138,210,335,133,
|
||||
311,352,328,141,396,346,123,319,450,281,429,228,443,481, 92,404,
|
||||
485,422,248,297, 23,213,130,466, 22,217,283, 70,294,360,419,127,
|
||||
312,377, 7,468,194, 2,117,295,463,258,224,447,247,187, 80,398,
|
||||
284,353,105,390,299,471,470,184, 57,200,348, 63,204,188, 33,451,
|
||||
97, 30,310,219, 94,160,129,493, 64,179,263,102,189,207,114,402,
|
||||
438,477,387,122,192, 42,381, 5,145,118,180,449,293,323,136,380,
|
||||
43, 66, 60,455,341,445,202,432, 8,237, 15,376,436,464, 59,461};
|
||||
|
||||
/* The sixteen bit input is split into two unequal halves, *
|
||||
* nine bits and seven bits - as is the subkey */
|
||||
|
||||
nine = (u16)(in>>7)&0x1FF;
|
||||
seven = (u16)(in&0x7F);
|
||||
|
||||
/* Now run the various operations */
|
||||
nine = (u16)(S9[nine] ^ seven);
|
||||
seven = (u16)(S7[seven] ^ (nine & 0x7F));
|
||||
seven ^= (subkey>>9);
|
||||
nine ^= (subkey&0x1FF);
|
||||
nine = (u16)(S9[nine] ^ seven);
|
||||
seven = (u16)(S7[seven] ^ (nine & 0x7F));
|
||||
return (u16)(seven<<9) + nine;
|
||||
}
|
||||
|
||||
static ulong32 FO( ulong32 in, int round_no, symmetric_key *key)
|
||||
{
|
||||
u16 left, right;
|
||||
|
||||
/* Split the input into two 16-bit words */
|
||||
left = (u16)(in>>16);
|
||||
right = (u16) in&0xFFFF;
|
||||
|
||||
/* Now apply the same basic transformation three times */
|
||||
left ^= key->kasumi.KOi1[round_no];
|
||||
left = FI( left, key->kasumi.KIi1[round_no] );
|
||||
left ^= right;
|
||||
|
||||
right ^= key->kasumi.KOi2[round_no];
|
||||
right = FI( right, key->kasumi.KIi2[round_no] );
|
||||
right ^= left;
|
||||
|
||||
left ^= key->kasumi.KOi3[round_no];
|
||||
left = FI( left, key->kasumi.KIi3[round_no] );
|
||||
left ^= right;
|
||||
|
||||
return (((ulong32)right)<<16)+left;
|
||||
}
|
||||
|
||||
static ulong32 FL( ulong32 in, int round_no, symmetric_key *key )
|
||||
{
|
||||
u16 l, r, a, b;
|
||||
/* split out the left and right halves */
|
||||
l = (u16)(in>>16);
|
||||
r = (u16)(in)&0xFFFF;
|
||||
/* do the FL() operations */
|
||||
a = (u16) (l & key->kasumi.KLi1[round_no]);
|
||||
r ^= ROL16(a,1);
|
||||
b = (u16)(r | key->kasumi.KLi2[round_no]);
|
||||
l ^= ROL16(b,1);
|
||||
/* put the two halves back together */
|
||||
|
||||
return (((ulong32)l)<<16) + r;
|
||||
}
|
||||
|
||||
int kasumi_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
|
||||
{
|
||||
ulong32 left, right, temp;
|
||||
int n;
|
||||
|
||||
LTC_ARGCHK(pt != NULL);
|
||||
LTC_ARGCHK(ct != NULL);
|
||||
LTC_ARGCHK(skey != NULL);
|
||||
|
||||
LOAD32H(left, pt);
|
||||
LOAD32H(right, pt+4);
|
||||
|
||||
for (n = 0; n <= 7; ) {
|
||||
temp = FL(left, n, skey);
|
||||
temp = FO(temp, n++, skey);
|
||||
right ^= temp;
|
||||
temp = FO(right, n, skey);
|
||||
temp = FL(temp, n++, skey);
|
||||
left ^= temp;
|
||||
}
|
||||
|
||||
STORE32H(left, ct);
|
||||
STORE32H(right, ct+4);
|
||||
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
int kasumi_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
|
||||
{
|
||||
ulong32 left, right, temp;
|
||||
int n;
|
||||
|
||||
LTC_ARGCHK(pt != NULL);
|
||||
LTC_ARGCHK(ct != NULL);
|
||||
LTC_ARGCHK(skey != NULL);
|
||||
|
||||
LOAD32H(left, ct);
|
||||
LOAD32H(right, ct+4);
|
||||
|
||||
for (n = 7; n >= 0; ) {
|
||||
temp = FO(right, n, skey);
|
||||
temp = FL(temp, n--, skey);
|
||||
left ^= temp;
|
||||
temp = FL(left, n, skey);
|
||||
temp = FO(temp, n--, skey);
|
||||
right ^= temp;
|
||||
}
|
||||
|
||||
STORE32H(left, pt);
|
||||
STORE32H(right, pt+4);
|
||||
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
int kasumi_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey)
|
||||
{
|
||||
static const u16 C[8] = { 0x0123,0x4567,0x89AB,0xCDEF, 0xFEDC,0xBA98,0x7654,0x3210 };
|
||||
u16 ukey[8], Kprime[8];
|
||||
int n;
|
||||
|
||||
LTC_ARGCHK(key != NULL);
|
||||
LTC_ARGCHK(skey != NULL);
|
||||
|
||||
if (keylen != 16) {
|
||||
return CRYPT_INVALID_KEYSIZE;
|
||||
}
|
||||
|
||||
if (num_rounds != 0 && num_rounds != 8) {
|
||||
return CRYPT_INVALID_ROUNDS;
|
||||
}
|
||||
|
||||
/* Start by ensuring the subkeys are endian correct on a 16-bit basis */
|
||||
for (n = 0; n < 8; n++ ) {
|
||||
ukey[n] = (((u16)key[2*n]) << 8) | key[2*n+1];
|
||||
}
|
||||
|
||||
/* Now build the K'[] keys */
|
||||
for (n = 0; n < 8; n++) {
|
||||
Kprime[n] = ukey[n] ^ C[n];
|
||||
}
|
||||
|
||||
/* Finally construct the various sub keys */
|
||||
for(n = 0; n < 8; n++) {
|
||||
skey->kasumi.KLi1[n] = ROL16(ukey[n],1);
|
||||
skey->kasumi.KLi2[n] = Kprime[(n+2)&0x7];
|
||||
skey->kasumi.KOi1[n] = ROL16(ukey[(n+1)&0x7],5);
|
||||
skey->kasumi.KOi2[n] = ROL16(ukey[(n+5)&0x7],8);
|
||||
skey->kasumi.KOi3[n] = ROL16(ukey[(n+6)&0x7],13);
|
||||
skey->kasumi.KIi1[n] = Kprime[(n+4)&0x7];
|
||||
skey->kasumi.KIi2[n] = Kprime[(n+3)&0x7];
|
||||
skey->kasumi.KIi3[n] = Kprime[(n+7)&0x7];
|
||||
}
|
||||
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
void kasumi_done(symmetric_key *skey)
|
||||
{
|
||||
}
|
||||
|
||||
int kasumi_keysize(int *keysize)
|
||||
{
|
||||
LTC_ARGCHK(keysize != NULL);
|
||||
if (*keysize >= 16) {
|
||||
*keysize = 16;
|
||||
return CRYPT_OK;
|
||||
} else {
|
||||
return CRYPT_INVALID_KEYSIZE;
|
||||
}
|
||||
}
|
||||
|
||||
int kasumi_test(void)
|
||||
{
|
||||
#ifndef LTC_TEST
|
||||
return CRYPT_NOP;
|
||||
#else
|
||||
static const struct {
|
||||
unsigned char key[16], pt[8], ct[8];
|
||||
} tests[] = {
|
||||
|
||||
{
|
||||
{ 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
||||
{ 0x4B, 0x58, 0xA7, 0x71, 0xAF, 0xC7, 0xE5, 0xE8 }
|
||||
},
|
||||
|
||||
{
|
||||
{ 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
||||
{ 0x7E, 0xEF, 0x11, 0x3C, 0x95, 0xBB, 0x5A, 0x77 }
|
||||
},
|
||||
|
||||
{
|
||||
{ 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
||||
{ 0x5F, 0x14, 0x06, 0x86, 0xD7, 0xAD, 0x5A, 0x39 },
|
||||
},
|
||||
|
||||
{
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 },
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
||||
{ 0x2E, 0x14, 0x91, 0xCF, 0x70, 0xAA, 0x46, 0x5D }
|
||||
},
|
||||
|
||||
{
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00 },
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
||||
{ 0xB5, 0x45, 0x86, 0xF4, 0xAB, 0x9A, 0xE5, 0x46 }
|
||||
},
|
||||
|
||||
};
|
||||
unsigned char buf[2][8];
|
||||
symmetric_key key;
|
||||
int err, x;
|
||||
|
||||
for (x = 0; x < (int)(sizeof(tests)/sizeof(tests[0])); x++) {
|
||||
if ((err = kasumi_setup(tests[x].key, 16, 0, &key)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
if ((err = kasumi_ecb_encrypt(tests[x].pt, buf[0], &key)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
if ((err = kasumi_ecb_decrypt(tests[x].ct, buf[1], &key)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
if (XMEMCMP(tests[x].pt, buf[1], 8) || XMEMCMP(tests[x].ct, buf[0], 8)) {
|
||||
return CRYPT_FAIL_TESTVECTOR;
|
||||
}
|
||||
}
|
||||
return CRYPT_OK;
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/ciphers/kasumi.c,v $ */
|
||||
/* $Revision: 1.7 $ */
|
||||
/* $Date: 2006/11/09 03:05:44 $ */
|
||||
@@ -6,7 +6,7 @@
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
@@ -28,7 +28,7 @@ const struct ltc_cipher_descriptor khazad_desc = {
|
||||
&khazad_test,
|
||||
&khazad_done,
|
||||
&khazad_keysize,
|
||||
NULL, NULL, NULL, NULL, NULL, NULL, NULL
|
||||
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
|
||||
};
|
||||
|
||||
#define R 8
|
||||
@@ -741,13 +741,15 @@ static void khazad_crypt(const unsigned char *plaintext, unsigned char *cipherte
|
||||
@param pt The input plaintext (8 bytes)
|
||||
@param ct The output ciphertext (8 bytes)
|
||||
@param skey The key as scheduled
|
||||
@return CRYPT_OK if successful
|
||||
*/
|
||||
void khazad_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
|
||||
int khazad_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
|
||||
{
|
||||
LTC_ARGCHK(pt != NULL);
|
||||
LTC_ARGCHK(ct != NULL);
|
||||
LTC_ARGCHK(skey != NULL);
|
||||
khazad_crypt(pt, ct, skey->khazad.roundKeyEnc);
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -755,13 +757,15 @@ void khazad_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_ke
|
||||
@param ct The input ciphertext (8 bytes)
|
||||
@param pt The output plaintext (8 bytes)
|
||||
@param skey The key as scheduled
|
||||
@return CRYPT_OK if successful
|
||||
*/
|
||||
void khazad_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
|
||||
int khazad_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
|
||||
{
|
||||
LTC_ARGCHK(pt != NULL);
|
||||
LTC_ARGCHK(ct != NULL);
|
||||
LTC_ARGCHK(skey != NULL);
|
||||
khazad_crypt(ct, pt, skey->khazad.roundKeyDec);
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -806,13 +810,13 @@ int khazad_test(void)
|
||||
khazad_setup(tests[x].key, 16, 0, &skey);
|
||||
khazad_ecb_encrypt(tests[x].pt, buf[0], &skey);
|
||||
khazad_ecb_decrypt(buf[0], buf[1], &skey);
|
||||
if (memcmp(buf[0], tests[x].ct, 8) || memcmp(buf[1], tests[x].pt, 8)) {
|
||||
if (XMEMCMP(buf[0], tests[x].ct, 8) || XMEMCMP(buf[1], tests[x].pt, 8)) {
|
||||
return CRYPT_FAIL_TESTVECTOR;
|
||||
}
|
||||
|
||||
for (y = 0; y < 1000; y++) khazad_ecb_encrypt(buf[0], buf[0], &skey);
|
||||
for (y = 0; y < 1000; y++) khazad_ecb_decrypt(buf[0], buf[0], &skey);
|
||||
if (memcmp(buf[0], tests[x].ct, 8)) {
|
||||
if (XMEMCMP(buf[0], tests[x].ct, 8)) {
|
||||
return CRYPT_FAIL_TESTVECTOR;
|
||||
}
|
||||
|
||||
@@ -847,5 +851,5 @@ int khazad_keysize(int *keysize)
|
||||
#endif
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/ciphers/khazad.c,v $ */
|
||||
/* $Revision: 1.7 $ */
|
||||
/* $Date: 2005/05/05 14:35:58 $ */
|
||||
/* $Revision: 1.12 $ */
|
||||
/* $Date: 2006/11/08 23:01:06 $ */
|
||||
|
||||
376
libtomcrypt/src/ciphers/kseed.c
Normal file
376
libtomcrypt/src/ciphers/kseed.c
Normal file
@@ -0,0 +1,376 @@
|
||||
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
|
||||
*
|
||||
* LibTomCrypt is a library that provides various cryptographic
|
||||
* algorithms in a highly modular and flexible manner.
|
||||
*
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
*/
|
||||
|
||||
/**
|
||||
@file kseed.c
|
||||
seed implementation of SEED derived from RFC4269
|
||||
Tom St Denis
|
||||
*/
|
||||
|
||||
#include "tomcrypt.h"
|
||||
|
||||
#ifdef KSEED
|
||||
|
||||
const struct ltc_cipher_descriptor kseed_desc = {
|
||||
"seed",
|
||||
20,
|
||||
16, 16, 16, 16,
|
||||
&kseed_setup,
|
||||
&kseed_ecb_encrypt,
|
||||
&kseed_ecb_decrypt,
|
||||
&kseed_test,
|
||||
&kseed_done,
|
||||
&kseed_keysize,
|
||||
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
|
||||
};
|
||||
|
||||
static const ulong32 SS0[256] = {
|
||||
0x2989A1A8UL,0x05858184UL,0x16C6D2D4UL,0x13C3D3D0UL,0x14445054UL,0x1D0D111CUL,0x2C8CA0ACUL,0x25052124UL,
|
||||
0x1D4D515CUL,0x03434340UL,0x18081018UL,0x1E0E121CUL,0x11415150UL,0x3CCCF0FCUL,0x0ACAC2C8UL,0x23436360UL,
|
||||
0x28082028UL,0x04444044UL,0x20002020UL,0x1D8D919CUL,0x20C0E0E0UL,0x22C2E2E0UL,0x08C8C0C8UL,0x17071314UL,
|
||||
0x2585A1A4UL,0x0F8F838CUL,0x03030300UL,0x3B4B7378UL,0x3B8BB3B8UL,0x13031310UL,0x12C2D2D0UL,0x2ECEE2ECUL,
|
||||
0x30407070UL,0x0C8C808CUL,0x3F0F333CUL,0x2888A0A8UL,0x32023230UL,0x1DCDD1DCUL,0x36C6F2F4UL,0x34447074UL,
|
||||
0x2CCCE0ECUL,0x15859194UL,0x0B0B0308UL,0x17475354UL,0x1C4C505CUL,0x1B4B5358UL,0x3D8DB1BCUL,0x01010100UL,
|
||||
0x24042024UL,0x1C0C101CUL,0x33437370UL,0x18889098UL,0x10001010UL,0x0CCCC0CCUL,0x32C2F2F0UL,0x19C9D1D8UL,
|
||||
0x2C0C202CUL,0x27C7E3E4UL,0x32427270UL,0x03838380UL,0x1B8B9398UL,0x11C1D1D0UL,0x06868284UL,0x09C9C1C8UL,
|
||||
0x20406060UL,0x10405050UL,0x2383A3A0UL,0x2BCBE3E8UL,0x0D0D010CUL,0x3686B2B4UL,0x1E8E929CUL,0x0F4F434CUL,
|
||||
0x3787B3B4UL,0x1A4A5258UL,0x06C6C2C4UL,0x38487078UL,0x2686A2A4UL,0x12021210UL,0x2F8FA3ACUL,0x15C5D1D4UL,
|
||||
0x21416160UL,0x03C3C3C0UL,0x3484B0B4UL,0x01414140UL,0x12425250UL,0x3D4D717CUL,0x0D8D818CUL,0x08080008UL,
|
||||
0x1F0F131CUL,0x19899198UL,0x00000000UL,0x19091118UL,0x04040004UL,0x13435350UL,0x37C7F3F4UL,0x21C1E1E0UL,
|
||||
0x3DCDF1FCUL,0x36467274UL,0x2F0F232CUL,0x27072324UL,0x3080B0B0UL,0x0B8B8388UL,0x0E0E020CUL,0x2B8BA3A8UL,
|
||||
0x2282A2A0UL,0x2E4E626CUL,0x13839390UL,0x0D4D414CUL,0x29496168UL,0x3C4C707CUL,0x09090108UL,0x0A0A0208UL,
|
||||
0x3F8FB3BCUL,0x2FCFE3ECUL,0x33C3F3F0UL,0x05C5C1C4UL,0x07878384UL,0x14041014UL,0x3ECEF2FCUL,0x24446064UL,
|
||||
0x1ECED2DCUL,0x2E0E222CUL,0x0B4B4348UL,0x1A0A1218UL,0x06060204UL,0x21012120UL,0x2B4B6368UL,0x26466264UL,
|
||||
0x02020200UL,0x35C5F1F4UL,0x12829290UL,0x0A8A8288UL,0x0C0C000CUL,0x3383B3B0UL,0x3E4E727CUL,0x10C0D0D0UL,
|
||||
0x3A4A7278UL,0x07474344UL,0x16869294UL,0x25C5E1E4UL,0x26062224UL,0x00808080UL,0x2D8DA1ACUL,0x1FCFD3DCUL,
|
||||
0x2181A1A0UL,0x30003030UL,0x37073334UL,0x2E8EA2ACUL,0x36063234UL,0x15051114UL,0x22022220UL,0x38083038UL,
|
||||
0x34C4F0F4UL,0x2787A3A4UL,0x05454144UL,0x0C4C404CUL,0x01818180UL,0x29C9E1E8UL,0x04848084UL,0x17879394UL,
|
||||
0x35053134UL,0x0BCBC3C8UL,0x0ECEC2CCUL,0x3C0C303CUL,0x31417170UL,0x11011110UL,0x07C7C3C4UL,0x09898188UL,
|
||||
0x35457174UL,0x3BCBF3F8UL,0x1ACAD2D8UL,0x38C8F0F8UL,0x14849094UL,0x19495158UL,0x02828280UL,0x04C4C0C4UL,
|
||||
0x3FCFF3FCUL,0x09494148UL,0x39093138UL,0x27476364UL,0x00C0C0C0UL,0x0FCFC3CCUL,0x17C7D3D4UL,0x3888B0B8UL,
|
||||
0x0F0F030CUL,0x0E8E828CUL,0x02424240UL,0x23032320UL,0x11819190UL,0x2C4C606CUL,0x1BCBD3D8UL,0x2484A0A4UL,
|
||||
0x34043034UL,0x31C1F1F0UL,0x08484048UL,0x02C2C2C0UL,0x2F4F636CUL,0x3D0D313CUL,0x2D0D212CUL,0x00404040UL,
|
||||
0x3E8EB2BCUL,0x3E0E323CUL,0x3C8CB0BCUL,0x01C1C1C0UL,0x2A8AA2A8UL,0x3A8AB2B8UL,0x0E4E424CUL,0x15455154UL,
|
||||
0x3B0B3338UL,0x1CCCD0DCUL,0x28486068UL,0x3F4F737CUL,0x1C8C909CUL,0x18C8D0D8UL,0x0A4A4248UL,0x16465254UL,
|
||||
0x37477374UL,0x2080A0A0UL,0x2DCDE1ECUL,0x06464244UL,0x3585B1B4UL,0x2B0B2328UL,0x25456164UL,0x3ACAF2F8UL,
|
||||
0x23C3E3E0UL,0x3989B1B8UL,0x3181B1B0UL,0x1F8F939CUL,0x1E4E525CUL,0x39C9F1F8UL,0x26C6E2E4UL,0x3282B2B0UL,
|
||||
0x31013130UL,0x2ACAE2E8UL,0x2D4D616CUL,0x1F4F535CUL,0x24C4E0E4UL,0x30C0F0F0UL,0x0DCDC1CCUL,0x08888088UL,
|
||||
0x16061214UL,0x3A0A3238UL,0x18485058UL,0x14C4D0D4UL,0x22426260UL,0x29092128UL,0x07070304UL,0x33033330UL,
|
||||
0x28C8E0E8UL,0x1B0B1318UL,0x05050104UL,0x39497178UL,0x10809090UL,0x2A4A6268UL,0x2A0A2228UL,0x1A8A9298UL
|
||||
};
|
||||
|
||||
static const ulong32 SS1[256] = {
|
||||
0x38380830UL,0xE828C8E0UL,0x2C2D0D21UL,0xA42686A2UL,0xCC0FCFC3UL,0xDC1ECED2UL,0xB03383B3UL,0xB83888B0UL,
|
||||
0xAC2F8FA3UL,0x60204060UL,0x54154551UL,0xC407C7C3UL,0x44044440UL,0x6C2F4F63UL,0x682B4B63UL,0x581B4B53UL,
|
||||
0xC003C3C3UL,0x60224262UL,0x30330333UL,0xB43585B1UL,0x28290921UL,0xA02080A0UL,0xE022C2E2UL,0xA42787A3UL,
|
||||
0xD013C3D3UL,0x90118191UL,0x10110111UL,0x04060602UL,0x1C1C0C10UL,0xBC3C8CB0UL,0x34360632UL,0x480B4B43UL,
|
||||
0xEC2FCFE3UL,0x88088880UL,0x6C2C4C60UL,0xA82888A0UL,0x14170713UL,0xC404C4C0UL,0x14160612UL,0xF434C4F0UL,
|
||||
0xC002C2C2UL,0x44054541UL,0xE021C1E1UL,0xD416C6D2UL,0x3C3F0F33UL,0x3C3D0D31UL,0x8C0E8E82UL,0x98188890UL,
|
||||
0x28280820UL,0x4C0E4E42UL,0xF436C6F2UL,0x3C3E0E32UL,0xA42585A1UL,0xF839C9F1UL,0x0C0D0D01UL,0xDC1FCFD3UL,
|
||||
0xD818C8D0UL,0x282B0B23UL,0x64264662UL,0x783A4A72UL,0x24270723UL,0x2C2F0F23UL,0xF031C1F1UL,0x70324272UL,
|
||||
0x40024242UL,0xD414C4D0UL,0x40014141UL,0xC000C0C0UL,0x70334373UL,0x64274763UL,0xAC2C8CA0UL,0x880B8B83UL,
|
||||
0xF437C7F3UL,0xAC2D8DA1UL,0x80008080UL,0x1C1F0F13UL,0xC80ACAC2UL,0x2C2C0C20UL,0xA82A8AA2UL,0x34340430UL,
|
||||
0xD012C2D2UL,0x080B0B03UL,0xEC2ECEE2UL,0xE829C9E1UL,0x5C1D4D51UL,0x94148490UL,0x18180810UL,0xF838C8F0UL,
|
||||
0x54174753UL,0xAC2E8EA2UL,0x08080800UL,0xC405C5C1UL,0x10130313UL,0xCC0DCDC1UL,0x84068682UL,0xB83989B1UL,
|
||||
0xFC3FCFF3UL,0x7C3D4D71UL,0xC001C1C1UL,0x30310131UL,0xF435C5F1UL,0x880A8A82UL,0x682A4A62UL,0xB03181B1UL,
|
||||
0xD011C1D1UL,0x20200020UL,0xD417C7D3UL,0x00020202UL,0x20220222UL,0x04040400UL,0x68284860UL,0x70314171UL,
|
||||
0x04070703UL,0xD81BCBD3UL,0x9C1D8D91UL,0x98198991UL,0x60214161UL,0xBC3E8EB2UL,0xE426C6E2UL,0x58194951UL,
|
||||
0xDC1DCDD1UL,0x50114151UL,0x90108090UL,0xDC1CCCD0UL,0x981A8A92UL,0xA02383A3UL,0xA82B8BA3UL,0xD010C0D0UL,
|
||||
0x80018181UL,0x0C0F0F03UL,0x44074743UL,0x181A0A12UL,0xE023C3E3UL,0xEC2CCCE0UL,0x8C0D8D81UL,0xBC3F8FB3UL,
|
||||
0x94168692UL,0x783B4B73UL,0x5C1C4C50UL,0xA02282A2UL,0xA02181A1UL,0x60234363UL,0x20230323UL,0x4C0D4D41UL,
|
||||
0xC808C8C0UL,0x9C1E8E92UL,0x9C1C8C90UL,0x383A0A32UL,0x0C0C0C00UL,0x2C2E0E22UL,0xB83A8AB2UL,0x6C2E4E62UL,
|
||||
0x9C1F8F93UL,0x581A4A52UL,0xF032C2F2UL,0x90128292UL,0xF033C3F3UL,0x48094941UL,0x78384870UL,0xCC0CCCC0UL,
|
||||
0x14150511UL,0xF83BCBF3UL,0x70304070UL,0x74354571UL,0x7C3F4F73UL,0x34350531UL,0x10100010UL,0x00030303UL,
|
||||
0x64244460UL,0x6C2D4D61UL,0xC406C6C2UL,0x74344470UL,0xD415C5D1UL,0xB43484B0UL,0xE82ACAE2UL,0x08090901UL,
|
||||
0x74364672UL,0x18190911UL,0xFC3ECEF2UL,0x40004040UL,0x10120212UL,0xE020C0E0UL,0xBC3D8DB1UL,0x04050501UL,
|
||||
0xF83ACAF2UL,0x00010101UL,0xF030C0F0UL,0x282A0A22UL,0x5C1E4E52UL,0xA82989A1UL,0x54164652UL,0x40034343UL,
|
||||
0x84058581UL,0x14140410UL,0x88098981UL,0x981B8B93UL,0xB03080B0UL,0xE425C5E1UL,0x48084840UL,0x78394971UL,
|
||||
0x94178793UL,0xFC3CCCF0UL,0x1C1E0E12UL,0x80028282UL,0x20210121UL,0x8C0C8C80UL,0x181B0B13UL,0x5C1F4F53UL,
|
||||
0x74374773UL,0x54144450UL,0xB03282B2UL,0x1C1D0D11UL,0x24250521UL,0x4C0F4F43UL,0x00000000UL,0x44064642UL,
|
||||
0xEC2DCDE1UL,0x58184850UL,0x50124252UL,0xE82BCBE3UL,0x7C3E4E72UL,0xD81ACAD2UL,0xC809C9C1UL,0xFC3DCDF1UL,
|
||||
0x30300030UL,0x94158591UL,0x64254561UL,0x3C3C0C30UL,0xB43686B2UL,0xE424C4E0UL,0xB83B8BB3UL,0x7C3C4C70UL,
|
||||
0x0C0E0E02UL,0x50104050UL,0x38390931UL,0x24260622UL,0x30320232UL,0x84048480UL,0x68294961UL,0x90138393UL,
|
||||
0x34370733UL,0xE427C7E3UL,0x24240420UL,0xA42484A0UL,0xC80BCBC3UL,0x50134353UL,0x080A0A02UL,0x84078783UL,
|
||||
0xD819C9D1UL,0x4C0C4C40UL,0x80038383UL,0x8C0F8F83UL,0xCC0ECEC2UL,0x383B0B33UL,0x480A4A42UL,0xB43787B3UL
|
||||
};
|
||||
|
||||
static const ulong32 SS2[256] = {
|
||||
0xA1A82989UL,0x81840585UL,0xD2D416C6UL,0xD3D013C3UL,0x50541444UL,0x111C1D0DUL,0xA0AC2C8CUL,0x21242505UL,
|
||||
0x515C1D4DUL,0x43400343UL,0x10181808UL,0x121C1E0EUL,0x51501141UL,0xF0FC3CCCUL,0xC2C80ACAUL,0x63602343UL,
|
||||
0x20282808UL,0x40440444UL,0x20202000UL,0x919C1D8DUL,0xE0E020C0UL,0xE2E022C2UL,0xC0C808C8UL,0x13141707UL,
|
||||
0xA1A42585UL,0x838C0F8FUL,0x03000303UL,0x73783B4BUL,0xB3B83B8BUL,0x13101303UL,0xD2D012C2UL,0xE2EC2ECEUL,
|
||||
0x70703040UL,0x808C0C8CUL,0x333C3F0FUL,0xA0A82888UL,0x32303202UL,0xD1DC1DCDUL,0xF2F436C6UL,0x70743444UL,
|
||||
0xE0EC2CCCUL,0x91941585UL,0x03080B0BUL,0x53541747UL,0x505C1C4CUL,0x53581B4BUL,0xB1BC3D8DUL,0x01000101UL,
|
||||
0x20242404UL,0x101C1C0CUL,0x73703343UL,0x90981888UL,0x10101000UL,0xC0CC0CCCUL,0xF2F032C2UL,0xD1D819C9UL,
|
||||
0x202C2C0CUL,0xE3E427C7UL,0x72703242UL,0x83800383UL,0x93981B8BUL,0xD1D011C1UL,0x82840686UL,0xC1C809C9UL,
|
||||
0x60602040UL,0x50501040UL,0xA3A02383UL,0xE3E82BCBUL,0x010C0D0DUL,0xB2B43686UL,0x929C1E8EUL,0x434C0F4FUL,
|
||||
0xB3B43787UL,0x52581A4AUL,0xC2C406C6UL,0x70783848UL,0xA2A42686UL,0x12101202UL,0xA3AC2F8FUL,0xD1D415C5UL,
|
||||
0x61602141UL,0xC3C003C3UL,0xB0B43484UL,0x41400141UL,0x52501242UL,0x717C3D4DUL,0x818C0D8DUL,0x00080808UL,
|
||||
0x131C1F0FUL,0x91981989UL,0x00000000UL,0x11181909UL,0x00040404UL,0x53501343UL,0xF3F437C7UL,0xE1E021C1UL,
|
||||
0xF1FC3DCDUL,0x72743646UL,0x232C2F0FUL,0x23242707UL,0xB0B03080UL,0x83880B8BUL,0x020C0E0EUL,0xA3A82B8BUL,
|
||||
0xA2A02282UL,0x626C2E4EUL,0x93901383UL,0x414C0D4DUL,0x61682949UL,0x707C3C4CUL,0x01080909UL,0x02080A0AUL,
|
||||
0xB3BC3F8FUL,0xE3EC2FCFUL,0xF3F033C3UL,0xC1C405C5UL,0x83840787UL,0x10141404UL,0xF2FC3ECEUL,0x60642444UL,
|
||||
0xD2DC1ECEUL,0x222C2E0EUL,0x43480B4BUL,0x12181A0AUL,0x02040606UL,0x21202101UL,0x63682B4BUL,0x62642646UL,
|
||||
0x02000202UL,0xF1F435C5UL,0x92901282UL,0x82880A8AUL,0x000C0C0CUL,0xB3B03383UL,0x727C3E4EUL,0xD0D010C0UL,
|
||||
0x72783A4AUL,0x43440747UL,0x92941686UL,0xE1E425C5UL,0x22242606UL,0x80800080UL,0xA1AC2D8DUL,0xD3DC1FCFUL,
|
||||
0xA1A02181UL,0x30303000UL,0x33343707UL,0xA2AC2E8EUL,0x32343606UL,0x11141505UL,0x22202202UL,0x30383808UL,
|
||||
0xF0F434C4UL,0xA3A42787UL,0x41440545UL,0x404C0C4CUL,0x81800181UL,0xE1E829C9UL,0x80840484UL,0x93941787UL,
|
||||
0x31343505UL,0xC3C80BCBUL,0xC2CC0ECEUL,0x303C3C0CUL,0x71703141UL,0x11101101UL,0xC3C407C7UL,0x81880989UL,
|
||||
0x71743545UL,0xF3F83BCBUL,0xD2D81ACAUL,0xF0F838C8UL,0x90941484UL,0x51581949UL,0x82800282UL,0xC0C404C4UL,
|
||||
0xF3FC3FCFUL,0x41480949UL,0x31383909UL,0x63642747UL,0xC0C000C0UL,0xC3CC0FCFUL,0xD3D417C7UL,0xB0B83888UL,
|
||||
0x030C0F0FUL,0x828C0E8EUL,0x42400242UL,0x23202303UL,0x91901181UL,0x606C2C4CUL,0xD3D81BCBUL,0xA0A42484UL,
|
||||
0x30343404UL,0xF1F031C1UL,0x40480848UL,0xC2C002C2UL,0x636C2F4FUL,0x313C3D0DUL,0x212C2D0DUL,0x40400040UL,
|
||||
0xB2BC3E8EUL,0x323C3E0EUL,0xB0BC3C8CUL,0xC1C001C1UL,0xA2A82A8AUL,0xB2B83A8AUL,0x424C0E4EUL,0x51541545UL,
|
||||
0x33383B0BUL,0xD0DC1CCCUL,0x60682848UL,0x737C3F4FUL,0x909C1C8CUL,0xD0D818C8UL,0x42480A4AUL,0x52541646UL,
|
||||
0x73743747UL,0xA0A02080UL,0xE1EC2DCDUL,0x42440646UL,0xB1B43585UL,0x23282B0BUL,0x61642545UL,0xF2F83ACAUL,
|
||||
0xE3E023C3UL,0xB1B83989UL,0xB1B03181UL,0x939C1F8FUL,0x525C1E4EUL,0xF1F839C9UL,0xE2E426C6UL,0xB2B03282UL,
|
||||
0x31303101UL,0xE2E82ACAUL,0x616C2D4DUL,0x535C1F4FUL,0xE0E424C4UL,0xF0F030C0UL,0xC1CC0DCDUL,0x80880888UL,
|
||||
0x12141606UL,0x32383A0AUL,0x50581848UL,0xD0D414C4UL,0x62602242UL,0x21282909UL,0x03040707UL,0x33303303UL,
|
||||
0xE0E828C8UL,0x13181B0BUL,0x01040505UL,0x71783949UL,0x90901080UL,0x62682A4AUL,0x22282A0AUL,0x92981A8AUL
|
||||
};
|
||||
|
||||
static const ulong32 SS3[256] = {
|
||||
0x08303838UL,0xC8E0E828UL,0x0D212C2DUL,0x86A2A426UL,0xCFC3CC0FUL,0xCED2DC1EUL,0x83B3B033UL,0x88B0B838UL,
|
||||
0x8FA3AC2FUL,0x40606020UL,0x45515415UL,0xC7C3C407UL,0x44404404UL,0x4F636C2FUL,0x4B63682BUL,0x4B53581BUL,
|
||||
0xC3C3C003UL,0x42626022UL,0x03333033UL,0x85B1B435UL,0x09212829UL,0x80A0A020UL,0xC2E2E022UL,0x87A3A427UL,
|
||||
0xC3D3D013UL,0x81919011UL,0x01111011UL,0x06020406UL,0x0C101C1CUL,0x8CB0BC3CUL,0x06323436UL,0x4B43480BUL,
|
||||
0xCFE3EC2FUL,0x88808808UL,0x4C606C2CUL,0x88A0A828UL,0x07131417UL,0xC4C0C404UL,0x06121416UL,0xC4F0F434UL,
|
||||
0xC2C2C002UL,0x45414405UL,0xC1E1E021UL,0xC6D2D416UL,0x0F333C3FUL,0x0D313C3DUL,0x8E828C0EUL,0x88909818UL,
|
||||
0x08202828UL,0x4E424C0EUL,0xC6F2F436UL,0x0E323C3EUL,0x85A1A425UL,0xC9F1F839UL,0x0D010C0DUL,0xCFD3DC1FUL,
|
||||
0xC8D0D818UL,0x0B23282BUL,0x46626426UL,0x4A72783AUL,0x07232427UL,0x0F232C2FUL,0xC1F1F031UL,0x42727032UL,
|
||||
0x42424002UL,0xC4D0D414UL,0x41414001UL,0xC0C0C000UL,0x43737033UL,0x47636427UL,0x8CA0AC2CUL,0x8B83880BUL,
|
||||
0xC7F3F437UL,0x8DA1AC2DUL,0x80808000UL,0x0F131C1FUL,0xCAC2C80AUL,0x0C202C2CUL,0x8AA2A82AUL,0x04303434UL,
|
||||
0xC2D2D012UL,0x0B03080BUL,0xCEE2EC2EUL,0xC9E1E829UL,0x4D515C1DUL,0x84909414UL,0x08101818UL,0xC8F0F838UL,
|
||||
0x47535417UL,0x8EA2AC2EUL,0x08000808UL,0xC5C1C405UL,0x03131013UL,0xCDC1CC0DUL,0x86828406UL,0x89B1B839UL,
|
||||
0xCFF3FC3FUL,0x4D717C3DUL,0xC1C1C001UL,0x01313031UL,0xC5F1F435UL,0x8A82880AUL,0x4A62682AUL,0x81B1B031UL,
|
||||
0xC1D1D011UL,0x00202020UL,0xC7D3D417UL,0x02020002UL,0x02222022UL,0x04000404UL,0x48606828UL,0x41717031UL,
|
||||
0x07030407UL,0xCBD3D81BUL,0x8D919C1DUL,0x89919819UL,0x41616021UL,0x8EB2BC3EUL,0xC6E2E426UL,0x49515819UL,
|
||||
0xCDD1DC1DUL,0x41515011UL,0x80909010UL,0xCCD0DC1CUL,0x8A92981AUL,0x83A3A023UL,0x8BA3A82BUL,0xC0D0D010UL,
|
||||
0x81818001UL,0x0F030C0FUL,0x47434407UL,0x0A12181AUL,0xC3E3E023UL,0xCCE0EC2CUL,0x8D818C0DUL,0x8FB3BC3FUL,
|
||||
0x86929416UL,0x4B73783BUL,0x4C505C1CUL,0x82A2A022UL,0x81A1A021UL,0x43636023UL,0x03232023UL,0x4D414C0DUL,
|
||||
0xC8C0C808UL,0x8E929C1EUL,0x8C909C1CUL,0x0A32383AUL,0x0C000C0CUL,0x0E222C2EUL,0x8AB2B83AUL,0x4E626C2EUL,
|
||||
0x8F939C1FUL,0x4A52581AUL,0xC2F2F032UL,0x82929012UL,0xC3F3F033UL,0x49414809UL,0x48707838UL,0xCCC0CC0CUL,
|
||||
0x05111415UL,0xCBF3F83BUL,0x40707030UL,0x45717435UL,0x4F737C3FUL,0x05313435UL,0x00101010UL,0x03030003UL,
|
||||
0x44606424UL,0x4D616C2DUL,0xC6C2C406UL,0x44707434UL,0xC5D1D415UL,0x84B0B434UL,0xCAE2E82AUL,0x09010809UL,
|
||||
0x46727436UL,0x09111819UL,0xCEF2FC3EUL,0x40404000UL,0x02121012UL,0xC0E0E020UL,0x8DB1BC3DUL,0x05010405UL,
|
||||
0xCAF2F83AUL,0x01010001UL,0xC0F0F030UL,0x0A22282AUL,0x4E525C1EUL,0x89A1A829UL,0x46525416UL,0x43434003UL,
|
||||
0x85818405UL,0x04101414UL,0x89818809UL,0x8B93981BUL,0x80B0B030UL,0xC5E1E425UL,0x48404808UL,0x49717839UL,
|
||||
0x87939417UL,0xCCF0FC3CUL,0x0E121C1EUL,0x82828002UL,0x01212021UL,0x8C808C0CUL,0x0B13181BUL,0x4F535C1FUL,
|
||||
0x47737437UL,0x44505414UL,0x82B2B032UL,0x0D111C1DUL,0x05212425UL,0x4F434C0FUL,0x00000000UL,0x46424406UL,
|
||||
0xCDE1EC2DUL,0x48505818UL,0x42525012UL,0xCBE3E82BUL,0x4E727C3EUL,0xCAD2D81AUL,0xC9C1C809UL,0xCDF1FC3DUL,
|
||||
0x00303030UL,0x85919415UL,0x45616425UL,0x0C303C3CUL,0x86B2B436UL,0xC4E0E424UL,0x8BB3B83BUL,0x4C707C3CUL,
|
||||
0x0E020C0EUL,0x40505010UL,0x09313839UL,0x06222426UL,0x02323032UL,0x84808404UL,0x49616829UL,0x83939013UL,
|
||||
0x07333437UL,0xC7E3E427UL,0x04202424UL,0x84A0A424UL,0xCBC3C80BUL,0x43535013UL,0x0A02080AUL,0x87838407UL,
|
||||
0xC9D1D819UL,0x4C404C0CUL,0x83838003UL,0x8F838C0FUL,0xCEC2CC0EUL,0x0B33383BUL,0x4A42480AUL,0x87B3B437UL
|
||||
};
|
||||
|
||||
static const ulong32 KCi[16] = {
|
||||
0x9E3779B9,0x3C6EF373,
|
||||
0x78DDE6E6,0xF1BBCDCC,
|
||||
0xE3779B99,0xC6EF3733,
|
||||
0x8DDE6E67,0x1BBCDCCF,
|
||||
0x3779B99E,0x6EF3733C,
|
||||
0xDDE6E678,0xBBCDCCF1,
|
||||
0x779B99E3,0xEF3733C6,
|
||||
0xDE6E678D,0xBCDCCF1B
|
||||
};
|
||||
|
||||
#define G(x) (SS3[((x)>>24)&255] ^ SS2[((x)>>16)&255] ^ SS1[((x)>>8)&255] ^ SS0[(x)&255])
|
||||
|
||||
#define F(L1, L2, R1, R2, K1, K2) \
|
||||
T2 = G((R1 ^ K1) ^ (R2 ^ K2)); \
|
||||
T = G( G(T2 + (R1 ^ K1)) + T2); \
|
||||
L2 ^= T; \
|
||||
L1 ^= (T + G(T2 + (R1 ^ K1))); \
|
||||
|
||||
/**
|
||||
Initialize the SEED block cipher
|
||||
@param key The symmetric key you wish to pass
|
||||
@param keylen The key length in bytes
|
||||
@param num_rounds The number of rounds desired (0 for default)
|
||||
@param skey The key in as scheduled by this function.
|
||||
@return CRYPT_OK if successful
|
||||
*/
|
||||
int kseed_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey)
|
||||
{
|
||||
int i;
|
||||
ulong32 tmp, k1, k2, k3, k4;
|
||||
|
||||
if (keylen != 16) {
|
||||
return CRYPT_INVALID_KEYSIZE;
|
||||
}
|
||||
|
||||
if (num_rounds != 16 && num_rounds != 0) {
|
||||
return CRYPT_INVALID_ROUNDS;
|
||||
}
|
||||
|
||||
/* load key */
|
||||
LOAD32H(k1, key);
|
||||
LOAD32H(k2, key+4);
|
||||
LOAD32H(k3, key+8);
|
||||
LOAD32H(k4, key+12);
|
||||
|
||||
for (i = 0; i < 16; i++) {
|
||||
skey->kseed.K[2*i+0] = G(k1 + k3 - KCi[i]);
|
||||
skey->kseed.K[2*i+1] = G(k2 - k4 + KCi[i]);
|
||||
if (i&1) {
|
||||
tmp = k3;
|
||||
k3 = ((k3 << 8) | (k4 >> 24)) & 0xFFFFFFFF;
|
||||
k4 = ((k4 << 8) | (tmp >> 24)) & 0xFFFFFFFF;
|
||||
} else {
|
||||
tmp = k1;
|
||||
k1 = ((k1 >> 8) | (k2 << 24)) & 0xFFFFFFFF;
|
||||
k2 = ((k2 >> 8) | (tmp << 24)) & 0xFFFFFFFF;
|
||||
}
|
||||
/* reverse keys for decrypt */
|
||||
skey->kseed.dK[2*(15-i)+0] = skey->kseed.K[2*i+0];
|
||||
skey->kseed.dK[2*(15-i)+1] = skey->kseed.K[2*i+1];
|
||||
}
|
||||
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
static void rounds(ulong32 *P, ulong32 *K)
|
||||
{
|
||||
ulong32 T, T2;
|
||||
int i;
|
||||
for (i = 0; i < 16; i += 2) {
|
||||
F(P[0], P[1], P[2], P[3], K[0], K[1]);
|
||||
F(P[2], P[3], P[0], P[1], K[2], K[3]);
|
||||
K += 4;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Encrypts a block of text with SEED
|
||||
@param pt The input plaintext (16 bytes)
|
||||
@param ct The output ciphertext (16 bytes)
|
||||
@param skey The key as scheduled
|
||||
@return CRYPT_OK if successful
|
||||
*/
|
||||
int kseed_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
|
||||
{
|
||||
ulong32 P[4];
|
||||
LOAD32H(P[0], pt);
|
||||
LOAD32H(P[1], pt+4);
|
||||
LOAD32H(P[2], pt+8);
|
||||
LOAD32H(P[3], pt+12);
|
||||
rounds(P, skey->kseed.K);
|
||||
STORE32H(P[2], ct);
|
||||
STORE32H(P[3], ct+4);
|
||||
STORE32H(P[0], ct+8);
|
||||
STORE32H(P[1], ct+12);
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
Decrypts a block of text with SEED
|
||||
@param ct The input ciphertext (16 bytes)
|
||||
@param pt The output plaintext (16 bytes)
|
||||
@param skey The key as scheduled
|
||||
@return CRYPT_OK if successful
|
||||
*/
|
||||
int kseed_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
|
||||
{
|
||||
ulong32 P[4];
|
||||
LOAD32H(P[0], ct);
|
||||
LOAD32H(P[1], ct+4);
|
||||
LOAD32H(P[2], ct+8);
|
||||
LOAD32H(P[3], ct+12);
|
||||
rounds(P, skey->kseed.dK);
|
||||
STORE32H(P[2], pt);
|
||||
STORE32H(P[3], pt+4);
|
||||
STORE32H(P[0], pt+8);
|
||||
STORE32H(P[1], pt+12);
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
/** Terminate the context
|
||||
@param skey The scheduled key
|
||||
*/
|
||||
void kseed_done(symmetric_key *skey)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
Performs a self-test of the SEED block cipher
|
||||
@return CRYPT_OK if functional, CRYPT_NOP if self-test has been disabled
|
||||
*/
|
||||
int kseed_test(void)
|
||||
{
|
||||
#if !defined(LTC_TEST)
|
||||
return CRYPT_NOP;
|
||||
#else
|
||||
static const struct test {
|
||||
unsigned char pt[16], ct[16], key[16];
|
||||
} tests[] = {
|
||||
|
||||
{
|
||||
{ 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F },
|
||||
{ 0x5E,0xBA,0xC6,0xE0,0x05,0x4E,0x16,0x68,0x19,0xAF,0xF1,0xCC,0x6D,0x34,0x6C,0xDB },
|
||||
{ 0 },
|
||||
},
|
||||
|
||||
{
|
||||
{ 0 },
|
||||
{ 0xC1,0x1F,0x22,0xF2,0x01,0x40,0x50,0x50,0x84,0x48,0x35,0x97,0xE4,0x37,0x0F,0x43 },
|
||||
{ 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F },
|
||||
},
|
||||
|
||||
{
|
||||
{ 0x83,0xA2,0xF8,0xA2,0x88,0x64,0x1F,0xB9,0xA4,0xE9,0xA5,0xCC,0x2F,0x13,0x1C,0x7D },
|
||||
{ 0xEE,0x54,0xD1,0x3E,0xBC,0xAE,0x70,0x6D,0x22,0x6B,0xC3,0x14,0x2C,0xD4,0x0D,0x4A },
|
||||
{ 0x47,0x06,0x48,0x08,0x51,0xE6,0x1B,0xE8,0x5D,0x74,0xBF,0xB3,0xFD,0x95,0x61,0x85 },
|
||||
},
|
||||
|
||||
{
|
||||
{ 0xB4,0x1E,0x6B,0xE2,0xEB,0xA8,0x4A,0x14,0x8E,0x2E,0xED,0x84,0x59,0x3C,0x5E,0xC7 },
|
||||
{ 0x9B,0x9B,0x7B,0xFC,0xD1,0x81,0x3C,0xB9,0x5D,0x0B,0x36,0x18,0xF4,0x0F,0x51,0x22 },
|
||||
{ 0x28,0xDB,0xC3,0xBC,0x49,0xFF,0xD8,0x7D,0xCF,0xA5,0x09,0xB1,0x1D,0x42,0x2B,0xE7 },
|
||||
}
|
||||
};
|
||||
int x;
|
||||
unsigned char buf[2][16];
|
||||
symmetric_key skey;
|
||||
|
||||
for (x = 0; x < (int)(sizeof(tests)/sizeof(tests[0])); x++) {
|
||||
kseed_setup(tests[x].key, 16, 0, &skey);
|
||||
kseed_ecb_encrypt(tests[x].pt, buf[0], &skey);
|
||||
kseed_ecb_decrypt(buf[0], buf[1], &skey);
|
||||
if (XMEMCMP(buf[0], tests[x].ct, 16) || XMEMCMP(buf[1], tests[x].pt, 16)) {
|
||||
return CRYPT_FAIL_TESTVECTOR;
|
||||
}
|
||||
}
|
||||
return CRYPT_OK;
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
Gets suitable key size
|
||||
@param keysize [in/out] The length of the recommended key (in bytes). This function will store the suitable size back in this variable.
|
||||
@return CRYPT_OK if the input key size is acceptable.
|
||||
*/
|
||||
int kseed_keysize(int *keysize)
|
||||
{
|
||||
LTC_ARGCHK(keysize != NULL);
|
||||
if (*keysize >= 16) {
|
||||
*keysize = 16;
|
||||
} else {
|
||||
return CRYPT_INVALID_KEYSIZE;
|
||||
}
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/ciphers/kseed.c,v $ */
|
||||
/* $Revision: 1.8 $ */
|
||||
/* $Date: 2006/11/08 23:01:06 $ */
|
||||
@@ -6,7 +6,7 @@
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
*/
|
||||
/**
|
||||
@file noekeon.c
|
||||
@@ -27,7 +27,7 @@ const struct ltc_cipher_descriptor noekeon_desc =
|
||||
&noekeon_test,
|
||||
&noekeon_done,
|
||||
&noekeon_keysize,
|
||||
NULL, NULL, NULL, NULL, NULL, NULL, NULL
|
||||
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
|
||||
};
|
||||
|
||||
static const ulong32 RC[] = {
|
||||
@@ -107,11 +107,12 @@ int noekeon_setup(const unsigned char *key, int keylen, int num_rounds, symmetri
|
||||
@param pt The input plaintext (16 bytes)
|
||||
@param ct The output ciphertext (16 bytes)
|
||||
@param skey The key as scheduled
|
||||
@return CRYPT_OK if successful
|
||||
*/
|
||||
#ifdef LTC_CLEAN_STACK
|
||||
static void _noekeon_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
|
||||
static int _noekeon_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
|
||||
#else
|
||||
void noekeon_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
|
||||
int noekeon_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
|
||||
#endif
|
||||
{
|
||||
ulong32 a,b,c,d,temp;
|
||||
@@ -142,13 +143,16 @@ void noekeon_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_k
|
||||
|
||||
STORE32H(a,&ct[0]); STORE32H(b,&ct[4]);
|
||||
STORE32H(c,&ct[8]); STORE32H(d,&ct[12]);
|
||||
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
#ifdef LTC_CLEAN_STACK
|
||||
void noekeon_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
|
||||
int noekeon_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
|
||||
{
|
||||
_noekeon_ecb_encrypt(pt, ct, skey);
|
||||
int err = _noekeon_ecb_encrypt(pt, ct, skey);
|
||||
burn_stack(sizeof(ulong32) * 5 + sizeof(int));
|
||||
return CRYPT_OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -157,11 +161,12 @@ void noekeon_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_k
|
||||
@param ct The input ciphertext (16 bytes)
|
||||
@param pt The output plaintext (16 bytes)
|
||||
@param skey The key as scheduled
|
||||
@return CRYPT_OK if successful
|
||||
*/
|
||||
#ifdef LTC_CLEAN_STACK
|
||||
static void _noekeon_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
|
||||
static int _noekeon_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
|
||||
#else
|
||||
void noekeon_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
|
||||
int noekeon_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
|
||||
#endif
|
||||
{
|
||||
ulong32 a,b,c,d, temp;
|
||||
@@ -192,13 +197,15 @@ void noekeon_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_k
|
||||
a ^= RC[0];
|
||||
STORE32H(a,&pt[0]); STORE32H(b, &pt[4]);
|
||||
STORE32H(c,&pt[8]); STORE32H(d, &pt[12]);
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
#ifdef LTC_CLEAN_STACK
|
||||
void noekeon_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
|
||||
int noekeon_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
|
||||
{
|
||||
_noekeon_ecb_decrypt(ct, pt, skey);
|
||||
int err = _noekeon_ecb_decrypt(ct, pt, skey);
|
||||
burn_stack(sizeof(ulong32) * 5 + sizeof(int));
|
||||
return err;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -235,10 +242,10 @@ int noekeon_test(void)
|
||||
|
||||
noekeon_ecb_encrypt(tests[i].pt, tmp[0], &key);
|
||||
noekeon_ecb_decrypt(tmp[0], tmp[1], &key);
|
||||
if (memcmp(tmp[0], tests[i].ct, 16) || memcmp(tmp[1], tests[i].pt, 16)) {
|
||||
if (XMEMCMP(tmp[0], tests[i].ct, 16) || XMEMCMP(tmp[1], tests[i].pt, 16)) {
|
||||
#if 0
|
||||
printf("\n\nTest %d failed\n", i);
|
||||
if (memcmp(tmp[0], tests[i].ct, 16)) {
|
||||
if (XMEMCMP(tmp[0], tests[i].ct, 16)) {
|
||||
printf("CT: ");
|
||||
for (i = 0; i < 16; i++) {
|
||||
printf("%02x ", tmp[0][i]);
|
||||
@@ -292,5 +299,5 @@ int noekeon_keysize(int *keysize)
|
||||
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/ciphers/noekeon.c,v $ */
|
||||
/* $Revision: 1.7 $ */
|
||||
/* $Date: 2005/05/05 14:35:58 $ */
|
||||
/* $Revision: 1.12 $ */
|
||||
/* $Date: 2006/11/08 23:01:06 $ */
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
*/
|
||||
/**********************************************************************\
|
||||
* To commemorate the 1996 RSA Data Security Conference, the following *
|
||||
@@ -36,7 +36,7 @@ const struct ltc_cipher_descriptor rc2_desc = {
|
||||
&rc2_test,
|
||||
&rc2_done,
|
||||
&rc2_keysize,
|
||||
NULL, NULL, NULL, NULL, NULL, NULL, NULL
|
||||
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
|
||||
};
|
||||
|
||||
/* 256-entry permutation table, probably derived somehow from pi */
|
||||
@@ -125,13 +125,14 @@ int rc2_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_ke
|
||||
@param pt The input plaintext (8 bytes)
|
||||
@param ct The output ciphertext (8 bytes)
|
||||
@param skey The key as scheduled
|
||||
@return CRYPT_OK if successful
|
||||
*/
|
||||
#ifdef LTC_CLEAN_STACK
|
||||
static void _rc2_ecb_encrypt( const unsigned char *pt,
|
||||
static int _rc2_ecb_encrypt( const unsigned char *pt,
|
||||
unsigned char *ct,
|
||||
symmetric_key *skey)
|
||||
#else
|
||||
void rc2_ecb_encrypt( const unsigned char *pt,
|
||||
int rc2_ecb_encrypt( const unsigned char *pt,
|
||||
unsigned char *ct,
|
||||
symmetric_key *skey)
|
||||
#endif
|
||||
@@ -179,15 +180,18 @@ void rc2_ecb_encrypt( const unsigned char *pt,
|
||||
ct[5] = (unsigned char)(x54 >> 8);
|
||||
ct[6] = (unsigned char)x76;
|
||||
ct[7] = (unsigned char)(x76 >> 8);
|
||||
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
#ifdef LTC_CLEAN_STACK
|
||||
void rc2_ecb_encrypt( const unsigned char *pt,
|
||||
int rc2_ecb_encrypt( const unsigned char *pt,
|
||||
unsigned char *ct,
|
||||
symmetric_key *skey)
|
||||
{
|
||||
_rc2_ecb_encrypt(pt, ct, skey);
|
||||
int err = _rc2_ecb_encrypt(pt, ct, skey);
|
||||
burn_stack(sizeof(unsigned *) + sizeof(unsigned) * 5);
|
||||
return err;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -199,13 +203,14 @@ void rc2_ecb_encrypt( const unsigned char *pt,
|
||||
@param ct The input ciphertext (8 bytes)
|
||||
@param pt The output plaintext (8 bytes)
|
||||
@param skey The key as scheduled
|
||||
@return CRYPT_OK if successful
|
||||
*/
|
||||
#ifdef LTC_CLEAN_STACK
|
||||
static void _rc2_ecb_decrypt( const unsigned char *ct,
|
||||
static int _rc2_ecb_decrypt( const unsigned char *ct,
|
||||
unsigned char *pt,
|
||||
symmetric_key *skey)
|
||||
#else
|
||||
void rc2_ecb_decrypt( const unsigned char *ct,
|
||||
int rc2_ecb_decrypt( const unsigned char *ct,
|
||||
unsigned char *pt,
|
||||
symmetric_key *skey)
|
||||
#endif
|
||||
@@ -254,15 +259,18 @@ void rc2_ecb_decrypt( const unsigned char *ct,
|
||||
pt[5] = (unsigned char)(x54 >> 8);
|
||||
pt[6] = (unsigned char)x76;
|
||||
pt[7] = (unsigned char)(x76 >> 8);
|
||||
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
#ifdef LTC_CLEAN_STACK
|
||||
void rc2_ecb_decrypt( const unsigned char *ct,
|
||||
int rc2_ecb_decrypt( const unsigned char *ct,
|
||||
unsigned char *pt,
|
||||
symmetric_key *skey)
|
||||
{
|
||||
_rc2_ecb_decrypt(ct, pt, skey);
|
||||
int err = _rc2_ecb_decrypt(ct, pt, skey);
|
||||
burn_stack(sizeof(unsigned *) + sizeof(unsigned) * 4 + sizeof(int));
|
||||
return err;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -307,7 +315,7 @@ int rc2_test(void)
|
||||
rc2_ecb_encrypt(tests[x].pt, tmp[0], &skey);
|
||||
rc2_ecb_decrypt(tmp[0], tmp[1], &skey);
|
||||
|
||||
if (memcmp(tmp[0], tests[x].ct, 8) != 0 || memcmp(tmp[1], tests[x].pt, 8) != 0) {
|
||||
if (XMEMCMP(tmp[0], tests[x].ct, 8) != 0 || XMEMCMP(tmp[1], tests[x].pt, 8) != 0) {
|
||||
return CRYPT_FAIL_TESTVECTOR;
|
||||
}
|
||||
|
||||
@@ -350,5 +358,5 @@ int rc2_keysize(int *keysize)
|
||||
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/ciphers/rc2.c,v $ */
|
||||
/* $Revision: 1.7 $ */
|
||||
/* $Date: 2005/05/05 14:35:58 $ */
|
||||
/* $Revision: 1.12 $ */
|
||||
/* $Date: 2006/11/08 23:01:06 $ */
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -29,7 +29,7 @@ const struct ltc_cipher_descriptor rc5_desc =
|
||||
&rc5_test,
|
||||
&rc5_done,
|
||||
&rc5_keysize,
|
||||
NULL, NULL, NULL, NULL, NULL, NULL, NULL
|
||||
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
|
||||
};
|
||||
|
||||
static const ulong32 stab[50] = {
|
||||
@@ -123,11 +123,12 @@ int rc5_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_ke
|
||||
@param pt The input plaintext (8 bytes)
|
||||
@param ct The output ciphertext (8 bytes)
|
||||
@param skey The key as scheduled
|
||||
@return CRYPT_OK if successful
|
||||
*/
|
||||
#ifdef LTC_CLEAN_STACK
|
||||
static void _rc5_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
|
||||
static int _rc5_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
|
||||
#else
|
||||
void rc5_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
|
||||
int rc5_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
|
||||
#endif
|
||||
{
|
||||
ulong32 A, B, *K;
|
||||
@@ -159,13 +160,16 @@ void rc5_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *
|
||||
}
|
||||
STORE32L(A, &ct[0]);
|
||||
STORE32L(B, &ct[4]);
|
||||
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
#ifdef LTC_CLEAN_STACK
|
||||
void rc5_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
|
||||
int rc5_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
|
||||
{
|
||||
_rc5_ecb_encrypt(pt, ct, skey);
|
||||
int err = _rc5_ecb_encrypt(pt, ct, skey);
|
||||
burn_stack(sizeof(ulong32) * 2 + sizeof(int));
|
||||
return err;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -174,11 +178,12 @@ void rc5_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *
|
||||
@param ct The input ciphertext (8 bytes)
|
||||
@param pt The output plaintext (8 bytes)
|
||||
@param skey The key as scheduled
|
||||
@return CRYPT_OK if successful
|
||||
*/
|
||||
#ifdef LTC_CLEAN_STACK
|
||||
static void _rc5_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
|
||||
static int _rc5_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
|
||||
#else
|
||||
void rc5_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
|
||||
int rc5_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
|
||||
#endif
|
||||
{
|
||||
ulong32 A, B, *K;
|
||||
@@ -211,13 +216,16 @@ void rc5_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *
|
||||
B -= skey->rc5.K[1];
|
||||
STORE32L(A, &pt[0]);
|
||||
STORE32L(B, &pt[4]);
|
||||
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
#ifdef LTC_CLEAN_STACK
|
||||
void rc5_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
|
||||
int rc5_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
|
||||
{
|
||||
_rc5_ecb_decrypt(ct, pt, skey);
|
||||
int err = _rc5_ecb_decrypt(ct, pt, skey);
|
||||
burn_stack(sizeof(ulong32) * 2 + sizeof(int));
|
||||
return err;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -267,7 +275,7 @@ int rc5_test(void)
|
||||
rc5_ecb_decrypt(tmp[0], tmp[1], &key);
|
||||
|
||||
/* compare */
|
||||
if (memcmp(tmp[0], tests[x].ct, 8) != 0 || memcmp(tmp[1], tests[x].pt, 8) != 0) {
|
||||
if (XMEMCMP(tmp[0], tests[x].ct, 8) != 0 || XMEMCMP(tmp[1], tests[x].pt, 8) != 0) {
|
||||
return CRYPT_FAIL_TESTVECTOR;
|
||||
}
|
||||
|
||||
@@ -310,5 +318,5 @@ int rc5_keysize(int *keysize)
|
||||
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/ciphers/rc5.c,v $ */
|
||||
/* $Revision: 1.7 $ */
|
||||
/* $Date: 2005/05/05 14:35:58 $ */
|
||||
/* $Revision: 1.12 $ */
|
||||
/* $Date: 2006/11/08 23:01:06 $ */
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -28,7 +28,7 @@ const struct ltc_cipher_descriptor rc6_desc =
|
||||
&rc6_test,
|
||||
&rc6_done,
|
||||
&rc6_keysize,
|
||||
NULL, NULL, NULL, NULL, NULL, NULL, NULL
|
||||
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
|
||||
};
|
||||
|
||||
static const ulong32 stab[44] = {
|
||||
@@ -120,9 +120,9 @@ int rc6_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_ke
|
||||
@param skey The key as scheduled
|
||||
*/
|
||||
#ifdef LTC_CLEAN_STACK
|
||||
static void _rc6_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
|
||||
static int _rc6_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
|
||||
#else
|
||||
void rc6_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
|
||||
int rc6_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
|
||||
#endif
|
||||
{
|
||||
ulong32 a,b,c,d,t,u, *K;
|
||||
@@ -155,13 +155,15 @@ void rc6_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *
|
||||
a += skey->rc6.K[42];
|
||||
c += skey->rc6.K[43];
|
||||
STORE32L(a,&ct[0]);STORE32L(b,&ct[4]);STORE32L(c,&ct[8]);STORE32L(d,&ct[12]);
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
#ifdef LTC_CLEAN_STACK
|
||||
void rc6_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
|
||||
int rc6_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
|
||||
{
|
||||
_rc6_ecb_encrypt(pt, ct, skey);
|
||||
int err = _rc6_ecb_encrypt(pt, ct, skey);
|
||||
burn_stack(sizeof(ulong32) * 6 + sizeof(int));
|
||||
return err;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -172,9 +174,9 @@ void rc6_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *
|
||||
@param skey The key as scheduled
|
||||
*/
|
||||
#ifdef LTC_CLEAN_STACK
|
||||
static void _rc6_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
|
||||
static int _rc6_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
|
||||
#else
|
||||
void rc6_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
|
||||
int rc6_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
|
||||
#endif
|
||||
{
|
||||
ulong32 a,b,c,d,t,u, *K;
|
||||
@@ -208,13 +210,16 @@ void rc6_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *
|
||||
b -= skey->rc6.K[0];
|
||||
d -= skey->rc6.K[1];
|
||||
STORE32L(a,&pt[0]);STORE32L(b,&pt[4]);STORE32L(c,&pt[8]);STORE32L(d,&pt[12]);
|
||||
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
#ifdef LTC_CLEAN_STACK
|
||||
void rc6_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
|
||||
int rc6_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
|
||||
{
|
||||
_rc6_ecb_decrypt(ct, pt, skey);
|
||||
int err = _rc6_ecb_decrypt(ct, pt, skey);
|
||||
burn_stack(sizeof(ulong32) * 6 + sizeof(int));
|
||||
return err;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -280,17 +285,17 @@ int rc6_test(void)
|
||||
rc6_ecb_decrypt(tmp[0], tmp[1], &key);
|
||||
|
||||
/* compare */
|
||||
if (memcmp(tmp[0], tests[x].ct, 16) || memcmp(tmp[1], tests[x].pt, 16)) {
|
||||
if (XMEMCMP(tmp[0], tests[x].ct, 16) || XMEMCMP(tmp[1], tests[x].pt, 16)) {
|
||||
#if 0
|
||||
printf("\n\nFailed test %d\n", x);
|
||||
if (memcmp(tmp[0], tests[x].ct, 16)) {
|
||||
if (XMEMCMP(tmp[0], tests[x].ct, 16)) {
|
||||
printf("Ciphertext: ");
|
||||
for (y = 0; y < 16; y++) printf("%02x ", tmp[0][y]);
|
||||
printf("\nExpected : ");
|
||||
for (y = 0; y < 16; y++) printf("%02x ", tests[x].ct[y]);
|
||||
printf("\n");
|
||||
}
|
||||
if (memcmp(tmp[1], tests[x].pt, 16)) {
|
||||
if (XMEMCMP(tmp[1], tests[x].pt, 16)) {
|
||||
printf("Plaintext: ");
|
||||
for (y = 0; y < 16; y++) printf("%02x ", tmp[0][y]);
|
||||
printf("\nExpected : ");
|
||||
@@ -339,5 +344,5 @@ int rc6_keysize(int *keysize)
|
||||
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/ciphers/rc6.c,v $ */
|
||||
/* $Revision: 1.7 $ */
|
||||
/* $Date: 2005/05/05 14:35:58 $ */
|
||||
/* $Revision: 1.12 $ */
|
||||
/* $Date: 2006/11/08 23:01:06 $ */
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
*/
|
||||
|
||||
/*******************************************************************************
|
||||
@@ -42,7 +42,7 @@ const struct ltc_cipher_descriptor
|
||||
&safer_k64_test,
|
||||
&safer_done,
|
||||
&safer_64_keysize,
|
||||
NULL, NULL, NULL, NULL, NULL, NULL, NULL
|
||||
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
|
||||
},
|
||||
|
||||
safer_sk64_desc = {
|
||||
@@ -54,7 +54,7 @@ const struct ltc_cipher_descriptor
|
||||
&safer_sk64_test,
|
||||
&safer_done,
|
||||
&safer_64_keysize,
|
||||
NULL, NULL, NULL, NULL, NULL, NULL, NULL
|
||||
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
|
||||
},
|
||||
|
||||
safer_k128_desc = {
|
||||
@@ -66,7 +66,7 @@ const struct ltc_cipher_descriptor
|
||||
&safer_sk128_test,
|
||||
&safer_done,
|
||||
&safer_128_keysize,
|
||||
NULL, NULL, NULL, NULL, NULL, NULL, NULL
|
||||
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
|
||||
},
|
||||
|
||||
safer_sk128_desc = {
|
||||
@@ -78,7 +78,7 @@ const struct ltc_cipher_descriptor
|
||||
&safer_sk128_test,
|
||||
&safer_done,
|
||||
&safer_128_keysize,
|
||||
NULL, NULL, NULL, NULL, NULL, NULL, NULL
|
||||
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
|
||||
};
|
||||
|
||||
/******************* Constants ************************************************/
|
||||
@@ -246,11 +246,11 @@ int safer_sk128_setup(const unsigned char *key, int keylen, int numrounds, symme
|
||||
}
|
||||
|
||||
#ifdef LTC_CLEAN_STACK
|
||||
static void _safer_ecb_encrypt(const unsigned char *block_in,
|
||||
static int _safer_ecb_encrypt(const unsigned char *block_in,
|
||||
unsigned char *block_out,
|
||||
symmetric_key *skey)
|
||||
#else
|
||||
void safer_ecb_encrypt(const unsigned char *block_in,
|
||||
int safer_ecb_encrypt(const unsigned char *block_in,
|
||||
unsigned char *block_out,
|
||||
symmetric_key *skey)
|
||||
#endif
|
||||
@@ -285,24 +285,26 @@ void safer_ecb_encrypt(const unsigned char *block_in,
|
||||
block_out[2] = c & 0xFF; block_out[3] = d & 0xFF;
|
||||
block_out[4] = e & 0xFF; block_out[5] = f & 0xFF;
|
||||
block_out[6] = g & 0xFF; block_out[7] = h & 0xFF;
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
#ifdef LTC_CLEAN_STACK
|
||||
void safer_ecb_encrypt(const unsigned char *block_in,
|
||||
int safer_ecb_encrypt(const unsigned char *block_in,
|
||||
unsigned char *block_out,
|
||||
symmetric_key *skey)
|
||||
{
|
||||
_safer_ecb_encrypt(block_in, block_out, skey);
|
||||
int err = _safer_ecb_encrypt(block_in, block_out, skey);
|
||||
burn_stack(sizeof(unsigned char) * 9 + sizeof(unsigned int) + sizeof(unsigned char *));
|
||||
return err;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef LTC_CLEAN_STACK
|
||||
static void _safer_ecb_decrypt(const unsigned char *block_in,
|
||||
static int _safer_ecb_decrypt(const unsigned char *block_in,
|
||||
unsigned char *block_out,
|
||||
symmetric_key *skey)
|
||||
#else
|
||||
void safer_ecb_decrypt(const unsigned char *block_in,
|
||||
int safer_ecb_decrypt(const unsigned char *block_in,
|
||||
unsigned char *block_out,
|
||||
symmetric_key *skey)
|
||||
#endif
|
||||
@@ -338,15 +340,17 @@ void safer_ecb_decrypt(const unsigned char *block_in,
|
||||
block_out[2] = c & 0xFF; block_out[3] = d & 0xFF;
|
||||
block_out[4] = e & 0xFF; block_out[5] = f & 0xFF;
|
||||
block_out[6] = g & 0xFF; block_out[7] = h & 0xFF;
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
#ifdef LTC_CLEAN_STACK
|
||||
void safer_ecb_decrypt(const unsigned char *block_in,
|
||||
int safer_ecb_decrypt(const unsigned char *block_in,
|
||||
unsigned char *block_out,
|
||||
symmetric_key *skey)
|
||||
{
|
||||
_safer_ecb_decrypt(block_in, block_out, skey);
|
||||
int err = _safer_ecb_decrypt(block_in, block_out, skey);
|
||||
burn_stack(sizeof(unsigned char) * 9 + sizeof(unsigned int) + sizeof(unsigned char *));
|
||||
return err;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -392,7 +396,7 @@ int safer_k64_test(void)
|
||||
safer_ecb_encrypt(k64_pt, buf[0], &skey);
|
||||
safer_ecb_decrypt(buf[0], buf[1], &skey);
|
||||
|
||||
if (memcmp(buf[0], k64_ct, 8) != 0 || memcmp(buf[1], k64_pt, 8) != 0) {
|
||||
if (XMEMCMP(buf[0], k64_ct, 8) != 0 || XMEMCMP(buf[1], k64_pt, 8) != 0) {
|
||||
return CRYPT_FAIL_TESTVECTOR;
|
||||
}
|
||||
|
||||
@@ -422,7 +426,7 @@ int safer_sk64_test(void)
|
||||
safer_ecb_encrypt(sk64_pt, buf[0], &skey);
|
||||
safer_ecb_decrypt(buf[0], buf[1], &skey);
|
||||
|
||||
if (memcmp(buf[0], sk64_ct, 8) != 0 || memcmp(buf[1], sk64_pt, 8) != 0) {
|
||||
if (XMEMCMP(buf[0], sk64_ct, 8) != 0 || XMEMCMP(buf[1], sk64_pt, 8) != 0) {
|
||||
return CRYPT_FAIL_TESTVECTOR;
|
||||
}
|
||||
|
||||
@@ -464,7 +468,7 @@ int safer_sk128_test(void)
|
||||
safer_ecb_encrypt(sk128_pt, buf[0], &skey);
|
||||
safer_ecb_decrypt(buf[0], buf[1], &skey);
|
||||
|
||||
if (memcmp(buf[0], sk128_ct, 8) != 0 || memcmp(buf[1], sk128_pt, 8) != 0) {
|
||||
if (XMEMCMP(buf[0], sk128_ct, 8) != 0 || XMEMCMP(buf[1], sk128_pt, 8) != 0) {
|
||||
return CRYPT_FAIL_TESTVECTOR;
|
||||
}
|
||||
|
||||
@@ -483,5 +487,5 @@ int safer_sk128_test(void)
|
||||
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/ciphers/safer/safer.c,v $ */
|
||||
/* $Revision: 1.8 $ */
|
||||
/* $Date: 2005/05/05 14:35:58 $ */
|
||||
/* $Revision: 1.13 $ */
|
||||
/* $Date: 2006/11/08 23:01:06 $ */
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -64,5 +64,5 @@ const unsigned char safer_lbox[256] = {
|
||||
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/ciphers/safer/safer_tab.c,v $ */
|
||||
/* $Revision: 1.3 $ */
|
||||
/* $Date: 2005/05/05 14:35:58 $ */
|
||||
/* $Revision: 1.4 $ */
|
||||
/* $Date: 2006/03/31 14:15:35 $ */
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -28,7 +28,7 @@ const struct ltc_cipher_descriptor saferp_desc =
|
||||
&saferp_test,
|
||||
&saferp_done,
|
||||
&saferp_keysize,
|
||||
NULL, NULL, NULL, NULL, NULL, NULL, NULL
|
||||
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
|
||||
};
|
||||
|
||||
/* ROUND(b,i)
|
||||
@@ -329,8 +329,9 @@ int saferp_setup(const unsigned char *key, int keylen, int num_rounds, symmetric
|
||||
@param pt The input plaintext (16 bytes)
|
||||
@param ct The output ciphertext (16 bytes)
|
||||
@param skey The key as scheduled
|
||||
@return CRYPT_OK if successful
|
||||
*/
|
||||
void saferp_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
|
||||
int saferp_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
|
||||
{
|
||||
unsigned char b[16];
|
||||
int x;
|
||||
@@ -384,6 +385,7 @@ void saferp_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_ke
|
||||
#ifdef LTC_CLEAN_STACK
|
||||
zeromem(b, sizeof(b));
|
||||
#endif
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -391,8 +393,9 @@ void saferp_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_ke
|
||||
@param ct The input ciphertext (16 bytes)
|
||||
@param pt The output plaintext (16 bytes)
|
||||
@param skey The key as scheduled
|
||||
@return CRYPT_OK if successful
|
||||
*/
|
||||
void saferp_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
|
||||
int saferp_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
|
||||
{
|
||||
unsigned char b[16];
|
||||
int x;
|
||||
@@ -446,6 +449,7 @@ void saferp_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_ke
|
||||
#ifdef LTC_CLEAN_STACK
|
||||
zeromem(b, sizeof(b));
|
||||
#endif
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -503,7 +507,7 @@ int saferp_test(void)
|
||||
saferp_ecb_decrypt(tmp[0], tmp[1], &skey);
|
||||
|
||||
/* compare */
|
||||
if (memcmp(tmp[0], tests[i].ct, 16) || memcmp(tmp[1], tests[i].pt, 16)) {
|
||||
if (XMEMCMP(tmp[0], tests[i].ct, 16) || XMEMCMP(tmp[1], tests[i].pt, 16)) {
|
||||
return CRYPT_FAIL_TESTVECTOR;
|
||||
}
|
||||
|
||||
@@ -551,5 +555,5 @@ int saferp_keysize(int *keysize)
|
||||
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/ciphers/safer/saferp.c,v $ */
|
||||
/* $Revision: 1.7 $ */
|
||||
/* $Date: 2005/05/05 14:35:58 $ */
|
||||
/* $Revision: 1.12 $ */
|
||||
/* $Date: 2006/11/08 23:01:06 $ */
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -28,7 +28,7 @@ const struct ltc_cipher_descriptor skipjack_desc =
|
||||
&skipjack_test,
|
||||
&skipjack_done,
|
||||
&skipjack_keysize,
|
||||
NULL, NULL, NULL, NULL, NULL, NULL, NULL
|
||||
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
|
||||
};
|
||||
|
||||
static const unsigned char sbox[256] = {
|
||||
@@ -138,11 +138,12 @@ static unsigned ig_func(unsigned w, int *kp, unsigned char *key)
|
||||
@param pt The input plaintext (8 bytes)
|
||||
@param ct The output ciphertext (8 bytes)
|
||||
@param skey The key as scheduled
|
||||
@return CRYPT_OK if successful
|
||||
*/
|
||||
#ifdef LTC_CLEAN_STACK
|
||||
static void _skipjack_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
|
||||
static int _skipjack_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
|
||||
#else
|
||||
void skipjack_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
|
||||
int skipjack_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
|
||||
#endif
|
||||
{
|
||||
unsigned w1,w2,w3,w4,tmp,tmp1;
|
||||
@@ -183,13 +184,16 @@ void skipjack_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_
|
||||
ct[2] = (w2>>8)&255; ct[3] = w2&255;
|
||||
ct[4] = (w3>>8)&255; ct[5] = w3&255;
|
||||
ct[6] = (w4>>8)&255; ct[7] = w4&255;
|
||||
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
#ifdef LTC_CLEAN_STACK
|
||||
void skipjack_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
|
||||
int skipjack_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
|
||||
{
|
||||
_skipjack_ecb_encrypt(pt, ct, skey);
|
||||
int err = _skipjack_ecb_encrypt(pt, ct, skey);
|
||||
burn_stack(sizeof(unsigned) * 8 + sizeof(int) * 2);
|
||||
return err;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -198,11 +202,12 @@ void skipjack_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_
|
||||
@param ct The input ciphertext (8 bytes)
|
||||
@param pt The output plaintext (8 bytes)
|
||||
@param skey The key as scheduled
|
||||
@return CRYPT_OK if successful
|
||||
*/
|
||||
#ifdef LTC_CLEAN_STACK
|
||||
static void _skipjack_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
|
||||
static int _skipjack_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
|
||||
#else
|
||||
void skipjack_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
|
||||
int skipjack_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
|
||||
#endif
|
||||
{
|
||||
unsigned w1,w2,w3,w4,tmp;
|
||||
@@ -247,13 +252,16 @@ void skipjack_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_
|
||||
pt[2] = (w2>>8)&255; pt[3] = w2&255;
|
||||
pt[4] = (w3>>8)&255; pt[5] = w3&255;
|
||||
pt[6] = (w4>>8)&255; pt[7] = w4&255;
|
||||
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
#ifdef LTC_CLEAN_STACK
|
||||
void skipjack_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
|
||||
int skipjack_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
|
||||
{
|
||||
_skipjack_ecb_decrypt(ct, pt, skey);
|
||||
int err = _skipjack_ecb_decrypt(ct, pt, skey);
|
||||
burn_stack(sizeof(unsigned) * 7 + sizeof(int) * 2);
|
||||
return err;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -290,7 +298,7 @@ int skipjack_test(void)
|
||||
skipjack_ecb_decrypt(buf[0], buf[1], &key);
|
||||
|
||||
/* compare */
|
||||
if (memcmp(buf[0], tests[x].ct, 8) != 0 || memcmp(buf[1], tests[x].pt, 8) != 0) {
|
||||
if (XMEMCMP(buf[0], tests[x].ct, 8) != 0 || XMEMCMP(buf[1], tests[x].pt, 8) != 0) {
|
||||
return CRYPT_FAIL_TESTVECTOR;
|
||||
}
|
||||
|
||||
@@ -331,5 +339,5 @@ int skipjack_keysize(int *keysize)
|
||||
#endif
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/ciphers/skipjack.c,v $ */
|
||||
/* $Revision: 1.7 $ */
|
||||
/* $Date: 2005/05/05 14:35:58 $ */
|
||||
/* $Revision: 1.12 $ */
|
||||
/* $Date: 2006/11/08 23:01:06 $ */
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -35,7 +35,7 @@ const struct ltc_cipher_descriptor twofish_desc =
|
||||
&twofish_test,
|
||||
&twofish_done,
|
||||
&twofish_keysize,
|
||||
NULL, NULL, NULL, NULL, NULL, NULL, NULL
|
||||
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
|
||||
};
|
||||
|
||||
/* the two polynomials */
|
||||
@@ -414,8 +414,8 @@ int twofish_setup(const unsigned char *key, int keylen, int num_rounds, symmetri
|
||||
/* make the sboxes (large ram variant) */
|
||||
if (k == 2) {
|
||||
for (x = 0; x < 256; x++) {
|
||||
tmpx0 = sbox(0, x);
|
||||
tmpx1 = sbox(1, x);
|
||||
tmpx0 = (unsigned char)sbox(0, x);
|
||||
tmpx1 = (unsigned char)sbox(1, x);
|
||||
skey->twofish.S[0][x] = mds_column_mult(sbox(1, (sbox(0, tmpx0 ^ S[0]) ^ S[4])),0);
|
||||
skey->twofish.S[1][x] = mds_column_mult(sbox(0, (sbox(0, tmpx1 ^ S[1]) ^ S[5])),1);
|
||||
skey->twofish.S[2][x] = mds_column_mult(sbox(1, (sbox(1, tmpx0 ^ S[2]) ^ S[6])),2);
|
||||
@@ -423,8 +423,8 @@ int twofish_setup(const unsigned char *key, int keylen, int num_rounds, symmetri
|
||||
}
|
||||
} else if (k == 3) {
|
||||
for (x = 0; x < 256; x++) {
|
||||
tmpx0 = sbox(0, x);
|
||||
tmpx1 = sbox(1, x);
|
||||
tmpx0 = (unsigned char)sbox(0, x);
|
||||
tmpx1 = (unsigned char)sbox(1, x);
|
||||
skey->twofish.S[0][x] = mds_column_mult(sbox(1, (sbox(0, sbox(0, tmpx1 ^ S[0]) ^ S[4]) ^ S[8])),0);
|
||||
skey->twofish.S[1][x] = mds_column_mult(sbox(0, (sbox(0, sbox(1, tmpx1 ^ S[1]) ^ S[5]) ^ S[9])),1);
|
||||
skey->twofish.S[2][x] = mds_column_mult(sbox(1, (sbox(1, sbox(0, tmpx0 ^ S[2]) ^ S[6]) ^ S[10])),2);
|
||||
@@ -432,8 +432,8 @@ int twofish_setup(const unsigned char *key, int keylen, int num_rounds, symmetri
|
||||
}
|
||||
} else {
|
||||
for (x = 0; x < 256; x++) {
|
||||
tmpx0 = sbox(0, x);
|
||||
tmpx1 = sbox(1, x);
|
||||
tmpx0 = (unsigned char)sbox(0, x);
|
||||
tmpx1 = (unsigned char)sbox(1, x);
|
||||
skey->twofish.S[0][x] = mds_column_mult(sbox(1, (sbox(0, sbox(0, sbox(1, tmpx1 ^ S[0]) ^ S[4]) ^ S[8]) ^ S[12])),0);
|
||||
skey->twofish.S[1][x] = mds_column_mult(sbox(0, (sbox(0, sbox(1, sbox(1, tmpx0 ^ S[1]) ^ S[5]) ^ S[9]) ^ S[13])),1);
|
||||
skey->twofish.S[2][x] = mds_column_mult(sbox(1, (sbox(1, sbox(0, sbox(0, tmpx0 ^ S[2]) ^ S[6]) ^ S[10]) ^ S[14])),2);
|
||||
@@ -467,11 +467,12 @@ int twofish_setup(const unsigned char *key, int keylen, int num_rounds, symmetri
|
||||
@param pt The input plaintext (16 bytes)
|
||||
@param ct The output ciphertext (16 bytes)
|
||||
@param skey The key as scheduled
|
||||
@return CRYPT_OK if successful
|
||||
*/
|
||||
#ifdef LTC_CLEAN_STACK
|
||||
static void _twofish_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
|
||||
static int _twofish_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
|
||||
#else
|
||||
void twofish_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
|
||||
int twofish_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
|
||||
#endif
|
||||
{
|
||||
ulong32 a,b,c,d,ta,tb,tc,td,t1,t2, *k;
|
||||
@@ -521,13 +522,16 @@ void twofish_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_k
|
||||
/* store output */
|
||||
STORE32L(ta,&ct[0]); STORE32L(tb,&ct[4]);
|
||||
STORE32L(tc,&ct[8]); STORE32L(td,&ct[12]);
|
||||
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
#ifdef LTC_CLEAN_STACK
|
||||
void twofish_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
|
||||
int twofish_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
|
||||
{
|
||||
_twofish_ecb_encrypt(pt, ct, skey);
|
||||
int err = _twofish_ecb_encrypt(pt, ct, skey);
|
||||
burn_stack(sizeof(ulong32) * 10 + sizeof(int));
|
||||
return err;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -536,11 +540,12 @@ void twofish_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_k
|
||||
@param ct The input ciphertext (16 bytes)
|
||||
@param pt The output plaintext (16 bytes)
|
||||
@param skey The key as scheduled
|
||||
@return CRYPT_OK if successful
|
||||
*/
|
||||
#ifdef LTC_CLEAN_STACK
|
||||
static void _twofish_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
|
||||
static int _twofish_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
|
||||
#else
|
||||
void twofish_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
|
||||
int twofish_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
|
||||
#endif
|
||||
{
|
||||
ulong32 a,b,c,d,ta,tb,tc,td,t1,t2, *k;
|
||||
@@ -593,13 +598,15 @@ void twofish_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_k
|
||||
/* store */
|
||||
STORE32L(a, &pt[0]); STORE32L(b, &pt[4]);
|
||||
STORE32L(c, &pt[8]); STORE32L(d, &pt[12]);
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
#ifdef LTC_CLEAN_STACK
|
||||
void twofish_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
|
||||
int twofish_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
|
||||
{
|
||||
_twofish_ecb_decrypt(ct, pt, skey);
|
||||
int err =_twofish_ecb_decrypt(ct, pt, skey);
|
||||
burn_stack(sizeof(ulong32) * 10 + sizeof(int));
|
||||
return err;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -656,7 +663,10 @@ int twofish_test(void)
|
||||
}
|
||||
twofish_ecb_encrypt(tests[i].pt, tmp[0], &key);
|
||||
twofish_ecb_decrypt(tmp[0], tmp[1], &key);
|
||||
if (memcmp(tmp[0], tests[i].ct, 16) != 0 || memcmp(tmp[1], tests[i].pt, 16) != 0) {
|
||||
if (XMEMCMP(tmp[0], tests[i].ct, 16) != 0 || XMEMCMP(tmp[1], tests[i].pt, 16) != 0) {
|
||||
#if 0
|
||||
printf("Twofish failed test %d, %d, %d\n", i, XMEMCMP(tmp[0], tests[i].ct, 16), XMEMCMP(tmp[1], tests[i].pt, 16));
|
||||
#endif
|
||||
return CRYPT_FAIL_TESTVECTOR;
|
||||
}
|
||||
/* now see if we can encrypt all zero bytes 1000 times, decrypt and come back where we started */
|
||||
@@ -704,5 +714,5 @@ int twofish_keysize(int *keysize)
|
||||
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/ciphers/twofish/twofish.c,v $ */
|
||||
/* $Revision: 1.8 $ */
|
||||
/* $Date: 2005/05/05 14:35:58 $ */
|
||||
/* $Revision: 1.14 $ */
|
||||
/* $Date: 2006/12/04 21:34:03 $ */
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -492,5 +492,5 @@ static const ulong32 rs_tab7[256] = {
|
||||
#endif
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/ciphers/twofish/twofish_tab.c,v $ */
|
||||
/* $Revision: 1.3 $ */
|
||||
/* $Date: 2005/05/05 14:35:58 $ */
|
||||
/* $Revision: 1.4 $ */
|
||||
/* $Date: 2006/03/31 14:15:35 $ */
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -28,7 +28,7 @@ const struct ltc_cipher_descriptor xtea_desc =
|
||||
&xtea_test,
|
||||
&xtea_done,
|
||||
&xtea_keysize,
|
||||
NULL, NULL, NULL, NULL, NULL, NULL, NULL
|
||||
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
|
||||
};
|
||||
|
||||
int xtea_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey)
|
||||
@@ -71,8 +71,9 @@ int xtea_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_k
|
||||
@param pt The input plaintext (8 bytes)
|
||||
@param ct The output ciphertext (8 bytes)
|
||||
@param skey The key as scheduled
|
||||
@return CRYPT_OK if successful
|
||||
*/
|
||||
void xtea_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
|
||||
int xtea_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
|
||||
{
|
||||
unsigned long y, z;
|
||||
int r;
|
||||
@@ -98,6 +99,7 @@ void xtea_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key
|
||||
}
|
||||
STORE32L(y, &ct[0]);
|
||||
STORE32L(z, &ct[4]);
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -105,8 +107,9 @@ void xtea_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key
|
||||
@param ct The input ciphertext (8 bytes)
|
||||
@param pt The output plaintext (8 bytes)
|
||||
@param skey The key as scheduled
|
||||
@return CRYPT_OK if successful
|
||||
*/
|
||||
void xtea_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
|
||||
int xtea_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
|
||||
{
|
||||
unsigned long y, z;
|
||||
int r;
|
||||
@@ -132,6 +135,7 @@ void xtea_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key
|
||||
}
|
||||
STORE32L(y, &pt[0]);
|
||||
STORE32L(z, &pt[4]);
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -160,7 +164,7 @@ int xtea_test(void)
|
||||
xtea_ecb_encrypt(pt, tmp[0], &skey);
|
||||
xtea_ecb_decrypt(tmp[0], tmp[1], &skey);
|
||||
|
||||
if (memcmp(tmp[0], ct, 8) != 0 || memcmp(tmp[1], pt, 8) != 0) {
|
||||
if (XMEMCMP(tmp[0], ct, 8) != 0 || XMEMCMP(tmp[1], pt, 8) != 0) {
|
||||
return CRYPT_FAIL_TESTVECTOR;
|
||||
}
|
||||
|
||||
@@ -203,5 +207,5 @@ int xtea_keysize(int *keysize)
|
||||
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/ciphers/xtea.c,v $ */
|
||||
/* $Revision: 1.7 $ */
|
||||
/* $Date: 2005/05/05 14:35:58 $ */
|
||||
/* $Revision: 1.12 $ */
|
||||
/* $Date: 2006/11/08 23:01:06 $ */
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
@param cipher The index of the cipher desired
|
||||
@param key The secret key to use
|
||||
@param keylen The length of the secret key (octets)
|
||||
@param uskey A previously scheduled key [optional can be NULL]
|
||||
@param nonce The session nonce [use once]
|
||||
@param noncelen The length of the nonce
|
||||
@param header The header for the session
|
||||
@@ -36,6 +37,7 @@
|
||||
*/
|
||||
int ccm_memory(int cipher,
|
||||
const unsigned char *key, unsigned long keylen,
|
||||
symmetric_key *uskey,
|
||||
const unsigned char *nonce, unsigned long noncelen,
|
||||
const unsigned char *header, unsigned long headerlen,
|
||||
unsigned char *pt, unsigned long ptlen,
|
||||
@@ -48,7 +50,9 @@ int ccm_memory(int cipher,
|
||||
int err;
|
||||
unsigned long len, L, x, y, z, CTRlen;
|
||||
|
||||
LTC_ARGCHK(key != NULL);
|
||||
if (uskey == NULL) {
|
||||
LTC_ARGCHK(key != NULL);
|
||||
}
|
||||
LTC_ARGCHK(nonce != NULL);
|
||||
if (headerlen > 0) {
|
||||
LTC_ARGCHK(header != NULL);
|
||||
@@ -85,15 +89,15 @@ int ccm_memory(int cipher,
|
||||
|
||||
/* is there an accelerator? */
|
||||
if (cipher_descriptor[cipher].accel_ccm_memory != NULL) {
|
||||
cipher_descriptor[cipher].accel_ccm_memory(
|
||||
return cipher_descriptor[cipher].accel_ccm_memory(
|
||||
key, keylen,
|
||||
uskey,
|
||||
nonce, noncelen,
|
||||
header, headerlen,
|
||||
pt, ptlen,
|
||||
ct,
|
||||
tag, taglen,
|
||||
direction);
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
/* let's get the L value */
|
||||
@@ -113,23 +117,32 @@ int ccm_memory(int cipher,
|
||||
L = 15 - noncelen;
|
||||
}
|
||||
|
||||
/* allocate mem for the symmetric key */
|
||||
skey = XMALLOC(sizeof(*skey));
|
||||
if (skey == NULL) {
|
||||
return CRYPT_MEM;
|
||||
/* decrease noncelen to match L */
|
||||
if ((noncelen + L) > 15) {
|
||||
noncelen = 15 - L;
|
||||
}
|
||||
|
||||
/* initialize the cipher */
|
||||
if ((err = cipher_descriptor[cipher].setup(key, keylen, 0, skey)) != CRYPT_OK) {
|
||||
XFREE(skey);
|
||||
return err;
|
||||
/* allocate mem for the symmetric key */
|
||||
if (uskey == NULL) {
|
||||
skey = XMALLOC(sizeof(*skey));
|
||||
if (skey == NULL) {
|
||||
return CRYPT_MEM;
|
||||
}
|
||||
|
||||
/* initialize the cipher */
|
||||
if ((err = cipher_descriptor[cipher].setup(key, keylen, 0, skey)) != CRYPT_OK) {
|
||||
XFREE(skey);
|
||||
return err;
|
||||
}
|
||||
} else {
|
||||
skey = uskey;
|
||||
}
|
||||
|
||||
/* form B_0 == flags | Nonce N | l(m) */
|
||||
x = 0;
|
||||
PAD[x++] = ((headerlen > 0) ? (1<<6) : 0) |
|
||||
PAD[x++] = (unsigned char)(((headerlen > 0) ? (1<<6) : 0) |
|
||||
(((*taglen - 2)>>1)<<3) |
|
||||
(L-1);
|
||||
(L-1));
|
||||
|
||||
/* nonce */
|
||||
for (y = 0; y < (16 - (L + 1)); y++) {
|
||||
@@ -149,12 +162,14 @@ int ccm_memory(int cipher,
|
||||
PAD[x++] = 0;
|
||||
}
|
||||
for (; y < L; y++) {
|
||||
PAD[x++] = (len >> 24) & 255;
|
||||
PAD[x++] = (unsigned char)((len >> 24) & 255);
|
||||
len <<= 8;
|
||||
}
|
||||
|
||||
/* encrypt PAD */
|
||||
cipher_descriptor[cipher].ecb_encrypt(PAD, PAD, skey);
|
||||
if ((err = cipher_descriptor[cipher].ecb_encrypt(PAD, PAD, skey)) != CRYPT_OK) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
/* handle header */
|
||||
if (headerlen > 0) {
|
||||
@@ -177,7 +192,9 @@ int ccm_memory(int cipher,
|
||||
for (y = 0; y < headerlen; y++) {
|
||||
if (x == 16) {
|
||||
/* full block so let's encrypt it */
|
||||
cipher_descriptor[cipher].ecb_encrypt(PAD, PAD, skey);
|
||||
if ((err = cipher_descriptor[cipher].ecb_encrypt(PAD, PAD, skey)) != CRYPT_OK) {
|
||||
goto error;
|
||||
}
|
||||
x = 0;
|
||||
}
|
||||
PAD[x++] ^= header[y];
|
||||
@@ -185,7 +202,9 @@ int ccm_memory(int cipher,
|
||||
|
||||
/* remainder? */
|
||||
if (x != 0) {
|
||||
cipher_descriptor[cipher].ecb_encrypt(PAD, PAD, skey);
|
||||
if ((err = cipher_descriptor[cipher].ecb_encrypt(PAD, PAD, skey)) != CRYPT_OK) {
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -193,7 +212,7 @@ int ccm_memory(int cipher,
|
||||
x = 0;
|
||||
|
||||
/* flags */
|
||||
ctr[x++] = L-1;
|
||||
ctr[x++] = (unsigned char)L-1;
|
||||
|
||||
/* nonce */
|
||||
for (y = 0; y < (16 - (L+1)); ++y) {
|
||||
@@ -219,14 +238,18 @@ int ccm_memory(int cipher,
|
||||
ctr[z] = (ctr[z] + 1) & 255;
|
||||
if (ctr[z]) break;
|
||||
}
|
||||
cipher_descriptor[cipher].ecb_encrypt(ctr, CTRPAD, skey);
|
||||
if ((err = cipher_descriptor[cipher].ecb_encrypt(ctr, CTRPAD, skey)) != CRYPT_OK) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
/* xor the PT against the pad first */
|
||||
for (z = 0; z < 16; z += sizeof(LTC_FAST_TYPE)) {
|
||||
*((LTC_FAST_TYPE*)(&PAD[z])) ^= *((LTC_FAST_TYPE*)(&pt[y+z]));
|
||||
*((LTC_FAST_TYPE*)(&ct[y+z])) = *((LTC_FAST_TYPE*)(&pt[y+z])) ^ *((LTC_FAST_TYPE*)(&CTRPAD[z]));
|
||||
}
|
||||
cipher_descriptor[cipher].ecb_encrypt(PAD, PAD, skey);
|
||||
if ((err = cipher_descriptor[cipher].ecb_encrypt(PAD, PAD, skey)) != CRYPT_OK) {
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (; y < (ptlen & ~15); y += 16) {
|
||||
@@ -235,14 +258,18 @@ int ccm_memory(int cipher,
|
||||
ctr[z] = (ctr[z] + 1) & 255;
|
||||
if (ctr[z]) break;
|
||||
}
|
||||
cipher_descriptor[cipher].ecb_encrypt(ctr, CTRPAD, skey);
|
||||
if ((err = cipher_descriptor[cipher].ecb_encrypt(ctr, CTRPAD, skey)) != CRYPT_OK) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
/* xor the PT against the pad last */
|
||||
for (z = 0; z < 16; z += sizeof(LTC_FAST_TYPE)) {
|
||||
*((LTC_FAST_TYPE*)(&pt[y+z])) = *((LTC_FAST_TYPE*)(&ct[y+z])) ^ *((LTC_FAST_TYPE*)(&CTRPAD[z]));
|
||||
*((LTC_FAST_TYPE*)(&PAD[z])) ^= *((LTC_FAST_TYPE*)(&pt[y+z]));
|
||||
}
|
||||
cipher_descriptor[cipher].ecb_encrypt(PAD, PAD, skey);
|
||||
if ((err = cipher_descriptor[cipher].ecb_encrypt(PAD, PAD, skey)) != CRYPT_OK) {
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -255,7 +282,9 @@ int ccm_memory(int cipher,
|
||||
ctr[z] = (ctr[z] + 1) & 255;
|
||||
if (ctr[z]) break;
|
||||
}
|
||||
cipher_descriptor[cipher].ecb_encrypt(ctr, CTRPAD, skey);
|
||||
if ((err = cipher_descriptor[cipher].ecb_encrypt(ctr, CTRPAD, skey)) != CRYPT_OK) {
|
||||
goto error;
|
||||
}
|
||||
CTRlen = 0;
|
||||
}
|
||||
|
||||
@@ -269,21 +298,32 @@ int ccm_memory(int cipher,
|
||||
}
|
||||
|
||||
if (x == 16) {
|
||||
cipher_descriptor[cipher].ecb_encrypt(PAD, PAD, skey);
|
||||
if ((err = cipher_descriptor[cipher].ecb_encrypt(PAD, PAD, skey)) != CRYPT_OK) {
|
||||
goto error;
|
||||
}
|
||||
x = 0;
|
||||
}
|
||||
PAD[x++] ^= b;
|
||||
}
|
||||
|
||||
if (x != 0) {
|
||||
cipher_descriptor[cipher].ecb_encrypt(PAD, PAD, skey);
|
||||
if ((err = cipher_descriptor[cipher].ecb_encrypt(PAD, PAD, skey)) != CRYPT_OK) {
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* setup CTR for the TAG */
|
||||
ctr[14] = ctr[15] = 0x00;
|
||||
cipher_descriptor[cipher].ecb_encrypt(ctr, CTRPAD, skey);
|
||||
cipher_descriptor[cipher].done(skey);
|
||||
/* 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;
|
||||
}
|
||||
|
||||
if (skey != uskey) {
|
||||
cipher_descriptor[cipher].done(skey);
|
||||
}
|
||||
|
||||
/* store the TAG */
|
||||
for (x = 0; x < 16 && x < *taglen; x++) {
|
||||
@@ -296,14 +336,16 @@ int ccm_memory(int cipher,
|
||||
zeromem(PAD, sizeof(PAD));
|
||||
zeromem(CTRPAD, sizeof(CTRPAD));
|
||||
#endif
|
||||
error:
|
||||
if (skey != uskey) {
|
||||
XFREE(skey);
|
||||
}
|
||||
|
||||
XFREE(skey);
|
||||
|
||||
return CRYPT_OK;
|
||||
return err;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/encauth/ccm/ccm_memory.c,v $ */
|
||||
/* $Revision: 1.9 $ */
|
||||
/* $Date: 2005/05/05 14:35:58 $ */
|
||||
/* $Revision: 1.18 $ */
|
||||
/* $Date: 2006/12/04 21:34:03 $ */
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
@@ -116,6 +116,7 @@ int ccm_test(void)
|
||||
unsigned long taglen, x;
|
||||
unsigned char buf[64], buf2[64], tag2[16], tag[16];
|
||||
int err, idx;
|
||||
symmetric_key skey;
|
||||
|
||||
idx = find_cipher("aes");
|
||||
if (idx == -1) {
|
||||
@@ -127,8 +128,13 @@ int ccm_test(void)
|
||||
|
||||
for (x = 0; x < (sizeof(tests)/sizeof(tests[0])); x++) {
|
||||
taglen = tests[x].taglen;
|
||||
if ((err = cipher_descriptor[idx].setup(tests[x].key, 16, 0, &skey)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
if ((err = ccm_memory(idx,
|
||||
tests[x].key, 16,
|
||||
&skey,
|
||||
tests[x].nonce, tests[x].noncelen,
|
||||
tests[x].header, tests[x].headerlen,
|
||||
(unsigned char*)tests[x].pt, tests[x].ptlen,
|
||||
@@ -137,31 +143,31 @@ int ccm_test(void)
|
||||
return err;
|
||||
}
|
||||
|
||||
if (memcmp(buf, tests[x].ct, tests[x].ptlen)) {
|
||||
if (XMEMCMP(buf, tests[x].ct, tests[x].ptlen)) {
|
||||
return CRYPT_FAIL_TESTVECTOR;
|
||||
}
|
||||
if (memcmp(tag, tests[x].tag, tests[x].taglen)) {
|
||||
if (XMEMCMP(tag, tests[x].tag, tests[x].taglen)) {
|
||||
return CRYPT_FAIL_TESTVECTOR;
|
||||
}
|
||||
|
||||
if ((err = ccm_memory(idx,
|
||||
tests[x].key, 16,
|
||||
NULL,
|
||||
tests[x].nonce, tests[x].noncelen,
|
||||
tests[x].header, tests[x].headerlen,
|
||||
buf2, tests[x].ptlen,
|
||||
buf,
|
||||
tag2, &taglen, 1 )) != CRYPT_OK) {
|
||||
tag2, &taglen, 1 )) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
if (memcmp(buf2, tests[x].pt, tests[x].ptlen)) {
|
||||
if (XMEMCMP(buf2, tests[x].pt, tests[x].ptlen)) {
|
||||
return CRYPT_FAIL_TESTVECTOR;
|
||||
}
|
||||
if (memcmp(tag2, tests[x].tag, tests[x].taglen)) {
|
||||
if (XMEMCMP(tag2, tests[x].tag, tests[x].taglen)) {
|
||||
return CRYPT_FAIL_TESTVECTOR;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
cipher_descriptor[idx].done(&skey);
|
||||
}
|
||||
return CRYPT_OK;
|
||||
#endif
|
||||
@@ -170,5 +176,5 @@ int ccm_test(void)
|
||||
#endif
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/encauth/ccm/ccm_test.c,v $ */
|
||||
/* $Revision: 1.4 $ */
|
||||
/* $Date: 2005/05/05 14:35:58 $ */
|
||||
/* $Revision: 1.8 $ */
|
||||
/* $Date: 2006/11/21 00:18:23 $ */
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
*/
|
||||
/**
|
||||
@file eax_addheader.c
|
||||
@@ -34,5 +34,5 @@ int eax_addheader(eax_state *eax, const unsigned char *header,
|
||||
#endif
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/encauth/eax/eax_addheader.c,v $ */
|
||||
/* $Revision: 1.3 $ */
|
||||
/* $Date: 2005/05/05 14:35:58 $ */
|
||||
/* $Revision: 1.4 $ */
|
||||
/* $Date: 2006/03/31 14:15:35 $ */
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -46,5 +46,5 @@ int eax_decrypt(eax_state *eax, const unsigned char *ct, unsigned char *pt,
|
||||
#endif
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/encauth/eax/eax_decrypt.c,v $ */
|
||||
/* $Revision: 1.3 $ */
|
||||
/* $Date: 2005/05/05 14:35:58 $ */
|
||||
/* $Revision: 1.4 $ */
|
||||
/* $Date: 2006/03/31 14:15:35 $ */
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -84,7 +84,7 @@ int eax_decrypt_verify_memory(int cipher,
|
||||
}
|
||||
|
||||
/* compare tags */
|
||||
if (buflen >= taglen && memcmp(buf, tag, taglen) == 0) {
|
||||
if (buflen >= taglen && XMEMCMP(buf, tag, taglen) == 0) {
|
||||
*stat = 1;
|
||||
}
|
||||
|
||||
@@ -104,5 +104,5 @@ LBL_ERR:
|
||||
#endif
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/encauth/eax/eax_decrypt_verify_memory.c,v $ */
|
||||
/* $Revision: 1.3 $ */
|
||||
/* $Date: 2005/05/05 14:35:58 $ */
|
||||
/* $Revision: 1.5 $ */
|
||||
/* $Date: 2006/11/01 09:28:17 $ */
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -90,5 +90,5 @@ LBL_ERR:
|
||||
#endif
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/encauth/eax/eax_done.c,v $ */
|
||||
/* $Revision: 1.4 $ */
|
||||
/* $Date: 2005/05/05 14:35:58 $ */
|
||||
/* $Revision: 1.5 $ */
|
||||
/* $Date: 2006/03/31 14:15:35 $ */
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -47,5 +47,5 @@ int eax_encrypt(eax_state *eax, const unsigned char *pt, unsigned char *ct,
|
||||
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/encauth/eax/eax_encrypt.c,v $ */
|
||||
/* $Revision: 1.3 $ */
|
||||
/* $Date: 2005/05/05 14:35:58 $ */
|
||||
/* $Revision: 1.4 $ */
|
||||
/* $Date: 2006/03/31 14:15:35 $ */
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -78,5 +78,5 @@ LBL_ERR:
|
||||
#endif
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/encauth/eax/eax_encrypt_authenticate_memory.c,v $ */
|
||||
/* $Revision: 1.3 $ */
|
||||
/* $Date: 2005/05/05 14:35:58 $ */
|
||||
/* $Revision: 1.4 $ */
|
||||
/* $Date: 2006/03/31 14:15:35 $ */
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -140,5 +140,5 @@ LBL_ERR:
|
||||
#endif
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/encauth/eax/eax_init.c,v $ */
|
||||
/* $Revision: 1.4 $ */
|
||||
/* $Date: 2005/05/05 14:35:58 $ */
|
||||
/* $Revision: 1.5 $ */
|
||||
/* $Date: 2006/03/31 14:15:35 $ */
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -231,7 +231,7 @@ int eax_test(void)
|
||||
tests[x].plaintext, tests[x].msglen, outct, outtag, &len)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
if (memcmp(outct, tests[x].ciphertext, tests[x].msglen) || memcmp(outtag, tests[x].tag, len)) {
|
||||
if (XMEMCMP(outct, tests[x].ciphertext, tests[x].msglen) || XMEMCMP(outtag, tests[x].tag, len)) {
|
||||
#if 0
|
||||
unsigned long y;
|
||||
printf("\n\nFailure: \nCT:\n");
|
||||
@@ -256,7 +256,7 @@ int eax_test(void)
|
||||
outct, tests[x].msglen, outct, outtag, len, &res)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
if ((res != 1) || memcmp(outct, tests[x].plaintext, tests[x].msglen)) {
|
||||
if ((res != 1) || XMEMCMP(outct, tests[x].plaintext, tests[x].msglen)) {
|
||||
#if 0
|
||||
unsigned long y;
|
||||
printf("\n\nFailure (res == %d): \nPT:\n", res);
|
||||
@@ -278,5 +278,5 @@ int eax_test(void)
|
||||
#endif /* EAX_MODE */
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/encauth/eax/eax_test.c,v $ */
|
||||
/* $Revision: 1.3 $ */
|
||||
/* $Date: 2005/05/05 14:35:58 $ */
|
||||
/* $Revision: 1.5 $ */
|
||||
/* $Date: 2006/11/01 09:28:17 $ */
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -57,7 +57,7 @@ int gcm_add_aad(gcm_state *gcm,
|
||||
gcm->totlen += gcm->buflen * CONST64(8);
|
||||
gcm_mult_h(gcm, gcm->X);
|
||||
}
|
||||
|
||||
|
||||
/* mix in the length */
|
||||
zeromem(gcm->buf, 8);
|
||||
STORE64H(gcm->totlen, gcm->buf+8);
|
||||
@@ -120,5 +120,5 @@ int gcm_add_aad(gcm_state *gcm,
|
||||
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/encauth/gcm/gcm_add_aad.c,v $ */
|
||||
/* $Revision: 1.14 $ */
|
||||
/* $Date: 2005/05/05 14:35:58 $ */
|
||||
/* $Revision: 1.16 $ */
|
||||
/* $Date: 2006/09/23 19:24:21 $ */
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -90,5 +90,5 @@ int gcm_add_iv(gcm_state *gcm,
|
||||
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/encauth/gcm/gcm_add_iv.c,v $ */
|
||||
/* $Revision: 1.6 $ */
|
||||
/* $Date: 2005/05/05 14:35:58 $ */
|
||||
/* $Revision: 1.7 $ */
|
||||
/* $Date: 2006/03/31 14:15:35 $ */
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -62,7 +62,9 @@ int gcm_done(gcm_state *gcm,
|
||||
gcm_mult_h(gcm, gcm->X);
|
||||
|
||||
/* encrypt original counter */
|
||||
cipher_descriptor[gcm->cipher].ecb_encrypt(gcm->Y_0, gcm->buf, &gcm->K);
|
||||
if ((err = cipher_descriptor[gcm->cipher].ecb_encrypt(gcm->Y_0, gcm->buf, &gcm->K)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
for (x = 0; x < 16 && x < *taglen; x++) {
|
||||
tag[x] = gcm->buf[x] ^ gcm->X[x];
|
||||
}
|
||||
@@ -77,5 +79,5 @@ int gcm_done(gcm_state *gcm,
|
||||
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/encauth/gcm/gcm_done.c,v $ */
|
||||
/* $Revision: 1.7 $ */
|
||||
/* $Date: 2005/05/05 14:35:58 $ */
|
||||
/* $Revision: 1.9 $ */
|
||||
/* $Date: 2006/03/31 14:15:35 $ */
|
||||
|
||||
@@ -6,17 +6,59 @@
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
*/
|
||||
|
||||
/**
|
||||
@file gcm_gf_mult.c
|
||||
GCM implementation, initialize state, by Tom St Denis
|
||||
GCM implementation, do the GF mult, by Tom St Denis
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
#ifdef GCM_MODE
|
||||
#if defined(GCM_TABLES) || defined(LRW_TABLES) || ((defined(GCM_MODE) || defined(GCM_MODE)) && defined(LTC_FAST))
|
||||
|
||||
/* this is x*2^128 mod p(x) ... the results are 16 bytes each stored in a packed format. Since only the
|
||||
* lower 16 bits are not zero'ed I removed the upper 14 bytes */
|
||||
const unsigned char gcm_shift_table[256*2] = {
|
||||
0x00, 0x00, 0x01, 0xc2, 0x03, 0x84, 0x02, 0x46, 0x07, 0x08, 0x06, 0xca, 0x04, 0x8c, 0x05, 0x4e,
|
||||
0x0e, 0x10, 0x0f, 0xd2, 0x0d, 0x94, 0x0c, 0x56, 0x09, 0x18, 0x08, 0xda, 0x0a, 0x9c, 0x0b, 0x5e,
|
||||
0x1c, 0x20, 0x1d, 0xe2, 0x1f, 0xa4, 0x1e, 0x66, 0x1b, 0x28, 0x1a, 0xea, 0x18, 0xac, 0x19, 0x6e,
|
||||
0x12, 0x30, 0x13, 0xf2, 0x11, 0xb4, 0x10, 0x76, 0x15, 0x38, 0x14, 0xfa, 0x16, 0xbc, 0x17, 0x7e,
|
||||
0x38, 0x40, 0x39, 0x82, 0x3b, 0xc4, 0x3a, 0x06, 0x3f, 0x48, 0x3e, 0x8a, 0x3c, 0xcc, 0x3d, 0x0e,
|
||||
0x36, 0x50, 0x37, 0x92, 0x35, 0xd4, 0x34, 0x16, 0x31, 0x58, 0x30, 0x9a, 0x32, 0xdc, 0x33, 0x1e,
|
||||
0x24, 0x60, 0x25, 0xa2, 0x27, 0xe4, 0x26, 0x26, 0x23, 0x68, 0x22, 0xaa, 0x20, 0xec, 0x21, 0x2e,
|
||||
0x2a, 0x70, 0x2b, 0xb2, 0x29, 0xf4, 0x28, 0x36, 0x2d, 0x78, 0x2c, 0xba, 0x2e, 0xfc, 0x2f, 0x3e,
|
||||
0x70, 0x80, 0x71, 0x42, 0x73, 0x04, 0x72, 0xc6, 0x77, 0x88, 0x76, 0x4a, 0x74, 0x0c, 0x75, 0xce,
|
||||
0x7e, 0x90, 0x7f, 0x52, 0x7d, 0x14, 0x7c, 0xd6, 0x79, 0x98, 0x78, 0x5a, 0x7a, 0x1c, 0x7b, 0xde,
|
||||
0x6c, 0xa0, 0x6d, 0x62, 0x6f, 0x24, 0x6e, 0xe6, 0x6b, 0xa8, 0x6a, 0x6a, 0x68, 0x2c, 0x69, 0xee,
|
||||
0x62, 0xb0, 0x63, 0x72, 0x61, 0x34, 0x60, 0xf6, 0x65, 0xb8, 0x64, 0x7a, 0x66, 0x3c, 0x67, 0xfe,
|
||||
0x48, 0xc0, 0x49, 0x02, 0x4b, 0x44, 0x4a, 0x86, 0x4f, 0xc8, 0x4e, 0x0a, 0x4c, 0x4c, 0x4d, 0x8e,
|
||||
0x46, 0xd0, 0x47, 0x12, 0x45, 0x54, 0x44, 0x96, 0x41, 0xd8, 0x40, 0x1a, 0x42, 0x5c, 0x43, 0x9e,
|
||||
0x54, 0xe0, 0x55, 0x22, 0x57, 0x64, 0x56, 0xa6, 0x53, 0xe8, 0x52, 0x2a, 0x50, 0x6c, 0x51, 0xae,
|
||||
0x5a, 0xf0, 0x5b, 0x32, 0x59, 0x74, 0x58, 0xb6, 0x5d, 0xf8, 0x5c, 0x3a, 0x5e, 0x7c, 0x5f, 0xbe,
|
||||
0xe1, 0x00, 0xe0, 0xc2, 0xe2, 0x84, 0xe3, 0x46, 0xe6, 0x08, 0xe7, 0xca, 0xe5, 0x8c, 0xe4, 0x4e,
|
||||
0xef, 0x10, 0xee, 0xd2, 0xec, 0x94, 0xed, 0x56, 0xe8, 0x18, 0xe9, 0xda, 0xeb, 0x9c, 0xea, 0x5e,
|
||||
0xfd, 0x20, 0xfc, 0xe2, 0xfe, 0xa4, 0xff, 0x66, 0xfa, 0x28, 0xfb, 0xea, 0xf9, 0xac, 0xf8, 0x6e,
|
||||
0xf3, 0x30, 0xf2, 0xf2, 0xf0, 0xb4, 0xf1, 0x76, 0xf4, 0x38, 0xf5, 0xfa, 0xf7, 0xbc, 0xf6, 0x7e,
|
||||
0xd9, 0x40, 0xd8, 0x82, 0xda, 0xc4, 0xdb, 0x06, 0xde, 0x48, 0xdf, 0x8a, 0xdd, 0xcc, 0xdc, 0x0e,
|
||||
0xd7, 0x50, 0xd6, 0x92, 0xd4, 0xd4, 0xd5, 0x16, 0xd0, 0x58, 0xd1, 0x9a, 0xd3, 0xdc, 0xd2, 0x1e,
|
||||
0xc5, 0x60, 0xc4, 0xa2, 0xc6, 0xe4, 0xc7, 0x26, 0xc2, 0x68, 0xc3, 0xaa, 0xc1, 0xec, 0xc0, 0x2e,
|
||||
0xcb, 0x70, 0xca, 0xb2, 0xc8, 0xf4, 0xc9, 0x36, 0xcc, 0x78, 0xcd, 0xba, 0xcf, 0xfc, 0xce, 0x3e,
|
||||
0x91, 0x80, 0x90, 0x42, 0x92, 0x04, 0x93, 0xc6, 0x96, 0x88, 0x97, 0x4a, 0x95, 0x0c, 0x94, 0xce,
|
||||
0x9f, 0x90, 0x9e, 0x52, 0x9c, 0x14, 0x9d, 0xd6, 0x98, 0x98, 0x99, 0x5a, 0x9b, 0x1c, 0x9a, 0xde,
|
||||
0x8d, 0xa0, 0x8c, 0x62, 0x8e, 0x24, 0x8f, 0xe6, 0x8a, 0xa8, 0x8b, 0x6a, 0x89, 0x2c, 0x88, 0xee,
|
||||
0x83, 0xb0, 0x82, 0x72, 0x80, 0x34, 0x81, 0xf6, 0x84, 0xb8, 0x85, 0x7a, 0x87, 0x3c, 0x86, 0xfe,
|
||||
0xa9, 0xc0, 0xa8, 0x02, 0xaa, 0x44, 0xab, 0x86, 0xae, 0xc8, 0xaf, 0x0a, 0xad, 0x4c, 0xac, 0x8e,
|
||||
0xa7, 0xd0, 0xa6, 0x12, 0xa4, 0x54, 0xa5, 0x96, 0xa0, 0xd8, 0xa1, 0x1a, 0xa3, 0x5c, 0xa2, 0x9e,
|
||||
0xb5, 0xe0, 0xb4, 0x22, 0xb6, 0x64, 0xb7, 0xa6, 0xb2, 0xe8, 0xb3, 0x2a, 0xb1, 0x6c, 0xb0, 0xae,
|
||||
0xbb, 0xf0, 0xba, 0x32, 0xb8, 0x74, 0xb9, 0xb6, 0xbc, 0xf8, 0xbd, 0x3a, 0xbf, 0x7c, 0xbe, 0xbe };
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#if defined(GCM_MODE) || defined(LRW_MODE)
|
||||
|
||||
#ifndef LTC_FAST
|
||||
/* right shift */
|
||||
static void gcm_rightshift(unsigned char *a)
|
||||
{
|
||||
@@ -33,7 +75,7 @@ static const unsigned char poly[] = { 0x00, 0xE1 };
|
||||
|
||||
|
||||
/**
|
||||
GCM GF multiplier (internal use only)
|
||||
GCM GF multiplier (internal use only) bitserial
|
||||
@param a First value
|
||||
@param b Second value
|
||||
@param c Destination for a * b
|
||||
@@ -58,37 +100,122 @@ void gcm_gf_mult(const unsigned char *a, const unsigned char *b, unsigned char *
|
||||
XMEMCPY(c, Z, 16);
|
||||
}
|
||||
|
||||
/**
|
||||
GCM multiply by H
|
||||
@param gcm The GCM state which holds the H value
|
||||
@param I The value to multiply H by
|
||||
*/
|
||||
void gcm_mult_h(gcm_state *gcm, unsigned char *I)
|
||||
{
|
||||
unsigned char T[16];
|
||||
#ifdef GCM_TABLES
|
||||
int x, y;
|
||||
XMEMCPY(T, &gcm->PC[0][I[0]][0], 16);
|
||||
for (x = 1; x < 16; x++) {
|
||||
#ifdef LTC_FAST
|
||||
for (y = 0; y < 16; y += sizeof(LTC_FAST_TYPE)) {
|
||||
*((LTC_FAST_TYPE *)(T + y)) ^= *((LTC_FAST_TYPE *)(&gcm->PC[x][I[x]][y]));
|
||||
}
|
||||
#else
|
||||
for (y = 0; y < 16; y++) {
|
||||
T[y] ^= gcm->PC[x][I[x]][y];
|
||||
}
|
||||
#endif
|
||||
|
||||
/* map normal numbers to "ieee" way ... e.g. bit reversed */
|
||||
#define M(x) ( ((x&8)>>3) | ((x&4)>>1) | ((x&2)<<1) | ((x&1)<<3) )
|
||||
|
||||
#define BPD (sizeof(LTC_FAST_TYPE) * 8)
|
||||
#define WPV (1 + (16 / sizeof(LTC_FAST_TYPE)))
|
||||
|
||||
/**
|
||||
GCM GF multiplier (internal use only) word oriented
|
||||
@param a First value
|
||||
@param b Second value
|
||||
@param c Destination for a * b
|
||||
*/
|
||||
void gcm_gf_mult(const unsigned char *a, const unsigned char *b, unsigned char *c)
|
||||
{
|
||||
int i, j, k, u;
|
||||
LTC_FAST_TYPE B[16][WPV], tmp[32 / sizeof(LTC_FAST_TYPE)], pB[16 / sizeof(LTC_FAST_TYPE)], zz, z;
|
||||
unsigned char pTmp[32];
|
||||
|
||||
/* create simple tables */
|
||||
zeromem(B[0], sizeof(B[0]));
|
||||
zeromem(B[M(1)], sizeof(B[M(1)]));
|
||||
|
||||
#ifdef ENDIAN_32BITWORD
|
||||
for (i = 0; i < 4; i++) {
|
||||
LOAD32H(B[M(1)][i], a + (i<<2));
|
||||
LOAD32L(pB[i], b + (i<<2));
|
||||
}
|
||||
#else
|
||||
for (i = 0; i < 2; i++) {
|
||||
LOAD64H(B[M(1)][i], a + (i<<3));
|
||||
LOAD64L(pB[i], b + (i<<3));
|
||||
}
|
||||
#else
|
||||
gcm_gf_mult(gcm->H, I, T);
|
||||
#endif
|
||||
XMEMCPY(I, T, 16);
|
||||
|
||||
/* now create 2, 4 and 8 */
|
||||
B[M(2)][0] = B[M(1)][0] >> 1;
|
||||
B[M(4)][0] = B[M(1)][0] >> 2;
|
||||
B[M(8)][0] = B[M(1)][0] >> 3;
|
||||
for (i = 1; i < (int)WPV; i++) {
|
||||
B[M(2)][i] = (B[M(1)][i-1] << (BPD-1)) | (B[M(1)][i] >> 1);
|
||||
B[M(4)][i] = (B[M(1)][i-1] << (BPD-2)) | (B[M(1)][i] >> 2);
|
||||
B[M(8)][i] = (B[M(1)][i-1] << (BPD-3)) | (B[M(1)][i] >> 3);
|
||||
}
|
||||
|
||||
/* now all values with two bits which are 3, 5, 6, 9, 10, 12 */
|
||||
for (i = 0; i < (int)WPV; i++) {
|
||||
B[M(3)][i] = B[M(1)][i] ^ B[M(2)][i];
|
||||
B[M(5)][i] = B[M(1)][i] ^ B[M(4)][i];
|
||||
B[M(6)][i] = B[M(2)][i] ^ B[M(4)][i];
|
||||
B[M(9)][i] = B[M(1)][i] ^ B[M(8)][i];
|
||||
B[M(10)][i] = B[M(2)][i] ^ B[M(8)][i];
|
||||
B[M(12)][i] = B[M(8)][i] ^ B[M(4)][i];
|
||||
|
||||
/* now all 3 bit values and the only 4 bit value: 7, 11, 13, 14, 15 */
|
||||
B[M(7)][i] = B[M(3)][i] ^ B[M(4)][i];
|
||||
B[M(11)][i] = B[M(3)][i] ^ B[M(8)][i];
|
||||
B[M(13)][i] = B[M(1)][i] ^ B[M(12)][i];
|
||||
B[M(14)][i] = B[M(6)][i] ^ B[M(8)][i];
|
||||
B[M(15)][i] = B[M(7)][i] ^ B[M(8)][i];
|
||||
}
|
||||
|
||||
zeromem(tmp, sizeof(tmp));
|
||||
|
||||
/* compute product four bits of each word at a time */
|
||||
/* for each nibble */
|
||||
for (i = (BPD/4)-1; i >= 0; i--) {
|
||||
/* for each word */
|
||||
for (j = 0; j < (int)(WPV-1); j++) {
|
||||
/* grab the 4 bits recall the nibbles are backwards so it's a shift by (i^1)*4 */
|
||||
u = (pB[j] >> ((i^1)<<2)) & 15;
|
||||
|
||||
/* add offset by the word count the table looked up value to the result */
|
||||
for (k = 0; k < (int)WPV; k++) {
|
||||
tmp[k+j] ^= B[u][k];
|
||||
}
|
||||
}
|
||||
/* shift result up by 4 bits */
|
||||
if (i != 0) {
|
||||
for (z = j = 0; j < (int)(32 / sizeof(LTC_FAST_TYPE)); j++) {
|
||||
zz = tmp[j] << (BPD-4);
|
||||
tmp[j] = (tmp[j] >> 4) | z;
|
||||
z = zz;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* store product */
|
||||
#ifdef ENDIAN_32BITWORD
|
||||
for (i = 0; i < 8; i++) {
|
||||
STORE32H(tmp[i], pTmp + (i<<2));
|
||||
}
|
||||
#else
|
||||
for (i = 0; i < 4; i++) {
|
||||
STORE64H(tmp[i], pTmp + (i<<3));
|
||||
}
|
||||
#endif
|
||||
|
||||
/* reduce by taking most significant byte and adding the appropriate two byte sequence 16 bytes down */
|
||||
for (i = 31; i >= 16; i--) {
|
||||
pTmp[i-16] ^= gcm_shift_table[((unsigned)pTmp[i]<<1)];
|
||||
pTmp[i-15] ^= gcm_shift_table[((unsigned)pTmp[i]<<1)+1];
|
||||
}
|
||||
|
||||
for (i = 0; i < 16; i++) {
|
||||
c[i] = pTmp[i];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/encauth/gcm/gcm_gf_mult.c,v $ */
|
||||
/* $Revision: 1.16 $ */
|
||||
/* $Date: 2005/05/21 14:33:42 $ */
|
||||
/* $Revision: 1.23 $ */
|
||||
/* $Date: 2006/03/31 14:15:35 $ */
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -17,46 +17,6 @@
|
||||
|
||||
#ifdef GCM_MODE
|
||||
|
||||
#ifdef GCM_TABLES
|
||||
|
||||
/* this is x*2^128 mod p(x) ... the results are 16 bytes each stored in a packed format. Since only the
|
||||
* lower 16 bits are not zero'ed I removed the upper 14 bytes */
|
||||
static const unsigned char gcm_shift_table[256*2] = {
|
||||
0x00, 0x00, 0x01, 0xc2, 0x03, 0x84, 0x02, 0x46, 0x07, 0x08, 0x06, 0xca, 0x04, 0x8c, 0x05, 0x4e,
|
||||
0x0e, 0x10, 0x0f, 0xd2, 0x0d, 0x94, 0x0c, 0x56, 0x09, 0x18, 0x08, 0xda, 0x0a, 0x9c, 0x0b, 0x5e,
|
||||
0x1c, 0x20, 0x1d, 0xe2, 0x1f, 0xa4, 0x1e, 0x66, 0x1b, 0x28, 0x1a, 0xea, 0x18, 0xac, 0x19, 0x6e,
|
||||
0x12, 0x30, 0x13, 0xf2, 0x11, 0xb4, 0x10, 0x76, 0x15, 0x38, 0x14, 0xfa, 0x16, 0xbc, 0x17, 0x7e,
|
||||
0x38, 0x40, 0x39, 0x82, 0x3b, 0xc4, 0x3a, 0x06, 0x3f, 0x48, 0x3e, 0x8a, 0x3c, 0xcc, 0x3d, 0x0e,
|
||||
0x36, 0x50, 0x37, 0x92, 0x35, 0xd4, 0x34, 0x16, 0x31, 0x58, 0x30, 0x9a, 0x32, 0xdc, 0x33, 0x1e,
|
||||
0x24, 0x60, 0x25, 0xa2, 0x27, 0xe4, 0x26, 0x26, 0x23, 0x68, 0x22, 0xaa, 0x20, 0xec, 0x21, 0x2e,
|
||||
0x2a, 0x70, 0x2b, 0xb2, 0x29, 0xf4, 0x28, 0x36, 0x2d, 0x78, 0x2c, 0xba, 0x2e, 0xfc, 0x2f, 0x3e,
|
||||
0x70, 0x80, 0x71, 0x42, 0x73, 0x04, 0x72, 0xc6, 0x77, 0x88, 0x76, 0x4a, 0x74, 0x0c, 0x75, 0xce,
|
||||
0x7e, 0x90, 0x7f, 0x52, 0x7d, 0x14, 0x7c, 0xd6, 0x79, 0x98, 0x78, 0x5a, 0x7a, 0x1c, 0x7b, 0xde,
|
||||
0x6c, 0xa0, 0x6d, 0x62, 0x6f, 0x24, 0x6e, 0xe6, 0x6b, 0xa8, 0x6a, 0x6a, 0x68, 0x2c, 0x69, 0xee,
|
||||
0x62, 0xb0, 0x63, 0x72, 0x61, 0x34, 0x60, 0xf6, 0x65, 0xb8, 0x64, 0x7a, 0x66, 0x3c, 0x67, 0xfe,
|
||||
0x48, 0xc0, 0x49, 0x02, 0x4b, 0x44, 0x4a, 0x86, 0x4f, 0xc8, 0x4e, 0x0a, 0x4c, 0x4c, 0x4d, 0x8e,
|
||||
0x46, 0xd0, 0x47, 0x12, 0x45, 0x54, 0x44, 0x96, 0x41, 0xd8, 0x40, 0x1a, 0x42, 0x5c, 0x43, 0x9e,
|
||||
0x54, 0xe0, 0x55, 0x22, 0x57, 0x64, 0x56, 0xa6, 0x53, 0xe8, 0x52, 0x2a, 0x50, 0x6c, 0x51, 0xae,
|
||||
0x5a, 0xf0, 0x5b, 0x32, 0x59, 0x74, 0x58, 0xb6, 0x5d, 0xf8, 0x5c, 0x3a, 0x5e, 0x7c, 0x5f, 0xbe,
|
||||
0xe1, 0x00, 0xe0, 0xc2, 0xe2, 0x84, 0xe3, 0x46, 0xe6, 0x08, 0xe7, 0xca, 0xe5, 0x8c, 0xe4, 0x4e,
|
||||
0xef, 0x10, 0xee, 0xd2, 0xec, 0x94, 0xed, 0x56, 0xe8, 0x18, 0xe9, 0xda, 0xeb, 0x9c, 0xea, 0x5e,
|
||||
0xfd, 0x20, 0xfc, 0xe2, 0xfe, 0xa4, 0xff, 0x66, 0xfa, 0x28, 0xfb, 0xea, 0xf9, 0xac, 0xf8, 0x6e,
|
||||
0xf3, 0x30, 0xf2, 0xf2, 0xf0, 0xb4, 0xf1, 0x76, 0xf4, 0x38, 0xf5, 0xfa, 0xf7, 0xbc, 0xf6, 0x7e,
|
||||
0xd9, 0x40, 0xd8, 0x82, 0xda, 0xc4, 0xdb, 0x06, 0xde, 0x48, 0xdf, 0x8a, 0xdd, 0xcc, 0xdc, 0x0e,
|
||||
0xd7, 0x50, 0xd6, 0x92, 0xd4, 0xd4, 0xd5, 0x16, 0xd0, 0x58, 0xd1, 0x9a, 0xd3, 0xdc, 0xd2, 0x1e,
|
||||
0xc5, 0x60, 0xc4, 0xa2, 0xc6, 0xe4, 0xc7, 0x26, 0xc2, 0x68, 0xc3, 0xaa, 0xc1, 0xec, 0xc0, 0x2e,
|
||||
0xcb, 0x70, 0xca, 0xb2, 0xc8, 0xf4, 0xc9, 0x36, 0xcc, 0x78, 0xcd, 0xba, 0xcf, 0xfc, 0xce, 0x3e,
|
||||
0x91, 0x80, 0x90, 0x42, 0x92, 0x04, 0x93, 0xc6, 0x96, 0x88, 0x97, 0x4a, 0x95, 0x0c, 0x94, 0xce,
|
||||
0x9f, 0x90, 0x9e, 0x52, 0x9c, 0x14, 0x9d, 0xd6, 0x98, 0x98, 0x99, 0x5a, 0x9b, 0x1c, 0x9a, 0xde,
|
||||
0x8d, 0xa0, 0x8c, 0x62, 0x8e, 0x24, 0x8f, 0xe6, 0x8a, 0xa8, 0x8b, 0x6a, 0x89, 0x2c, 0x88, 0xee,
|
||||
0x83, 0xb0, 0x82, 0x72, 0x80, 0x34, 0x81, 0xf6, 0x84, 0xb8, 0x85, 0x7a, 0x87, 0x3c, 0x86, 0xfe,
|
||||
0xa9, 0xc0, 0xa8, 0x02, 0xaa, 0x44, 0xab, 0x86, 0xae, 0xc8, 0xaf, 0x0a, 0xad, 0x4c, 0xac, 0x8e,
|
||||
0xa7, 0xd0, 0xa6, 0x12, 0xa4, 0x54, 0xa5, 0x96, 0xa0, 0xd8, 0xa1, 0x1a, 0xa3, 0x5c, 0xa2, 0x9e,
|
||||
0xb5, 0xe0, 0xb4, 0x22, 0xb6, 0x64, 0xb7, 0xa6, 0xb2, 0xe8, 0xb3, 0x2a, 0xb1, 0x6c, 0xb0, 0xae,
|
||||
0xbb, 0xf0, 0xba, 0x32, 0xb8, 0x74, 0xb9, 0xb6, 0xbc, 0xf8, 0xbd, 0x3a, 0xbf, 0x7c, 0xbe, 0xbe };
|
||||
|
||||
#endif
|
||||
|
||||
/**
|
||||
Initialize a GCM state
|
||||
@param gcm The GCM state to initialize
|
||||
@@ -98,7 +58,9 @@ int gcm_init(gcm_state *gcm, int cipher,
|
||||
|
||||
/* H = E(0) */
|
||||
zeromem(B, 16);
|
||||
cipher_descriptor[cipher].ecb_encrypt(B, gcm->H, &gcm->K);
|
||||
if ((err = cipher_descriptor[cipher].ecb_encrypt(B, gcm->H, &gcm->K)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
/* setup state */
|
||||
zeromem(gcm->buf, sizeof(gcm->buf));
|
||||
@@ -141,5 +103,5 @@ int gcm_init(gcm_state *gcm, int cipher,
|
||||
#endif
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/encauth/gcm/gcm_init.c,v $ */
|
||||
/* $Revision: 1.15 $ */
|
||||
/* $Date: 2005/05/21 15:05:19 $ */
|
||||
/* $Revision: 1.18 $ */
|
||||
/* $Date: 2006/03/31 14:15:35 $ */
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -43,6 +43,7 @@ int gcm_memory( int cipher,
|
||||
unsigned char *tag, unsigned long *taglen,
|
||||
int direction)
|
||||
{
|
||||
void *orig;
|
||||
gcm_state *gcm;
|
||||
int err;
|
||||
|
||||
@@ -51,7 +52,8 @@ int gcm_memory( int cipher,
|
||||
}
|
||||
|
||||
if (cipher_descriptor[cipher].accel_gcm_memory != NULL) {
|
||||
cipher_descriptor[cipher].accel_gcm_memory
|
||||
return
|
||||
cipher_descriptor[cipher].accel_gcm_memory
|
||||
(key, keylen,
|
||||
IV, IVlen,
|
||||
adata, adatalen,
|
||||
@@ -59,15 +61,29 @@ int gcm_memory( int cipher,
|
||||
ct,
|
||||
tag, taglen,
|
||||
direction);
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
|
||||
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,12 +98,12 @@ int gcm_memory( int cipher,
|
||||
}
|
||||
err = gcm_done(gcm, tag, taglen);
|
||||
LTC_ERR:
|
||||
XFREE(gcm);
|
||||
XFREE(orig);
|
||||
return err;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/encauth/gcm/gcm_memory.c,v $ */
|
||||
/* $Revision: 1.19 $ */
|
||||
/* $Date: 2005/05/05 14:35:58 $ */
|
||||
/* $Revision: 1.23 $ */
|
||||
/* $Date: 2006/09/07 10:00:57 $ */
|
||||
|
||||
58
libtomcrypt/src/encauth/gcm/gcm_mult_h.c
Normal file
58
libtomcrypt/src/encauth/gcm/gcm_mult_h.c
Normal file
@@ -0,0 +1,58 @@
|
||||
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
|
||||
*
|
||||
* LibTomCrypt is a library that provides various cryptographic
|
||||
* algorithms in a highly modular and flexible manner.
|
||||
*
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
*/
|
||||
|
||||
/**
|
||||
@file gcm_mult_h.c
|
||||
GCM implementation, do the GF mult, by Tom St Denis
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
#if defined(GCM_MODE)
|
||||
/**
|
||||
GCM multiply by H
|
||||
@param gcm The GCM state which holds the H value
|
||||
@param I The value to multiply H by
|
||||
*/
|
||||
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
|
||||
for (y = 0; y < 16; y += sizeof(LTC_FAST_TYPE)) {
|
||||
*((LTC_FAST_TYPE *)(T + y)) ^= *((LTC_FAST_TYPE *)(&gcm->PC[x][I[x]][y]));
|
||||
}
|
||||
#else
|
||||
for (y = 0; y < 16; y++) {
|
||||
T[y] ^= gcm->PC[x][I[x]][y];
|
||||
}
|
||||
#endif /* LTC_FAST */
|
||||
}
|
||||
#endif /* GCM_TABLES_SSE2 */
|
||||
#else
|
||||
gcm_gf_mult(gcm->H, I, T);
|
||||
#endif
|
||||
XMEMCPY(I, T, 16);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/encauth/gcm/gcm_mult_h.c,v $ */
|
||||
/* $Revision: 1.4 $ */
|
||||
/* $Date: 2006/08/23 20:40:23 $ */
|
||||
@@ -6,7 +6,7 @@
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -31,9 +31,9 @@ int gcm_process(gcm_state *gcm,
|
||||
unsigned char *ct,
|
||||
int direction)
|
||||
{
|
||||
unsigned long x, y;
|
||||
unsigned long x;
|
||||
int y, err;
|
||||
unsigned char b;
|
||||
int err;
|
||||
|
||||
LTC_ARGCHK(gcm != NULL);
|
||||
if (ptlen > 0) {
|
||||
@@ -59,10 +59,12 @@ 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 */
|
||||
cipher_descriptor[gcm->cipher].ecb_encrypt(gcm->Y, gcm->buf, &gcm->K);
|
||||
if ((err = cipher_descriptor[gcm->cipher].ecb_encrypt(gcm->Y, gcm->buf, &gcm->K)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
gcm->buflen = 0;
|
||||
gcm->mode = GCM_MODE_TEXT;
|
||||
@@ -87,9 +89,11 @@ 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;
|
||||
}
|
||||
cipher_descriptor[gcm->cipher].ecb_encrypt(gcm->Y, gcm->buf, &gcm->K);
|
||||
}
|
||||
} else {
|
||||
for (x = 0; x < (ptlen & ~15); x += 16) {
|
||||
@@ -103,9 +107,11 @@ 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;
|
||||
}
|
||||
cipher_descriptor[gcm->cipher].ecb_encrypt(gcm->Y, gcm->buf, &gcm->K);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -119,9 +125,11 @@ 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;
|
||||
}
|
||||
cipher_descriptor[gcm->cipher].ecb_encrypt(gcm->Y, gcm->buf, &gcm->K);
|
||||
gcm->buflen = 0;
|
||||
}
|
||||
|
||||
@@ -137,11 +145,8 @@ int gcm_process(gcm_state *gcm,
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/encauth/gcm/gcm_process.c,v $ */
|
||||
/* $Revision: 1.8 $ */
|
||||
/* $Date: 2005/05/05 14:35:58 $ */
|
||||
/* $Revision: 1.14 $ */
|
||||
/* $Date: 2006/11/19 19:33:36 $ */
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -40,5 +40,5 @@ int gcm_reset(gcm_state *gcm)
|
||||
#endif
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/encauth/gcm/gcm_reset.c,v $ */
|
||||
/* $Revision: 1.3 $ */
|
||||
/* $Date: 2005/05/05 14:35:58 $ */
|
||||
/* $Revision: 1.4 $ */
|
||||
/* $Date: 2006/03/31 14:15:35 $ */
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -29,13 +29,13 @@ int gcm_test(void)
|
||||
static const struct {
|
||||
unsigned char K[32];
|
||||
int keylen;
|
||||
unsigned char P[64];
|
||||
unsigned char P[128];
|
||||
unsigned long ptlen;
|
||||
unsigned char A[64];
|
||||
unsigned char A[128];
|
||||
unsigned long alen;
|
||||
unsigned char IV[64];
|
||||
unsigned char IV[128];
|
||||
unsigned long IVlen;
|
||||
unsigned char C[64];
|
||||
unsigned char C[128];
|
||||
unsigned char T[16];
|
||||
} tests[] = {
|
||||
|
||||
@@ -275,13 +275,58 @@ int gcm_test(void)
|
||||
/* TAG */
|
||||
{ 0x61, 0x9c, 0xc5, 0xae, 0xff, 0xfe, 0x0b, 0xfa,
|
||||
0x46, 0x2a, 0xf4, 0x3c, 0x16, 0x99, 0xd0, 0x50, }
|
||||
},
|
||||
|
||||
/* test case #46 from BG (catches the LTC bug of v1.15) */
|
||||
{
|
||||
/* key */
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
||||
16,
|
||||
|
||||
/* PT */
|
||||
{ 0xa2, 0xaa, 0xb3, 0xad, 0x8b, 0x17, 0xac, 0xdd,
|
||||
0xa2, 0x88, 0x42, 0x6c, 0xd7, 0xc4, 0x29, 0xb7,
|
||||
0xca, 0x86, 0xb7, 0xac, 0xa0, 0x58, 0x09, 0xc7,
|
||||
0x0c, 0xe8, 0x2d, 0xb2, 0x57, 0x11, 0xcb, 0x53,
|
||||
0x02, 0xeb, 0x27, 0x43, 0xb0, 0x36, 0xf3, 0xd7,
|
||||
0x50, 0xd6, 0xcf, 0x0d, 0xc0, 0xac, 0xb9, 0x29,
|
||||
0x50, 0xd5, 0x46, 0xdb, 0x30, 0x8f, 0x93, 0xb4,
|
||||
0xff, 0x24, 0x4a, 0xfa, 0x9d, 0xc7, 0x2b, 0xcd,
|
||||
0x75, 0x8d, 0x2c },
|
||||
67,
|
||||
|
||||
/* ADATA */
|
||||
{ 0x68, 0x8e, 0x1a, 0xa9, 0x84, 0xde, 0x92, 0x6d,
|
||||
0xc7, 0xb4, 0xc4, 0x7f, 0x44 },
|
||||
13,
|
||||
|
||||
/* IV */
|
||||
{ 0xb7, 0x21, 0x38, 0xb5, 0xa0, 0x5f, 0xf5, 0x07,
|
||||
0x0e, 0x8c, 0xd9, 0x41, 0x83, 0xf7, 0x61, 0xd8 },
|
||||
16,
|
||||
|
||||
/* CT */
|
||||
{ 0xcb, 0xc8, 0xd2, 0xf1, 0x54, 0x81, 0xa4, 0xcc,
|
||||
0x7d, 0xd1, 0xe1, 0x9a, 0xaa, 0x83, 0xde, 0x56,
|
||||
0x78, 0x48, 0x3e, 0xc3, 0x59, 0xae, 0x7d, 0xec,
|
||||
0x2a, 0xb8, 0xd5, 0x34, 0xe0, 0x90, 0x6f, 0x4b,
|
||||
0x46, 0x63, 0xfa, 0xff, 0x58, 0xa8, 0xb2, 0xd7,
|
||||
0x33, 0xb8, 0x45, 0xee, 0xf7, 0xc9, 0xb3, 0x31,
|
||||
0xe9, 0xe1, 0x0e, 0xb2, 0x61, 0x2c, 0x99, 0x5f,
|
||||
0xeb, 0x1a, 0xc1, 0x5a, 0x62, 0x86, 0xcc, 0xe8,
|
||||
0xb2, 0x97, 0xa8 },
|
||||
|
||||
/* TAG */
|
||||
{ 0x8d, 0x2d, 0x2a, 0x93, 0x72, 0x62, 0x6f, 0x6b,
|
||||
0xee, 0x85, 0x80, 0x27, 0x6a, 0x63, 0x66, 0xbf }
|
||||
}
|
||||
|
||||
/* rest of test cases are the same except AES key size changes... ignored... */
|
||||
};
|
||||
int idx, err;
|
||||
unsigned long x, y;
|
||||
unsigned char out[2][64], T[2][16];
|
||||
unsigned char out[2][128], T[2][16];
|
||||
|
||||
/* find aes */
|
||||
idx = find_cipher("aes");
|
||||
@@ -302,7 +347,7 @@ int gcm_test(void)
|
||||
return err;
|
||||
}
|
||||
|
||||
if (memcmp(out[0], tests[x].C, tests[x].ptlen)) {
|
||||
if (XMEMCMP(out[0], tests[x].C, tests[x].ptlen)) {
|
||||
#if 0
|
||||
printf("\nCiphertext wrong %lu\n", x);
|
||||
for (y = 0; y < tests[x].ptlen; y++) {
|
||||
@@ -313,7 +358,7 @@ int gcm_test(void)
|
||||
return CRYPT_FAIL_TESTVECTOR;
|
||||
}
|
||||
|
||||
if (memcmp(T[0], tests[x].T, 16)) {
|
||||
if (XMEMCMP(T[0], tests[x].T, 16)) {
|
||||
#if 0
|
||||
printf("\nTag on plaintext wrong %lu\n", x);
|
||||
for (y = 0; y < 16; y++) {
|
||||
@@ -333,7 +378,7 @@ int gcm_test(void)
|
||||
return err;
|
||||
}
|
||||
|
||||
if (memcmp(out[1], tests[x].P, tests[x].ptlen)) {
|
||||
if (XMEMCMP(out[1], tests[x].P, tests[x].ptlen)) {
|
||||
#if 0
|
||||
printf("\nplaintext wrong %lu\n", x);
|
||||
for (y = 0; y < tests[x].ptlen; y++) {
|
||||
@@ -344,7 +389,7 @@ int gcm_test(void)
|
||||
return CRYPT_FAIL_TESTVECTOR;
|
||||
}
|
||||
|
||||
if (memcmp(T[1], tests[x].T, 16)) {
|
||||
if (XMEMCMP(T[1], tests[x].T, 16)) {
|
||||
#if 0
|
||||
printf("\nTag on ciphertext wrong %lu\n", x);
|
||||
for (y = 0; y < 16; y++) {
|
||||
@@ -364,5 +409,5 @@ int gcm_test(void)
|
||||
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/encauth/gcm/gcm_test.c,v $ */
|
||||
/* $Revision: 1.15 $ */
|
||||
/* $Date: 2005/05/05 14:35:58 $ */
|
||||
/* $Revision: 1.20 $ */
|
||||
/* $Date: 2006/12/03 17:25:44 $ */
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -51,7 +51,9 @@ int ocb_decrypt(ocb_state *ocb, const unsigned char *ct, unsigned char *pt)
|
||||
for (x = 0; x < ocb->block_len; x++) {
|
||||
tmp[x] = ct[x] ^ Z[x];
|
||||
}
|
||||
cipher_descriptor[ocb->cipher].ecb_decrypt(tmp, pt, &ocb->key);
|
||||
if ((err = cipher_descriptor[ocb->cipher].ecb_decrypt(tmp, pt, &ocb->key)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
for (x = 0; x < ocb->block_len; x++) {
|
||||
pt[x] ^= Z[x];
|
||||
}
|
||||
@@ -73,5 +75,5 @@ int ocb_decrypt(ocb_state *ocb, const unsigned char *ct, unsigned char *pt)
|
||||
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/encauth/ocb/ocb_decrypt.c,v $ */
|
||||
/* $Revision: 1.3 $ */
|
||||
/* $Date: 2005/05/05 14:35:58 $ */
|
||||
/* $Revision: 1.5 $ */
|
||||
/* $Date: 2006/03/31 14:15:35 $ */
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -82,5 +82,5 @@ LBL_ERR:
|
||||
#endif
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/encauth/ocb/ocb_decrypt_verify_memory.c,v $ */
|
||||
/* $Revision: 1.3 $ */
|
||||
/* $Date: 2005/05/05 14:35:58 $ */
|
||||
/* $Revision: 1.4 $ */
|
||||
/* $Date: 2006/03/31 14:15:35 $ */
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -57,7 +57,7 @@ int ocb_done_decrypt(ocb_state *ocb,
|
||||
goto LBL_ERR;
|
||||
}
|
||||
|
||||
if (taglen <= tagbuflen && memcmp(tagbuf, tag, taglen) == 0) {
|
||||
if (taglen <= tagbuflen && XMEMCMP(tagbuf, tag, taglen) == 0) {
|
||||
*stat = 1;
|
||||
}
|
||||
|
||||
@@ -76,5 +76,5 @@ LBL_ERR:
|
||||
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/encauth/ocb/ocb_done_decrypt.c,v $ */
|
||||
/* $Revision: 1.3 $ */
|
||||
/* $Date: 2005/05/05 14:35:58 $ */
|
||||
/* $Revision: 1.5 $ */
|
||||
/* $Date: 2006/11/01 09:28:17 $ */
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -42,5 +42,5 @@ int ocb_done_encrypt(ocb_state *ocb, const unsigned char *pt, unsigned long ptle
|
||||
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/encauth/ocb/ocb_done_encrypt.c,v $ */
|
||||
/* $Revision: 1.3 $ */
|
||||
/* $Date: 2005/05/05 14:35:58 $ */
|
||||
/* $Revision: 1.4 $ */
|
||||
/* $Date: 2006/03/31 14:15:35 $ */
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -51,7 +51,9 @@ int ocb_encrypt(ocb_state *ocb, const unsigned char *pt, unsigned char *ct)
|
||||
for (x = 0; x < ocb->block_len; x++) {
|
||||
tmp[x] = pt[x] ^ Z[x];
|
||||
}
|
||||
cipher_descriptor[ocb->cipher].ecb_encrypt(tmp, ct, &ocb->key);
|
||||
if ((err = cipher_descriptor[ocb->cipher].ecb_encrypt(tmp, ct, &ocb->key)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
for (x = 0; x < ocb->block_len; x++) {
|
||||
ct[x] ^= Z[x];
|
||||
}
|
||||
@@ -66,5 +68,5 @@ int ocb_encrypt(ocb_state *ocb, const unsigned char *pt, unsigned char *ct)
|
||||
#endif
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/encauth/ocb/ocb_encrypt.c,v $ */
|
||||
/* $Revision: 1.3 $ */
|
||||
/* $Date: 2005/05/05 14:35:58 $ */
|
||||
/* $Revision: 1.5 $ */
|
||||
/* $Date: 2006/03/31 14:15:35 $ */
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -80,5 +80,5 @@ LBL_ERR:
|
||||
#endif
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/encauth/ocb/ocb_encrypt_authenticate_memory.c,v $ */
|
||||
/* $Revision: 1.3 $ */
|
||||
/* $Date: 2005/05/05 14:35:58 $ */
|
||||
/* $Revision: 1.4 $ */
|
||||
/* $Date: 2006/03/31 14:15:35 $ */
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -76,13 +76,17 @@ int ocb_init(ocb_state *ocb, int cipher,
|
||||
|
||||
/* find L = E[0] */
|
||||
zeromem(ocb->L, ocb->block_len);
|
||||
cipher_descriptor[cipher].ecb_encrypt(ocb->L, ocb->L, &ocb->key);
|
||||
if ((err = cipher_descriptor[cipher].ecb_encrypt(ocb->L, ocb->L, &ocb->key)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
/* find R = E[N xor L] */
|
||||
for (x = 0; x < ocb->block_len; x++) {
|
||||
ocb->R[x] = ocb->L[x] ^ nonce[x];
|
||||
}
|
||||
cipher_descriptor[cipher].ecb_encrypt(ocb->R, ocb->R, &ocb->key);
|
||||
if ((err = cipher_descriptor[cipher].ecb_encrypt(ocb->R, ocb->R, &ocb->key)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
/* find Ls[i] = L << i for i == 0..31 */
|
||||
XMEMCPY(ocb->Ls[0], ocb->L, ocb->block_len);
|
||||
@@ -129,5 +133,5 @@ int ocb_init(ocb_state *ocb, int cipher,
|
||||
#endif
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/encauth/ocb/ocb_init.c,v $ */
|
||||
/* $Revision: 1.3 $ */
|
||||
/* $Date: 2005/05/05 14:35:58 $ */
|
||||
/* $Revision: 1.5 $ */
|
||||
/* $Date: 2006/03/31 14:15:35 $ */
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -38,5 +38,5 @@ int ocb_ntz(unsigned long x)
|
||||
#endif
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/encauth/ocb/ocb_ntz.c,v $ */
|
||||
/* $Revision: 1.3 $ */
|
||||
/* $Date: 2005/05/05 14:35:58 $ */
|
||||
/* $Revision: 1.4 $ */
|
||||
/* $Date: 2006/03/31 14:15:35 $ */
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -35,5 +35,5 @@ void ocb_shift_xor(ocb_state *ocb, unsigned char *Z)
|
||||
#endif
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/encauth/ocb/ocb_shift_xor.c,v $ */
|
||||
/* $Revision: 1.3 $ */
|
||||
/* $Date: 2005/05/05 14:35:58 $ */
|
||||
/* $Revision: 1.4 $ */
|
||||
/* $Date: 2006/03/31 14:15:35 $ */
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -182,7 +182,7 @@ int ocb_test(void)
|
||||
return err;
|
||||
}
|
||||
|
||||
if (memcmp(outtag, tests[x].tag, len) || memcmp(outct, tests[x].ct, tests[x].ptlen)) {
|
||||
if (XMEMCMP(outtag, tests[x].tag, len) || XMEMCMP(outct, tests[x].ct, tests[x].ptlen)) {
|
||||
#if 0
|
||||
unsigned long y;
|
||||
printf("\n\nFailure: \nCT:\n");
|
||||
@@ -205,7 +205,7 @@ int ocb_test(void)
|
||||
outct, tests[x].tag, len, &res)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
if ((res != 1) || memcmp(tests[x].pt, outct, tests[x].ptlen)) {
|
||||
if ((res != 1) || XMEMCMP(tests[x].pt, outct, tests[x].ptlen)) {
|
||||
#if 0
|
||||
unsigned long y;
|
||||
printf("\n\nFailure-decrypt: \nPT:\n");
|
||||
@@ -233,5 +233,5 @@ int ocb_test(void)
|
||||
*/
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/encauth/ocb/ocb_test.c,v $ */
|
||||
/* $Revision: 1.3 $ */
|
||||
/* $Date: 2005/05/05 14:35:58 $ */
|
||||
/* $Revision: 1.5 $ */
|
||||
/* $Date: 2006/11/01 09:28:17 $ */
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -84,7 +84,9 @@ int s_ocb_done(ocb_state *ocb, const unsigned char *pt, unsigned long ptlen,
|
||||
}
|
||||
|
||||
/* Y[m] = E(X[m])) */
|
||||
cipher_descriptor[ocb->cipher].ecb_encrypt(X, Y, &ocb->key);
|
||||
if ((err = cipher_descriptor[ocb->cipher].ecb_encrypt(X, Y, &ocb->key)) != CRYPT_OK) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (mode == 1) {
|
||||
/* decrypt mode, so let's xor it first */
|
||||
@@ -113,7 +115,9 @@ int s_ocb_done(ocb_state *ocb, const unsigned char *pt, unsigned long ptlen,
|
||||
}
|
||||
|
||||
/* encrypt checksum, er... tag!! */
|
||||
cipher_descriptor[ocb->cipher].ecb_encrypt(ocb->checksum, X, &ocb->key);
|
||||
if ((err = cipher_descriptor[ocb->cipher].ecb_encrypt(ocb->checksum, X, &ocb->key)) != CRYPT_OK) {
|
||||
goto error;
|
||||
}
|
||||
cipher_descriptor[ocb->cipher].done(&ocb->key);
|
||||
|
||||
/* now store it */
|
||||
@@ -128,17 +132,17 @@ int s_ocb_done(ocb_state *ocb, const unsigned char *pt, unsigned long ptlen,
|
||||
zeromem(Z, MAXBLOCKSIZE);
|
||||
zeromem(ocb, sizeof(*ocb));
|
||||
#endif
|
||||
|
||||
error:
|
||||
XFREE(X);
|
||||
XFREE(Y);
|
||||
XFREE(Z);
|
||||
|
||||
return CRYPT_OK;
|
||||
return err;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/encauth/ocb/s_ocb_done.c,v $ */
|
||||
/* $Revision: 1.4 $ */
|
||||
/* $Date: 2005/05/05 14:35:58 $ */
|
||||
/* $Revision: 1.6 $ */
|
||||
/* $Date: 2006/03/31 14:15:35 $ */
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
*/
|
||||
|
||||
#include "tomcrypt.h"
|
||||
@@ -30,7 +30,8 @@ const struct ltc_hash_descriptor chc_desc = {
|
||||
&chc_init,
|
||||
&chc_process,
|
||||
&chc_done,
|
||||
&chc_test
|
||||
&chc_test,
|
||||
NULL
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -141,7 +142,7 @@ static int chc_compress(hash_state *md, unsigned char *buf)
|
||||
XFREE(key);
|
||||
return err;
|
||||
}
|
||||
memcpy(T[1], buf, cipher_blocksize);
|
||||
XMEMCPY(T[1], buf, cipher_blocksize);
|
||||
cipher_descriptor[cipher_idx].ecb_encrypt(buf, T[0], key);
|
||||
for (x = 0; x < cipher_blocksize; x++) {
|
||||
md->chc.state[x] ^= T[0][x] ^ T[1][x];
|
||||
@@ -279,7 +280,7 @@ int chc_test(void)
|
||||
chc_init(&md);
|
||||
chc_process(&md, tests[x].msg, strlen((char *)tests[x].msg));
|
||||
chc_done(&md, out);
|
||||
if (memcmp(out, tests[x].md, tests[x].len)) {
|
||||
if (XMEMCMP(out, tests[x].md, tests[x].len)) {
|
||||
return CRYPT_FAIL_TESTVECTOR;
|
||||
}
|
||||
}
|
||||
@@ -293,5 +294,5 @@ int chc_test(void)
|
||||
#endif
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/hashes/chc/chc.c,v $ */
|
||||
/* $Revision: 1.3 $ */
|
||||
/* $Date: 2005/05/05 14:35:58 $ */
|
||||
/* $Revision: 1.6 $ */
|
||||
/* $Date: 2006/11/01 09:28:17 $ */
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
@@ -53,5 +53,5 @@ int hash_file(int hash, const char *fname, unsigned char *out, unsigned long *ou
|
||||
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/hashes/helper/hash_file.c,v $ */
|
||||
/* $Revision: 1.3 $ */
|
||||
/* $Date: 2005/05/05 14:35:58 $ */
|
||||
/* $Revision: 1.4 $ */
|
||||
/* $Date: 2006/03/31 14:15:35 $ */
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
@@ -42,6 +42,7 @@ int hash_filehandle(int hash, FILE *in, unsigned char *out, unsigned long *outle
|
||||
}
|
||||
|
||||
if (*outlen < hash_descriptor[hash].hashsize) {
|
||||
*outlen = hash_descriptor[hash].hashsize;
|
||||
return CRYPT_BUFFER_OVERFLOW;
|
||||
}
|
||||
if ((err = hash_descriptor[hash].init(&md)) != CRYPT_OK) {
|
||||
@@ -66,5 +67,5 @@ int hash_filehandle(int hash, FILE *in, unsigned char *out, unsigned long *outle
|
||||
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/hashes/helper/hash_filehandle.c,v $ */
|
||||
/* $Revision: 1.3 $ */
|
||||
/* $Date: 2005/05/05 14:35:58 $ */
|
||||
/* $Revision: 1.5 $ */
|
||||
/* $Date: 2006/06/16 21:53:41 $ */
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
@@ -38,6 +38,7 @@ int hash_memory(int hash, const unsigned char *in, unsigned long inlen, unsigned
|
||||
}
|
||||
|
||||
if (*outlen < hash_descriptor[hash].hashsize) {
|
||||
*outlen = hash_descriptor[hash].hashsize;
|
||||
return CRYPT_BUFFER_OVERFLOW;
|
||||
}
|
||||
|
||||
@@ -64,5 +65,5 @@ LBL_ERR:
|
||||
}
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/hashes/helper/hash_memory.c,v $ */
|
||||
/* $Revision: 1.3 $ */
|
||||
/* $Date: 2005/05/05 14:35:58 $ */
|
||||
/* $Revision: 1.5 $ */
|
||||
/* $Date: 2006/06/16 21:53:41 $ */
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
#include <stdarg.h>
|
||||
@@ -43,6 +43,7 @@ int hash_memory_multi(int hash, unsigned char *out, unsigned long *outlen,
|
||||
}
|
||||
|
||||
if (*outlen < hash_descriptor[hash].hashsize) {
|
||||
*outlen = hash_descriptor[hash].hashsize;
|
||||
return CRYPT_BUFFER_OVERFLOW;
|
||||
}
|
||||
|
||||
@@ -82,5 +83,5 @@ LBL_ERR:
|
||||
}
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/hashes/helper/hash_memory_multi.c,v $ */
|
||||
/* $Revision: 1.3 $ */
|
||||
/* $Date: 2005/05/05 14:35:58 $ */
|
||||
/* $Revision: 1.5 $ */
|
||||
/* $Date: 2006/06/16 21:53:41 $ */
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
@@ -31,7 +31,8 @@ const struct ltc_hash_descriptor md2_desc =
|
||||
&md2_init,
|
||||
&md2_process,
|
||||
&md2_done,
|
||||
&md2_test
|
||||
&md2_test,
|
||||
NULL
|
||||
};
|
||||
|
||||
static const unsigned char PI_SUBST[256] = {
|
||||
@@ -234,7 +235,7 @@ int md2_test(void)
|
||||
md2_init(&md);
|
||||
md2_process(&md, (unsigned char*)tests[i].msg, (unsigned long)strlen(tests[i].msg));
|
||||
md2_done(&md, buf);
|
||||
if (memcmp(buf, tests[i].md, 16) != 0) {
|
||||
if (XMEMCMP(buf, tests[i].md, 16) != 0) {
|
||||
return CRYPT_FAIL_TESTVECTOR;
|
||||
}
|
||||
}
|
||||
@@ -246,5 +247,5 @@ int md2_test(void)
|
||||
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/hashes/md2.c,v $ */
|
||||
/* $Revision: 1.5 $ */
|
||||
/* $Date: 2005/05/23 02:42:07 $ */
|
||||
/* $Revision: 1.8 $ */
|
||||
/* $Date: 2006/11/01 09:28:17 $ */
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
@@ -31,7 +31,8 @@ const struct ltc_hash_descriptor md4_desc =
|
||||
&md4_init,
|
||||
&md4_process,
|
||||
&md4_done,
|
||||
&md4_test
|
||||
&md4_test,
|
||||
NULL
|
||||
};
|
||||
|
||||
#define S11 3
|
||||
@@ -288,7 +289,7 @@ int md4_test(void)
|
||||
md4_init(&md);
|
||||
md4_process(&md, (unsigned char *)cases[i].input, (unsigned long)strlen(cases[i].input));
|
||||
md4_done(&md, digest);
|
||||
if (memcmp(digest, cases[i].digest, 16) != 0) {
|
||||
if (XMEMCMP(digest, cases[i].digest, 16) != 0) {
|
||||
return CRYPT_FAIL_TESTVECTOR;
|
||||
}
|
||||
|
||||
@@ -302,5 +303,5 @@ int md4_test(void)
|
||||
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/hashes/md4.c,v $ */
|
||||
/* $Revision: 1.5 $ */
|
||||
/* $Date: 2005/05/23 02:42:07 $ */
|
||||
/* $Revision: 1.8 $ */
|
||||
/* $Date: 2006/11/01 09:28:17 $ */
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
@@ -32,7 +32,8 @@ const struct ltc_hash_descriptor md5_desc =
|
||||
&md5_init,
|
||||
&md5_process,
|
||||
&md5_done,
|
||||
&md5_test
|
||||
&md5_test,
|
||||
NULL
|
||||
};
|
||||
|
||||
#define F(x,y,z) (z ^ (x & (y ^ z)))
|
||||
@@ -350,7 +351,7 @@ int md5_test(void)
|
||||
md5_init(&md);
|
||||
md5_process(&md, (unsigned char *)tests[i].msg, (unsigned long)strlen(tests[i].msg));
|
||||
md5_done(&md, tmp);
|
||||
if (memcmp(tmp, tests[i].hash, 16) != 0) {
|
||||
if (XMEMCMP(tmp, tests[i].hash, 16) != 0) {
|
||||
return CRYPT_FAIL_TESTVECTOR;
|
||||
}
|
||||
}
|
||||
@@ -363,5 +364,5 @@ int md5_test(void)
|
||||
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/hashes/md5.c,v $ */
|
||||
/* $Revision: 1.5 $ */
|
||||
/* $Date: 2005/05/23 02:42:07 $ */
|
||||
/* $Revision: 1.8 $ */
|
||||
/* $Date: 2006/11/01 09:28:17 $ */
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
@@ -37,7 +37,8 @@ const struct ltc_hash_descriptor rmd128_desc =
|
||||
&rmd128_init,
|
||||
&rmd128_process,
|
||||
&rmd128_done,
|
||||
&rmd128_test
|
||||
&rmd128_test,
|
||||
NULL
|
||||
};
|
||||
|
||||
/* the four basic functions F(), G() and H() */
|
||||
@@ -390,7 +391,7 @@ int rmd128_test(void)
|
||||
rmd128_init(&md);
|
||||
rmd128_process(&md, (unsigned char *)tests[x].msg, strlen(tests[x].msg));
|
||||
rmd128_done(&md, buf);
|
||||
if (memcmp(buf, tests[x].md, 16) != 0) {
|
||||
if (XMEMCMP(buf, tests[x].md, 16) != 0) {
|
||||
#if 0
|
||||
printf("Failed test %d\n", x);
|
||||
#endif
|
||||
@@ -405,5 +406,5 @@ int rmd128_test(void)
|
||||
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/hashes/rmd128.c,v $ */
|
||||
/* $Revision: 1.6 $ */
|
||||
/* $Date: 2005/05/23 02:42:07 $ */
|
||||
/* $Revision: 1.9 $ */
|
||||
/* $Date: 2006/11/01 09:28:17 $ */
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
@@ -37,7 +37,8 @@ const struct ltc_hash_descriptor rmd160_desc =
|
||||
&rmd160_init,
|
||||
&rmd160_process,
|
||||
&rmd160_done,
|
||||
&rmd160_test
|
||||
&rmd160_test,
|
||||
NULL
|
||||
};
|
||||
|
||||
/* the five basic functions F(), G() and H() */
|
||||
@@ -449,7 +450,7 @@ int rmd160_test(void)
|
||||
rmd160_init(&md);
|
||||
rmd160_process(&md, (unsigned char *)tests[x].msg, strlen(tests[x].msg));
|
||||
rmd160_done(&md, buf);
|
||||
if (memcmp(buf, tests[x].md, 20) != 0) {
|
||||
if (XMEMCMP(buf, tests[x].md, 20) != 0) {
|
||||
#if 0
|
||||
printf("Failed test %d\n", x);
|
||||
#endif
|
||||
@@ -464,5 +465,5 @@ int rmd160_test(void)
|
||||
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/hashes/rmd160.c,v $ */
|
||||
/* $Revision: 1.5 $ */
|
||||
/* $Date: 2005/05/23 02:42:07 $ */
|
||||
/* $Revision: 1.8 $ */
|
||||
/* $Date: 2006/11/01 09:28:17 $ */
|
||||
|
||||
431
libtomcrypt/src/hashes/rmd256.c
Normal file
431
libtomcrypt/src/hashes/rmd256.c
Normal file
@@ -0,0 +1,431 @@
|
||||
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
|
||||
*
|
||||
* LibTomCrypt is a library that provides various cryptographic
|
||||
* algorithms in a highly modular and flexible manner.
|
||||
*
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
/**
|
||||
@param rmd256.c
|
||||
RMD256 Hash function
|
||||
*/
|
||||
|
||||
#ifdef RIPEMD256
|
||||
|
||||
const struct ltc_hash_descriptor rmd256_desc =
|
||||
{
|
||||
"rmd256",
|
||||
8,
|
||||
16,
|
||||
64,
|
||||
|
||||
/* OID */
|
||||
{ 1, 3, 36, 3, 2, 3 },
|
||||
6,
|
||||
|
||||
&rmd256_init,
|
||||
&rmd256_process,
|
||||
&rmd256_done,
|
||||
&rmd256_test,
|
||||
NULL
|
||||
};
|
||||
|
||||
/* the four basic functions F(), G() and H() */
|
||||
#define F(x, y, z) ((x) ^ (y) ^ (z))
|
||||
#define G(x, y, z) (((x) & (y)) | (~(x) & (z)))
|
||||
#define H(x, y, z) (((x) | ~(y)) ^ (z))
|
||||
#define I(x, y, z) (((x) & (z)) | ((y) & ~(z)))
|
||||
|
||||
/* the eight basic operations FF() through III() */
|
||||
#define FF(a, b, c, d, x, s) \
|
||||
(a) += F((b), (c), (d)) + (x);\
|
||||
(a) = ROLc((a), (s));
|
||||
|
||||
#define GG(a, b, c, d, x, s) \
|
||||
(a) += G((b), (c), (d)) + (x) + 0x5a827999UL;\
|
||||
(a) = ROLc((a), (s));
|
||||
|
||||
#define HH(a, b, c, d, x, s) \
|
||||
(a) += H((b), (c), (d)) + (x) + 0x6ed9eba1UL;\
|
||||
(a) = ROLc((a), (s));
|
||||
|
||||
#define II(a, b, c, d, x, s) \
|
||||
(a) += I((b), (c), (d)) + (x) + 0x8f1bbcdcUL;\
|
||||
(a) = ROLc((a), (s));
|
||||
|
||||
#define FFF(a, b, c, d, x, s) \
|
||||
(a) += F((b), (c), (d)) + (x);\
|
||||
(a) = ROLc((a), (s));
|
||||
|
||||
#define GGG(a, b, c, d, x, s) \
|
||||
(a) += G((b), (c), (d)) + (x) + 0x6d703ef3UL;\
|
||||
(a) = ROLc((a), (s));
|
||||
|
||||
#define HHH(a, b, c, d, x, s) \
|
||||
(a) += H((b), (c), (d)) + (x) + 0x5c4dd124UL;\
|
||||
(a) = ROLc((a), (s));
|
||||
|
||||
#define III(a, b, c, d, x, s) \
|
||||
(a) += I((b), (c), (d)) + (x) + 0x50a28be6UL;\
|
||||
(a) = ROLc((a), (s));
|
||||
|
||||
#ifdef LTC_CLEAN_STACK
|
||||
static int _rmd256_compress(hash_state *md, unsigned char *buf)
|
||||
#else
|
||||
static int rmd256_compress(hash_state *md, unsigned char *buf)
|
||||
#endif
|
||||
{
|
||||
ulong32 aa,bb,cc,dd,aaa,bbb,ccc,ddd,tmp,X[16];
|
||||
int i;
|
||||
|
||||
/* load words X */
|
||||
for (i = 0; i < 16; i++){
|
||||
LOAD32L(X[i], buf + (4 * i));
|
||||
}
|
||||
|
||||
/* load state */
|
||||
aa = md->rmd256.state[0];
|
||||
bb = md->rmd256.state[1];
|
||||
cc = md->rmd256.state[2];
|
||||
dd = md->rmd256.state[3];
|
||||
aaa = md->rmd256.state[4];
|
||||
bbb = md->rmd256.state[5];
|
||||
ccc = md->rmd256.state[6];
|
||||
ddd = md->rmd256.state[7];
|
||||
|
||||
/* round 1 */
|
||||
FF(aa, bb, cc, dd, X[ 0], 11);
|
||||
FF(dd, aa, bb, cc, X[ 1], 14);
|
||||
FF(cc, dd, aa, bb, X[ 2], 15);
|
||||
FF(bb, cc, dd, aa, X[ 3], 12);
|
||||
FF(aa, bb, cc, dd, X[ 4], 5);
|
||||
FF(dd, aa, bb, cc, X[ 5], 8);
|
||||
FF(cc, dd, aa, bb, X[ 6], 7);
|
||||
FF(bb, cc, dd, aa, X[ 7], 9);
|
||||
FF(aa, bb, cc, dd, X[ 8], 11);
|
||||
FF(dd, aa, bb, cc, X[ 9], 13);
|
||||
FF(cc, dd, aa, bb, X[10], 14);
|
||||
FF(bb, cc, dd, aa, X[11], 15);
|
||||
FF(aa, bb, cc, dd, X[12], 6);
|
||||
FF(dd, aa, bb, cc, X[13], 7);
|
||||
FF(cc, dd, aa, bb, X[14], 9);
|
||||
FF(bb, cc, dd, aa, X[15], 8);
|
||||
|
||||
/* parallel round 1 */
|
||||
III(aaa, bbb, ccc, ddd, X[ 5], 8);
|
||||
III(ddd, aaa, bbb, ccc, X[14], 9);
|
||||
III(ccc, ddd, aaa, bbb, X[ 7], 9);
|
||||
III(bbb, ccc, ddd, aaa, X[ 0], 11);
|
||||
III(aaa, bbb, ccc, ddd, X[ 9], 13);
|
||||
III(ddd, aaa, bbb, ccc, X[ 2], 15);
|
||||
III(ccc, ddd, aaa, bbb, X[11], 15);
|
||||
III(bbb, ccc, ddd, aaa, X[ 4], 5);
|
||||
III(aaa, bbb, ccc, ddd, X[13], 7);
|
||||
III(ddd, aaa, bbb, ccc, X[ 6], 7);
|
||||
III(ccc, ddd, aaa, bbb, X[15], 8);
|
||||
III(bbb, ccc, ddd, aaa, X[ 8], 11);
|
||||
III(aaa, bbb, ccc, ddd, X[ 1], 14);
|
||||
III(ddd, aaa, bbb, ccc, X[10], 14);
|
||||
III(ccc, ddd, aaa, bbb, X[ 3], 12);
|
||||
III(bbb, ccc, ddd, aaa, X[12], 6);
|
||||
|
||||
tmp = aa; aa = aaa; aaa = tmp;
|
||||
|
||||
/* round 2 */
|
||||
GG(aa, bb, cc, dd, X[ 7], 7);
|
||||
GG(dd, aa, bb, cc, X[ 4], 6);
|
||||
GG(cc, dd, aa, bb, X[13], 8);
|
||||
GG(bb, cc, dd, aa, X[ 1], 13);
|
||||
GG(aa, bb, cc, dd, X[10], 11);
|
||||
GG(dd, aa, bb, cc, X[ 6], 9);
|
||||
GG(cc, dd, aa, bb, X[15], 7);
|
||||
GG(bb, cc, dd, aa, X[ 3], 15);
|
||||
GG(aa, bb, cc, dd, X[12], 7);
|
||||
GG(dd, aa, bb, cc, X[ 0], 12);
|
||||
GG(cc, dd, aa, bb, X[ 9], 15);
|
||||
GG(bb, cc, dd, aa, X[ 5], 9);
|
||||
GG(aa, bb, cc, dd, X[ 2], 11);
|
||||
GG(dd, aa, bb, cc, X[14], 7);
|
||||
GG(cc, dd, aa, bb, X[11], 13);
|
||||
GG(bb, cc, dd, aa, X[ 8], 12);
|
||||
|
||||
/* parallel round 2 */
|
||||
HHH(aaa, bbb, ccc, ddd, X[ 6], 9);
|
||||
HHH(ddd, aaa, bbb, ccc, X[11], 13);
|
||||
HHH(ccc, ddd, aaa, bbb, X[ 3], 15);
|
||||
HHH(bbb, ccc, ddd, aaa, X[ 7], 7);
|
||||
HHH(aaa, bbb, ccc, ddd, X[ 0], 12);
|
||||
HHH(ddd, aaa, bbb, ccc, X[13], 8);
|
||||
HHH(ccc, ddd, aaa, bbb, X[ 5], 9);
|
||||
HHH(bbb, ccc, ddd, aaa, X[10], 11);
|
||||
HHH(aaa, bbb, ccc, ddd, X[14], 7);
|
||||
HHH(ddd, aaa, bbb, ccc, X[15], 7);
|
||||
HHH(ccc, ddd, aaa, bbb, X[ 8], 12);
|
||||
HHH(bbb, ccc, ddd, aaa, X[12], 7);
|
||||
HHH(aaa, bbb, ccc, ddd, X[ 4], 6);
|
||||
HHH(ddd, aaa, bbb, ccc, X[ 9], 15);
|
||||
HHH(ccc, ddd, aaa, bbb, X[ 1], 13);
|
||||
HHH(bbb, ccc, ddd, aaa, X[ 2], 11);
|
||||
|
||||
tmp = bb; bb = bbb; bbb = tmp;
|
||||
|
||||
/* round 3 */
|
||||
HH(aa, bb, cc, dd, X[ 3], 11);
|
||||
HH(dd, aa, bb, cc, X[10], 13);
|
||||
HH(cc, dd, aa, bb, X[14], 6);
|
||||
HH(bb, cc, dd, aa, X[ 4], 7);
|
||||
HH(aa, bb, cc, dd, X[ 9], 14);
|
||||
HH(dd, aa, bb, cc, X[15], 9);
|
||||
HH(cc, dd, aa, bb, X[ 8], 13);
|
||||
HH(bb, cc, dd, aa, X[ 1], 15);
|
||||
HH(aa, bb, cc, dd, X[ 2], 14);
|
||||
HH(dd, aa, bb, cc, X[ 7], 8);
|
||||
HH(cc, dd, aa, bb, X[ 0], 13);
|
||||
HH(bb, cc, dd, aa, X[ 6], 6);
|
||||
HH(aa, bb, cc, dd, X[13], 5);
|
||||
HH(dd, aa, bb, cc, X[11], 12);
|
||||
HH(cc, dd, aa, bb, X[ 5], 7);
|
||||
HH(bb, cc, dd, aa, X[12], 5);
|
||||
|
||||
/* parallel round 3 */
|
||||
GGG(aaa, bbb, ccc, ddd, X[15], 9);
|
||||
GGG(ddd, aaa, bbb, ccc, X[ 5], 7);
|
||||
GGG(ccc, ddd, aaa, bbb, X[ 1], 15);
|
||||
GGG(bbb, ccc, ddd, aaa, X[ 3], 11);
|
||||
GGG(aaa, bbb, ccc, ddd, X[ 7], 8);
|
||||
GGG(ddd, aaa, bbb, ccc, X[14], 6);
|
||||
GGG(ccc, ddd, aaa, bbb, X[ 6], 6);
|
||||
GGG(bbb, ccc, ddd, aaa, X[ 9], 14);
|
||||
GGG(aaa, bbb, ccc, ddd, X[11], 12);
|
||||
GGG(ddd, aaa, bbb, ccc, X[ 8], 13);
|
||||
GGG(ccc, ddd, aaa, bbb, X[12], 5);
|
||||
GGG(bbb, ccc, ddd, aaa, X[ 2], 14);
|
||||
GGG(aaa, bbb, ccc, ddd, X[10], 13);
|
||||
GGG(ddd, aaa, bbb, ccc, X[ 0], 13);
|
||||
GGG(ccc, ddd, aaa, bbb, X[ 4], 7);
|
||||
GGG(bbb, ccc, ddd, aaa, X[13], 5);
|
||||
|
||||
tmp = cc; cc = ccc; ccc = tmp;
|
||||
|
||||
/* round 4 */
|
||||
II(aa, bb, cc, dd, X[ 1], 11);
|
||||
II(dd, aa, bb, cc, X[ 9], 12);
|
||||
II(cc, dd, aa, bb, X[11], 14);
|
||||
II(bb, cc, dd, aa, X[10], 15);
|
||||
II(aa, bb, cc, dd, X[ 0], 14);
|
||||
II(dd, aa, bb, cc, X[ 8], 15);
|
||||
II(cc, dd, aa, bb, X[12], 9);
|
||||
II(bb, cc, dd, aa, X[ 4], 8);
|
||||
II(aa, bb, cc, dd, X[13], 9);
|
||||
II(dd, aa, bb, cc, X[ 3], 14);
|
||||
II(cc, dd, aa, bb, X[ 7], 5);
|
||||
II(bb, cc, dd, aa, X[15], 6);
|
||||
II(aa, bb, cc, dd, X[14], 8);
|
||||
II(dd, aa, bb, cc, X[ 5], 6);
|
||||
II(cc, dd, aa, bb, X[ 6], 5);
|
||||
II(bb, cc, dd, aa, X[ 2], 12);
|
||||
|
||||
/* parallel round 4 */
|
||||
FFF(aaa, bbb, ccc, ddd, X[ 8], 15);
|
||||
FFF(ddd, aaa, bbb, ccc, X[ 6], 5);
|
||||
FFF(ccc, ddd, aaa, bbb, X[ 4], 8);
|
||||
FFF(bbb, ccc, ddd, aaa, X[ 1], 11);
|
||||
FFF(aaa, bbb, ccc, ddd, X[ 3], 14);
|
||||
FFF(ddd, aaa, bbb, ccc, X[11], 14);
|
||||
FFF(ccc, ddd, aaa, bbb, X[15], 6);
|
||||
FFF(bbb, ccc, ddd, aaa, X[ 0], 14);
|
||||
FFF(aaa, bbb, ccc, ddd, X[ 5], 6);
|
||||
FFF(ddd, aaa, bbb, ccc, X[12], 9);
|
||||
FFF(ccc, ddd, aaa, bbb, X[ 2], 12);
|
||||
FFF(bbb, ccc, ddd, aaa, X[13], 9);
|
||||
FFF(aaa, bbb, ccc, ddd, X[ 9], 12);
|
||||
FFF(ddd, aaa, bbb, ccc, X[ 7], 5);
|
||||
FFF(ccc, ddd, aaa, bbb, X[10], 15);
|
||||
FFF(bbb, ccc, ddd, aaa, X[14], 8);
|
||||
|
||||
tmp = dd; dd = ddd; ddd = tmp;
|
||||
|
||||
/* combine results */
|
||||
md->rmd256.state[0] += aa;
|
||||
md->rmd256.state[1] += bb;
|
||||
md->rmd256.state[2] += cc;
|
||||
md->rmd256.state[3] += dd;
|
||||
md->rmd256.state[4] += aaa;
|
||||
md->rmd256.state[5] += bbb;
|
||||
md->rmd256.state[6] += ccc;
|
||||
md->rmd256.state[7] += ddd;
|
||||
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
#ifdef LTC_CLEAN_STACK
|
||||
static int rmd256_compress(hash_state *md, unsigned char *buf)
|
||||
{
|
||||
int err;
|
||||
err = _rmd256_compress(md, buf);
|
||||
burn_stack(sizeof(ulong32) * 25 + sizeof(int));
|
||||
return err;
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
Initialize the hash state
|
||||
@param md The hash state you wish to initialize
|
||||
@return CRYPT_OK if successful
|
||||
*/
|
||||
int rmd256_init(hash_state * md)
|
||||
{
|
||||
LTC_ARGCHK(md != NULL);
|
||||
md->rmd256.state[0] = 0x67452301UL;
|
||||
md->rmd256.state[1] = 0xefcdab89UL;
|
||||
md->rmd256.state[2] = 0x98badcfeUL;
|
||||
md->rmd256.state[3] = 0x10325476UL;
|
||||
md->rmd256.state[4] = 0x76543210UL;
|
||||
md->rmd256.state[5] = 0xfedcba98UL;
|
||||
md->rmd256.state[6] = 0x89abcdefUL;
|
||||
md->rmd256.state[7] = 0x01234567UL;
|
||||
md->rmd256.curlen = 0;
|
||||
md->rmd256.length = 0;
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
Process a block of memory though the hash
|
||||
@param md The hash state
|
||||
@param in The data to hash
|
||||
@param inlen The length of the data (octets)
|
||||
@return CRYPT_OK if successful
|
||||
*/
|
||||
HASH_PROCESS(rmd256_process, rmd256_compress, rmd256, 64)
|
||||
|
||||
/**
|
||||
Terminate the hash to get the digest
|
||||
@param md The hash state
|
||||
@param out [out] The destination of the hash (16 bytes)
|
||||
@return CRYPT_OK if successful
|
||||
*/
|
||||
int rmd256_done(hash_state * md, unsigned char *out)
|
||||
{
|
||||
int i;
|
||||
|
||||
LTC_ARGCHK(md != NULL);
|
||||
LTC_ARGCHK(out != NULL);
|
||||
|
||||
if (md->rmd256.curlen >= sizeof(md->rmd256.buf)) {
|
||||
return CRYPT_INVALID_ARG;
|
||||
}
|
||||
|
||||
|
||||
/* increase the length of the message */
|
||||
md->rmd256.length += md->rmd256.curlen * 8;
|
||||
|
||||
/* append the '1' bit */
|
||||
md->rmd256.buf[md->rmd256.curlen++] = (unsigned char)0x80;
|
||||
|
||||
/* if the length is currently above 56 bytes we append zeros
|
||||
* then compress. Then we can fall back to padding zeros and length
|
||||
* encoding like normal.
|
||||
*/
|
||||
if (md->rmd256.curlen > 56) {
|
||||
while (md->rmd256.curlen < 64) {
|
||||
md->rmd256.buf[md->rmd256.curlen++] = (unsigned char)0;
|
||||
}
|
||||
rmd256_compress(md, md->rmd256.buf);
|
||||
md->rmd256.curlen = 0;
|
||||
}
|
||||
|
||||
/* pad upto 56 bytes of zeroes */
|
||||
while (md->rmd256.curlen < 56) {
|
||||
md->rmd256.buf[md->rmd256.curlen++] = (unsigned char)0;
|
||||
}
|
||||
|
||||
/* store length */
|
||||
STORE64L(md->rmd256.length, md->rmd256.buf+56);
|
||||
rmd256_compress(md, md->rmd256.buf);
|
||||
|
||||
/* copy output */
|
||||
for (i = 0; i < 8; i++) {
|
||||
STORE32L(md->rmd256.state[i], out+(4*i));
|
||||
}
|
||||
#ifdef LTC_CLEAN_STACK
|
||||
zeromem(md, sizeof(hash_state));
|
||||
#endif
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
Self-test the hash
|
||||
@return CRYPT_OK if successful, CRYPT_NOP if self-tests have been disabled
|
||||
*/
|
||||
int rmd256_test(void)
|
||||
{
|
||||
#ifndef LTC_TEST
|
||||
return CRYPT_NOP;
|
||||
#else
|
||||
static const struct {
|
||||
char *msg;
|
||||
unsigned char md[32];
|
||||
} tests[] = {
|
||||
{ "",
|
||||
{ 0x02, 0xba, 0x4c, 0x4e, 0x5f, 0x8e, 0xcd, 0x18,
|
||||
0x77, 0xfc, 0x52, 0xd6, 0x4d, 0x30, 0xe3, 0x7a,
|
||||
0x2d, 0x97, 0x74, 0xfb, 0x1e, 0x5d, 0x02, 0x63,
|
||||
0x80, 0xae, 0x01, 0x68, 0xe3, 0xc5, 0x52, 0x2d }
|
||||
},
|
||||
{ "a",
|
||||
{ 0xf9, 0x33, 0x3e, 0x45, 0xd8, 0x57, 0xf5, 0xd9,
|
||||
0x0a, 0x91, 0xba, 0xb7, 0x0a, 0x1e, 0xba, 0x0c,
|
||||
0xfb, 0x1b, 0xe4, 0xb0, 0x78, 0x3c, 0x9a, 0xcf,
|
||||
0xcd, 0x88, 0x3a, 0x91, 0x34, 0x69, 0x29, 0x25 }
|
||||
},
|
||||
{ "abc",
|
||||
{ 0xaf, 0xbd, 0x6e, 0x22, 0x8b, 0x9d, 0x8c, 0xbb,
|
||||
0xce, 0xf5, 0xca, 0x2d, 0x03, 0xe6, 0xdb, 0xa1,
|
||||
0x0a, 0xc0, 0xbc, 0x7d, 0xcb, 0xe4, 0x68, 0x0e,
|
||||
0x1e, 0x42, 0xd2, 0xe9, 0x75, 0x45, 0x9b, 0x65 }
|
||||
},
|
||||
{ "message digest",
|
||||
{ 0x87, 0xe9, 0x71, 0x75, 0x9a, 0x1c, 0xe4, 0x7a,
|
||||
0x51, 0x4d, 0x5c, 0x91, 0x4c, 0x39, 0x2c, 0x90,
|
||||
0x18, 0xc7, 0xc4, 0x6b, 0xc1, 0x44, 0x65, 0x55,
|
||||
0x4a, 0xfc, 0xdf, 0x54, 0xa5, 0x07, 0x0c, 0x0e }
|
||||
},
|
||||
{ "abcdefghijklmnopqrstuvwxyz",
|
||||
{ 0x64, 0x9d, 0x30, 0x34, 0x75, 0x1e, 0xa2, 0x16,
|
||||
0x77, 0x6b, 0xf9, 0xa1, 0x8a, 0xcc, 0x81, 0xbc,
|
||||
0x78, 0x96, 0x11, 0x8a, 0x51, 0x97, 0x96, 0x87,
|
||||
0x82, 0xdd, 0x1f, 0xd9, 0x7d, 0x8d, 0x51, 0x33 }
|
||||
},
|
||||
{ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
|
||||
{ 0x57, 0x40, 0xa4, 0x08, 0xac, 0x16, 0xb7, 0x20,
|
||||
0xb8, 0x44, 0x24, 0xae, 0x93, 0x1c, 0xbb, 0x1f,
|
||||
0xe3, 0x63, 0xd1, 0xd0, 0xbf, 0x40, 0x17, 0xf1,
|
||||
0xa8, 0x9f, 0x7e, 0xa6, 0xde, 0x77, 0xa0, 0xb8 }
|
||||
}
|
||||
};
|
||||
int x;
|
||||
unsigned char buf[32];
|
||||
hash_state md;
|
||||
|
||||
for (x = 0; x < (int)(sizeof(tests)/sizeof(tests[0])); x++) {
|
||||
rmd256_init(&md);
|
||||
rmd256_process(&md, (unsigned char *)tests[x].msg, strlen(tests[x].msg));
|
||||
rmd256_done(&md, buf);
|
||||
if (XMEMCMP(buf, tests[x].md, 32) != 0) {
|
||||
#if 0
|
||||
printf("Failed test %d\n", x);
|
||||
#endif
|
||||
return CRYPT_FAIL_TESTVECTOR;
|
||||
}
|
||||
}
|
||||
return CRYPT_OK;
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
495
libtomcrypt/src/hashes/rmd320.c
Normal file
495
libtomcrypt/src/hashes/rmd320.c
Normal file
@@ -0,0 +1,495 @@
|
||||
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
|
||||
*
|
||||
* LibTomCrypt is a library that provides various cryptographic
|
||||
* algorithms in a highly modular and flexible manner.
|
||||
*
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
/**
|
||||
@file rmd320.c
|
||||
RMD320 hash function
|
||||
*/
|
||||
|
||||
#ifdef RIPEMD320
|
||||
|
||||
const struct ltc_hash_descriptor rmd320_desc =
|
||||
{
|
||||
"rmd320",
|
||||
9,
|
||||
20,
|
||||
64,
|
||||
|
||||
/* OID */
|
||||
{ 0 },
|
||||
0,
|
||||
|
||||
&rmd320_init,
|
||||
&rmd320_process,
|
||||
&rmd320_done,
|
||||
&rmd320_test,
|
||||
NULL
|
||||
};
|
||||
|
||||
/* the five basic functions F(), G() and H() */
|
||||
#define F(x, y, z) ((x) ^ (y) ^ (z))
|
||||
#define G(x, y, z) (((x) & (y)) | (~(x) & (z)))
|
||||
#define H(x, y, z) (((x) | ~(y)) ^ (z))
|
||||
#define I(x, y, z) (((x) & (z)) | ((y) & ~(z)))
|
||||
#define J(x, y, z) ((x) ^ ((y) | ~(z)))
|
||||
|
||||
/* the ten basic operations FF() through III() */
|
||||
#define FF(a, b, c, d, e, x, s) \
|
||||
(a) += F((b), (c), (d)) + (x);\
|
||||
(a) = ROLc((a), (s)) + (e);\
|
||||
(c) = ROLc((c), 10);
|
||||
|
||||
#define GG(a, b, c, d, e, x, s) \
|
||||
(a) += G((b), (c), (d)) + (x) + 0x5a827999UL;\
|
||||
(a) = ROLc((a), (s)) + (e);\
|
||||
(c) = ROLc((c), 10);
|
||||
|
||||
#define HH(a, b, c, d, e, x, s) \
|
||||
(a) += H((b), (c), (d)) + (x) + 0x6ed9eba1UL;\
|
||||
(a) = ROLc((a), (s)) + (e);\
|
||||
(c) = ROLc((c), 10);
|
||||
|
||||
#define II(a, b, c, d, e, x, s) \
|
||||
(a) += I((b), (c), (d)) + (x) + 0x8f1bbcdcUL;\
|
||||
(a) = ROLc((a), (s)) + (e);\
|
||||
(c) = ROLc((c), 10);
|
||||
|
||||
#define JJ(a, b, c, d, e, x, s) \
|
||||
(a) += J((b), (c), (d)) + (x) + 0xa953fd4eUL;\
|
||||
(a) = ROLc((a), (s)) + (e);\
|
||||
(c) = ROLc((c), 10);
|
||||
|
||||
#define FFF(a, b, c, d, e, x, s) \
|
||||
(a) += F((b), (c), (d)) + (x);\
|
||||
(a) = ROLc((a), (s)) + (e);\
|
||||
(c) = ROLc((c), 10);
|
||||
|
||||
#define GGG(a, b, c, d, e, x, s) \
|
||||
(a) += G((b), (c), (d)) + (x) + 0x7a6d76e9UL;\
|
||||
(a) = ROLc((a), (s)) + (e);\
|
||||
(c) = ROLc((c), 10);
|
||||
|
||||
#define HHH(a, b, c, d, e, x, s) \
|
||||
(a) += H((b), (c), (d)) + (x) + 0x6d703ef3UL;\
|
||||
(a) = ROLc((a), (s)) + (e);\
|
||||
(c) = ROLc((c), 10);
|
||||
|
||||
#define III(a, b, c, d, e, x, s) \
|
||||
(a) += I((b), (c), (d)) + (x) + 0x5c4dd124UL;\
|
||||
(a) = ROLc((a), (s)) + (e);\
|
||||
(c) = ROLc((c), 10);
|
||||
|
||||
#define JJJ(a, b, c, d, e, x, s) \
|
||||
(a) += J((b), (c), (d)) + (x) + 0x50a28be6UL;\
|
||||
(a) = ROLc((a), (s)) + (e);\
|
||||
(c) = ROLc((c), 10);
|
||||
|
||||
|
||||
#ifdef LTC_CLEAN_STACK
|
||||
static int _rmd320_compress(hash_state *md, unsigned char *buf)
|
||||
#else
|
||||
static int rmd320_compress(hash_state *md, unsigned char *buf)
|
||||
#endif
|
||||
{
|
||||
ulong32 aa,bb,cc,dd,ee,aaa,bbb,ccc,ddd,eee,tmp,X[16];
|
||||
int i;
|
||||
|
||||
/* load words X */
|
||||
for (i = 0; i < 16; i++){
|
||||
LOAD32L(X[i], buf + (4 * i));
|
||||
}
|
||||
|
||||
/* load state */
|
||||
aa = md->rmd320.state[0];
|
||||
bb = md->rmd320.state[1];
|
||||
cc = md->rmd320.state[2];
|
||||
dd = md->rmd320.state[3];
|
||||
ee = md->rmd320.state[4];
|
||||
aaa = md->rmd320.state[5];
|
||||
bbb = md->rmd320.state[6];
|
||||
ccc = md->rmd320.state[7];
|
||||
ddd = md->rmd320.state[8];
|
||||
eee = md->rmd320.state[9];
|
||||
|
||||
/* round 1 */
|
||||
FF(aa, bb, cc, dd, ee, X[ 0], 11);
|
||||
FF(ee, aa, bb, cc, dd, X[ 1], 14);
|
||||
FF(dd, ee, aa, bb, cc, X[ 2], 15);
|
||||
FF(cc, dd, ee, aa, bb, X[ 3], 12);
|
||||
FF(bb, cc, dd, ee, aa, X[ 4], 5);
|
||||
FF(aa, bb, cc, dd, ee, X[ 5], 8);
|
||||
FF(ee, aa, bb, cc, dd, X[ 6], 7);
|
||||
FF(dd, ee, aa, bb, cc, X[ 7], 9);
|
||||
FF(cc, dd, ee, aa, bb, X[ 8], 11);
|
||||
FF(bb, cc, dd, ee, aa, X[ 9], 13);
|
||||
FF(aa, bb, cc, dd, ee, X[10], 14);
|
||||
FF(ee, aa, bb, cc, dd, X[11], 15);
|
||||
FF(dd, ee, aa, bb, cc, X[12], 6);
|
||||
FF(cc, dd, ee, aa, bb, X[13], 7);
|
||||
FF(bb, cc, dd, ee, aa, X[14], 9);
|
||||
FF(aa, bb, cc, dd, ee, X[15], 8);
|
||||
|
||||
/* parallel round 1 */
|
||||
JJJ(aaa, bbb, ccc, ddd, eee, X[ 5], 8);
|
||||
JJJ(eee, aaa, bbb, ccc, ddd, X[14], 9);
|
||||
JJJ(ddd, eee, aaa, bbb, ccc, X[ 7], 9);
|
||||
JJJ(ccc, ddd, eee, aaa, bbb, X[ 0], 11);
|
||||
JJJ(bbb, ccc, ddd, eee, aaa, X[ 9], 13);
|
||||
JJJ(aaa, bbb, ccc, ddd, eee, X[ 2], 15);
|
||||
JJJ(eee, aaa, bbb, ccc, ddd, X[11], 15);
|
||||
JJJ(ddd, eee, aaa, bbb, ccc, X[ 4], 5);
|
||||
JJJ(ccc, ddd, eee, aaa, bbb, X[13], 7);
|
||||
JJJ(bbb, ccc, ddd, eee, aaa, X[ 6], 7);
|
||||
JJJ(aaa, bbb, ccc, ddd, eee, X[15], 8);
|
||||
JJJ(eee, aaa, bbb, ccc, ddd, X[ 8], 11);
|
||||
JJJ(ddd, eee, aaa, bbb, ccc, X[ 1], 14);
|
||||
JJJ(ccc, ddd, eee, aaa, bbb, X[10], 14);
|
||||
JJJ(bbb, ccc, ddd, eee, aaa, X[ 3], 12);
|
||||
JJJ(aaa, bbb, ccc, ddd, eee, X[12], 6);
|
||||
|
||||
tmp = aa; aa = aaa; aaa = tmp;
|
||||
|
||||
/* round 2 */
|
||||
GG(ee, aa, bb, cc, dd, X[ 7], 7);
|
||||
GG(dd, ee, aa, bb, cc, X[ 4], 6);
|
||||
GG(cc, dd, ee, aa, bb, X[13], 8);
|
||||
GG(bb, cc, dd, ee, aa, X[ 1], 13);
|
||||
GG(aa, bb, cc, dd, ee, X[10], 11);
|
||||
GG(ee, aa, bb, cc, dd, X[ 6], 9);
|
||||
GG(dd, ee, aa, bb, cc, X[15], 7);
|
||||
GG(cc, dd, ee, aa, bb, X[ 3], 15);
|
||||
GG(bb, cc, dd, ee, aa, X[12], 7);
|
||||
GG(aa, bb, cc, dd, ee, X[ 0], 12);
|
||||
GG(ee, aa, bb, cc, dd, X[ 9], 15);
|
||||
GG(dd, ee, aa, bb, cc, X[ 5], 9);
|
||||
GG(cc, dd, ee, aa, bb, X[ 2], 11);
|
||||
GG(bb, cc, dd, ee, aa, X[14], 7);
|
||||
GG(aa, bb, cc, dd, ee, X[11], 13);
|
||||
GG(ee, aa, bb, cc, dd, X[ 8], 12);
|
||||
|
||||
/* parallel round 2 */
|
||||
III(eee, aaa, bbb, ccc, ddd, X[ 6], 9);
|
||||
III(ddd, eee, aaa, bbb, ccc, X[11], 13);
|
||||
III(ccc, ddd, eee, aaa, bbb, X[ 3], 15);
|
||||
III(bbb, ccc, ddd, eee, aaa, X[ 7], 7);
|
||||
III(aaa, bbb, ccc, ddd, eee, X[ 0], 12);
|
||||
III(eee, aaa, bbb, ccc, ddd, X[13], 8);
|
||||
III(ddd, eee, aaa, bbb, ccc, X[ 5], 9);
|
||||
III(ccc, ddd, eee, aaa, bbb, X[10], 11);
|
||||
III(bbb, ccc, ddd, eee, aaa, X[14], 7);
|
||||
III(aaa, bbb, ccc, ddd, eee, X[15], 7);
|
||||
III(eee, aaa, bbb, ccc, ddd, X[ 8], 12);
|
||||
III(ddd, eee, aaa, bbb, ccc, X[12], 7);
|
||||
III(ccc, ddd, eee, aaa, bbb, X[ 4], 6);
|
||||
III(bbb, ccc, ddd, eee, aaa, X[ 9], 15);
|
||||
III(aaa, bbb, ccc, ddd, eee, X[ 1], 13);
|
||||
III(eee, aaa, bbb, ccc, ddd, X[ 2], 11);
|
||||
|
||||
tmp = bb; bb = bbb; bbb = tmp;
|
||||
|
||||
/* round 3 */
|
||||
HH(dd, ee, aa, bb, cc, X[ 3], 11);
|
||||
HH(cc, dd, ee, aa, bb, X[10], 13);
|
||||
HH(bb, cc, dd, ee, aa, X[14], 6);
|
||||
HH(aa, bb, cc, dd, ee, X[ 4], 7);
|
||||
HH(ee, aa, bb, cc, dd, X[ 9], 14);
|
||||
HH(dd, ee, aa, bb, cc, X[15], 9);
|
||||
HH(cc, dd, ee, aa, bb, X[ 8], 13);
|
||||
HH(bb, cc, dd, ee, aa, X[ 1], 15);
|
||||
HH(aa, bb, cc, dd, ee, X[ 2], 14);
|
||||
HH(ee, aa, bb, cc, dd, X[ 7], 8);
|
||||
HH(dd, ee, aa, bb, cc, X[ 0], 13);
|
||||
HH(cc, dd, ee, aa, bb, X[ 6], 6);
|
||||
HH(bb, cc, dd, ee, aa, X[13], 5);
|
||||
HH(aa, bb, cc, dd, ee, X[11], 12);
|
||||
HH(ee, aa, bb, cc, dd, X[ 5], 7);
|
||||
HH(dd, ee, aa, bb, cc, X[12], 5);
|
||||
|
||||
/* parallel round 3 */
|
||||
HHH(ddd, eee, aaa, bbb, ccc, X[15], 9);
|
||||
HHH(ccc, ddd, eee, aaa, bbb, X[ 5], 7);
|
||||
HHH(bbb, ccc, ddd, eee, aaa, X[ 1], 15);
|
||||
HHH(aaa, bbb, ccc, ddd, eee, X[ 3], 11);
|
||||
HHH(eee, aaa, bbb, ccc, ddd, X[ 7], 8);
|
||||
HHH(ddd, eee, aaa, bbb, ccc, X[14], 6);
|
||||
HHH(ccc, ddd, eee, aaa, bbb, X[ 6], 6);
|
||||
HHH(bbb, ccc, ddd, eee, aaa, X[ 9], 14);
|
||||
HHH(aaa, bbb, ccc, ddd, eee, X[11], 12);
|
||||
HHH(eee, aaa, bbb, ccc, ddd, X[ 8], 13);
|
||||
HHH(ddd, eee, aaa, bbb, ccc, X[12], 5);
|
||||
HHH(ccc, ddd, eee, aaa, bbb, X[ 2], 14);
|
||||
HHH(bbb, ccc, ddd, eee, aaa, X[10], 13);
|
||||
HHH(aaa, bbb, ccc, ddd, eee, X[ 0], 13);
|
||||
HHH(eee, aaa, bbb, ccc, ddd, X[ 4], 7);
|
||||
HHH(ddd, eee, aaa, bbb, ccc, X[13], 5);
|
||||
|
||||
tmp = cc; cc = ccc; ccc = tmp;
|
||||
|
||||
/* round 4 */
|
||||
II(cc, dd, ee, aa, bb, X[ 1], 11);
|
||||
II(bb, cc, dd, ee, aa, X[ 9], 12);
|
||||
II(aa, bb, cc, dd, ee, X[11], 14);
|
||||
II(ee, aa, bb, cc, dd, X[10], 15);
|
||||
II(dd, ee, aa, bb, cc, X[ 0], 14);
|
||||
II(cc, dd, ee, aa, bb, X[ 8], 15);
|
||||
II(bb, cc, dd, ee, aa, X[12], 9);
|
||||
II(aa, bb, cc, dd, ee, X[ 4], 8);
|
||||
II(ee, aa, bb, cc, dd, X[13], 9);
|
||||
II(dd, ee, aa, bb, cc, X[ 3], 14);
|
||||
II(cc, dd, ee, aa, bb, X[ 7], 5);
|
||||
II(bb, cc, dd, ee, aa, X[15], 6);
|
||||
II(aa, bb, cc, dd, ee, X[14], 8);
|
||||
II(ee, aa, bb, cc, dd, X[ 5], 6);
|
||||
II(dd, ee, aa, bb, cc, X[ 6], 5);
|
||||
II(cc, dd, ee, aa, bb, X[ 2], 12);
|
||||
|
||||
/* parallel round 4 */
|
||||
GGG(ccc, ddd, eee, aaa, bbb, X[ 8], 15);
|
||||
GGG(bbb, ccc, ddd, eee, aaa, X[ 6], 5);
|
||||
GGG(aaa, bbb, ccc, ddd, eee, X[ 4], 8);
|
||||
GGG(eee, aaa, bbb, ccc, ddd, X[ 1], 11);
|
||||
GGG(ddd, eee, aaa, bbb, ccc, X[ 3], 14);
|
||||
GGG(ccc, ddd, eee, aaa, bbb, X[11], 14);
|
||||
GGG(bbb, ccc, ddd, eee, aaa, X[15], 6);
|
||||
GGG(aaa, bbb, ccc, ddd, eee, X[ 0], 14);
|
||||
GGG(eee, aaa, bbb, ccc, ddd, X[ 5], 6);
|
||||
GGG(ddd, eee, aaa, bbb, ccc, X[12], 9);
|
||||
GGG(ccc, ddd, eee, aaa, bbb, X[ 2], 12);
|
||||
GGG(bbb, ccc, ddd, eee, aaa, X[13], 9);
|
||||
GGG(aaa, bbb, ccc, ddd, eee, X[ 9], 12);
|
||||
GGG(eee, aaa, bbb, ccc, ddd, X[ 7], 5);
|
||||
GGG(ddd, eee, aaa, bbb, ccc, X[10], 15);
|
||||
GGG(ccc, ddd, eee, aaa, bbb, X[14], 8);
|
||||
|
||||
tmp = dd; dd = ddd; ddd = tmp;
|
||||
|
||||
/* round 5 */
|
||||
JJ(bb, cc, dd, ee, aa, X[ 4], 9);
|
||||
JJ(aa, bb, cc, dd, ee, X[ 0], 15);
|
||||
JJ(ee, aa, bb, cc, dd, X[ 5], 5);
|
||||
JJ(dd, ee, aa, bb, cc, X[ 9], 11);
|
||||
JJ(cc, dd, ee, aa, bb, X[ 7], 6);
|
||||
JJ(bb, cc, dd, ee, aa, X[12], 8);
|
||||
JJ(aa, bb, cc, dd, ee, X[ 2], 13);
|
||||
JJ(ee, aa, bb, cc, dd, X[10], 12);
|
||||
JJ(dd, ee, aa, bb, cc, X[14], 5);
|
||||
JJ(cc, dd, ee, aa, bb, X[ 1], 12);
|
||||
JJ(bb, cc, dd, ee, aa, X[ 3], 13);
|
||||
JJ(aa, bb, cc, dd, ee, X[ 8], 14);
|
||||
JJ(ee, aa, bb, cc, dd, X[11], 11);
|
||||
JJ(dd, ee, aa, bb, cc, X[ 6], 8);
|
||||
JJ(cc, dd, ee, aa, bb, X[15], 5);
|
||||
JJ(bb, cc, dd, ee, aa, X[13], 6);
|
||||
|
||||
/* parallel round 5 */
|
||||
FFF(bbb, ccc, ddd, eee, aaa, X[12] , 8);
|
||||
FFF(aaa, bbb, ccc, ddd, eee, X[15] , 5);
|
||||
FFF(eee, aaa, bbb, ccc, ddd, X[10] , 12);
|
||||
FFF(ddd, eee, aaa, bbb, ccc, X[ 4] , 9);
|
||||
FFF(ccc, ddd, eee, aaa, bbb, X[ 1] , 12);
|
||||
FFF(bbb, ccc, ddd, eee, aaa, X[ 5] , 5);
|
||||
FFF(aaa, bbb, ccc, ddd, eee, X[ 8] , 14);
|
||||
FFF(eee, aaa, bbb, ccc, ddd, X[ 7] , 6);
|
||||
FFF(ddd, eee, aaa, bbb, ccc, X[ 6] , 8);
|
||||
FFF(ccc, ddd, eee, aaa, bbb, X[ 2] , 13);
|
||||
FFF(bbb, ccc, ddd, eee, aaa, X[13] , 6);
|
||||
FFF(aaa, bbb, ccc, ddd, eee, X[14] , 5);
|
||||
FFF(eee, aaa, bbb, ccc, ddd, X[ 0] , 15);
|
||||
FFF(ddd, eee, aaa, bbb, ccc, X[ 3] , 13);
|
||||
FFF(ccc, ddd, eee, aaa, bbb, X[ 9] , 11);
|
||||
FFF(bbb, ccc, ddd, eee, aaa, X[11] , 11);
|
||||
|
||||
tmp = ee; ee = eee; eee = tmp;
|
||||
|
||||
/* combine results */
|
||||
md->rmd320.state[0] += aa;
|
||||
md->rmd320.state[1] += bb;
|
||||
md->rmd320.state[2] += cc;
|
||||
md->rmd320.state[3] += dd;
|
||||
md->rmd320.state[4] += ee;
|
||||
md->rmd320.state[5] += aaa;
|
||||
md->rmd320.state[6] += bbb;
|
||||
md->rmd320.state[7] += ccc;
|
||||
md->rmd320.state[8] += ddd;
|
||||
md->rmd320.state[9] += eee;
|
||||
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
#ifdef LTC_CLEAN_STACK
|
||||
static int rmd320_compress(hash_state *md, unsigned char *buf)
|
||||
{
|
||||
int err;
|
||||
err = _rmd320_compress(md, buf);
|
||||
burn_stack(sizeof(ulong32) * 27 + sizeof(int));
|
||||
return err;
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
Initialize the hash state
|
||||
@param md The hash state you wish to initialize
|
||||
@return CRYPT_OK if successful
|
||||
*/
|
||||
int rmd320_init(hash_state * md)
|
||||
{
|
||||
LTC_ARGCHK(md != NULL);
|
||||
md->rmd320.state[0] = 0x67452301UL;
|
||||
md->rmd320.state[1] = 0xefcdab89UL;
|
||||
md->rmd320.state[2] = 0x98badcfeUL;
|
||||
md->rmd320.state[3] = 0x10325476UL;
|
||||
md->rmd320.state[4] = 0xc3d2e1f0UL;
|
||||
md->rmd320.state[5] = 0x76543210UL;
|
||||
md->rmd320.state[6] = 0xfedcba98UL;
|
||||
md->rmd320.state[7] = 0x89abcdefUL;
|
||||
md->rmd320.state[8] = 0x01234567UL;
|
||||
md->rmd320.state[9] = 0x3c2d1e0fUL;
|
||||
md->rmd320.curlen = 0;
|
||||
md->rmd320.length = 0;
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
Process a block of memory though the hash
|
||||
@param md The hash state
|
||||
@param in The data to hash
|
||||
@param inlen The length of the data (octets)
|
||||
@return CRYPT_OK if successful
|
||||
*/
|
||||
HASH_PROCESS(rmd320_process, rmd320_compress, rmd320, 64)
|
||||
|
||||
/**
|
||||
Terminate the hash to get the digest
|
||||
@param md The hash state
|
||||
@param out [out] The destination of the hash (20 bytes)
|
||||
@return CRYPT_OK if successful
|
||||
*/
|
||||
int rmd320_done(hash_state * md, unsigned char *out)
|
||||
{
|
||||
int i;
|
||||
|
||||
LTC_ARGCHK(md != NULL);
|
||||
LTC_ARGCHK(out != NULL);
|
||||
|
||||
if (md->rmd320.curlen >= sizeof(md->rmd320.buf)) {
|
||||
return CRYPT_INVALID_ARG;
|
||||
}
|
||||
|
||||
|
||||
/* increase the length of the message */
|
||||
md->rmd320.length += md->rmd320.curlen * 8;
|
||||
|
||||
/* append the '1' bit */
|
||||
md->rmd320.buf[md->rmd320.curlen++] = (unsigned char)0x80;
|
||||
|
||||
/* if the length is currently above 56 bytes we append zeros
|
||||
* then compress. Then we can fall back to padding zeros and length
|
||||
* encoding like normal.
|
||||
*/
|
||||
if (md->rmd320.curlen > 56) {
|
||||
while (md->rmd320.curlen < 64) {
|
||||
md->rmd320.buf[md->rmd320.curlen++] = (unsigned char)0;
|
||||
}
|
||||
rmd320_compress(md, md->rmd320.buf);
|
||||
md->rmd320.curlen = 0;
|
||||
}
|
||||
|
||||
/* pad upto 56 bytes of zeroes */
|
||||
while (md->rmd320.curlen < 56) {
|
||||
md->rmd320.buf[md->rmd320.curlen++] = (unsigned char)0;
|
||||
}
|
||||
|
||||
/* store length */
|
||||
STORE64L(md->rmd320.length, md->rmd320.buf+56);
|
||||
rmd320_compress(md, md->rmd320.buf);
|
||||
|
||||
/* copy output */
|
||||
for (i = 0; i < 10; i++) {
|
||||
STORE32L(md->rmd320.state[i], out+(4*i));
|
||||
}
|
||||
#ifdef LTC_CLEAN_STACK
|
||||
zeromem(md, sizeof(hash_state));
|
||||
#endif
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
Self-test the hash
|
||||
@return CRYPT_OK if successful, CRYPT_NOP if self-tests have been disabled
|
||||
*/
|
||||
int rmd320_test(void)
|
||||
{
|
||||
#ifndef LTC_TEST
|
||||
return CRYPT_NOP;
|
||||
#else
|
||||
static const struct {
|
||||
char *msg;
|
||||
unsigned char md[40];
|
||||
} tests[] = {
|
||||
{ "",
|
||||
{ 0x22, 0xd6, 0x5d, 0x56, 0x61, 0x53, 0x6c, 0xdc, 0x75, 0xc1,
|
||||
0xfd, 0xf5, 0xc6, 0xde, 0x7b, 0x41, 0xb9, 0xf2, 0x73, 0x25,
|
||||
0xeb, 0xc6, 0x1e, 0x85, 0x57, 0x17, 0x7d, 0x70, 0x5a, 0x0e,
|
||||
0xc8, 0x80, 0x15, 0x1c, 0x3a, 0x32, 0xa0, 0x08, 0x99, 0xb8 }
|
||||
},
|
||||
{ "a",
|
||||
{ 0xce, 0x78, 0x85, 0x06, 0x38, 0xf9, 0x26, 0x58, 0xa5, 0xa5,
|
||||
0x85, 0x09, 0x75, 0x79, 0x92, 0x6d, 0xda, 0x66, 0x7a, 0x57,
|
||||
0x16, 0x56, 0x2c, 0xfc, 0xf6, 0xfb, 0xe7, 0x7f, 0x63, 0x54,
|
||||
0x2f, 0x99, 0xb0, 0x47, 0x05, 0xd6, 0x97, 0x0d, 0xff, 0x5d }
|
||||
},
|
||||
{ "abc",
|
||||
{ 0xde, 0x4c, 0x01, 0xb3, 0x05, 0x4f, 0x89, 0x30, 0xa7, 0x9d,
|
||||
0x09, 0xae, 0x73, 0x8e, 0x92, 0x30, 0x1e, 0x5a, 0x17, 0x08,
|
||||
0x5b, 0xef, 0xfd, 0xc1, 0xb8, 0xd1, 0x16, 0x71, 0x3e, 0x74,
|
||||
0xf8, 0x2f, 0xa9, 0x42, 0xd6, 0x4c, 0xdb, 0xc4, 0x68, 0x2d }
|
||||
},
|
||||
{ "message digest",
|
||||
{ 0x3a, 0x8e, 0x28, 0x50, 0x2e, 0xd4, 0x5d, 0x42, 0x2f, 0x68,
|
||||
0x84, 0x4f, 0x9d, 0xd3, 0x16, 0xe7, 0xb9, 0x85, 0x33, 0xfa,
|
||||
0x3f, 0x2a, 0x91, 0xd2, 0x9f, 0x84, 0xd4, 0x25, 0xc8, 0x8d,
|
||||
0x6b, 0x4e, 0xff, 0x72, 0x7d, 0xf6, 0x6a, 0x7c, 0x01, 0x97 }
|
||||
},
|
||||
{ "abcdefghijklmnopqrstuvwxyz",
|
||||
{ 0xca, 0xbd, 0xb1, 0x81, 0x0b, 0x92, 0x47, 0x0a, 0x20, 0x93,
|
||||
0xaa, 0x6b, 0xce, 0x05, 0x95, 0x2c, 0x28, 0x34, 0x8c, 0xf4,
|
||||
0x3f, 0xf6, 0x08, 0x41, 0x97, 0x51, 0x66, 0xbb, 0x40, 0xed,
|
||||
0x23, 0x40, 0x04, 0xb8, 0x82, 0x44, 0x63, 0xe6, 0xb0, 0x09 }
|
||||
},
|
||||
{ "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
|
||||
{ 0xd0, 0x34, 0xa7, 0x95, 0x0c, 0xf7, 0x22, 0x02, 0x1b, 0xa4,
|
||||
0xb8, 0x4d, 0xf7, 0x69, 0xa5, 0xde, 0x20, 0x60, 0xe2, 0x59,
|
||||
0xdf, 0x4c, 0x9b, 0xb4, 0xa4, 0x26, 0x8c, 0x0e, 0x93, 0x5b,
|
||||
0xbc, 0x74, 0x70, 0xa9, 0x69, 0xc9, 0xd0, 0x72, 0xa1, 0xac }
|
||||
}
|
||||
};
|
||||
int x;
|
||||
unsigned char buf[40];
|
||||
hash_state md;
|
||||
|
||||
for (x = 0; x < (int)(sizeof(tests)/sizeof(tests[0])); x++) {
|
||||
rmd320_init(&md);
|
||||
rmd320_process(&md, (unsigned char *)tests[x].msg, strlen(tests[x].msg));
|
||||
rmd320_done(&md, buf);
|
||||
if (XMEMCMP(buf, tests[x].md, 40) != 0) {
|
||||
#if 0
|
||||
printf("Failed test %d\n", x);
|
||||
#endif
|
||||
return CRYPT_FAIL_TESTVECTOR;
|
||||
}
|
||||
}
|
||||
return CRYPT_OK;
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
@@ -32,7 +32,8 @@ const struct ltc_hash_descriptor sha1_desc =
|
||||
&sha1_init,
|
||||
&sha1_process,
|
||||
&sha1_done,
|
||||
&sha1_test
|
||||
&sha1_test,
|
||||
NULL
|
||||
};
|
||||
|
||||
#define F0(x,y,z) (z ^ (x & (y ^ z)))
|
||||
@@ -270,7 +271,7 @@ int sha1_test(void)
|
||||
sha1_init(&md);
|
||||
sha1_process(&md, (unsigned char*)tests[i].msg, (unsigned long)strlen(tests[i].msg));
|
||||
sha1_done(&md, tmp);
|
||||
if (memcmp(tmp, tests[i].hash, 20) != 0) {
|
||||
if (XMEMCMP(tmp, tests[i].hash, 20) != 0) {
|
||||
return CRYPT_FAIL_TESTVECTOR;
|
||||
}
|
||||
}
|
||||
@@ -283,5 +284,5 @@ int sha1_test(void)
|
||||
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/hashes/sha1.c,v $ */
|
||||
/* $Revision: 1.5 $ */
|
||||
/* $Date: 2005/05/23 02:42:07 $ */
|
||||
/* $Revision: 1.8 $ */
|
||||
/* $Date: 2006/11/01 09:28:17 $ */
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
*/
|
||||
/**
|
||||
@param sha224.c
|
||||
@@ -27,7 +27,8 @@ const struct ltc_hash_descriptor sha224_desc =
|
||||
&sha224_init,
|
||||
&sha256_process,
|
||||
&sha224_done,
|
||||
&sha224_test
|
||||
&sha224_test,
|
||||
NULL
|
||||
};
|
||||
|
||||
/* init the sha256 er... sha224 state ;-) */
|
||||
@@ -110,7 +111,7 @@ int sha224_test(void)
|
||||
sha224_init(&md);
|
||||
sha224_process(&md, (unsigned char*)tests[i].msg, (unsigned long)strlen(tests[i].msg));
|
||||
sha224_done(&md, tmp);
|
||||
if (memcmp(tmp, tests[i].hash, 28) != 0) {
|
||||
if (XMEMCMP(tmp, tests[i].hash, 28) != 0) {
|
||||
return CRYPT_FAIL_TESTVECTOR;
|
||||
}
|
||||
}
|
||||
@@ -120,5 +121,5 @@ int sha224_test(void)
|
||||
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/hashes/sha2/sha224.c,v $ */
|
||||
/* $Revision: 1.5 $ */
|
||||
/* $Date: 2005/05/23 02:42:07 $ */
|
||||
/* $Revision: 1.8 $ */
|
||||
/* $Date: 2006/11/01 09:28:17 $ */
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
@@ -31,12 +31,13 @@ const struct ltc_hash_descriptor sha256_desc =
|
||||
&sha256_init,
|
||||
&sha256_process,
|
||||
&sha256_done,
|
||||
&sha256_test
|
||||
&sha256_test,
|
||||
NULL
|
||||
};
|
||||
|
||||
#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,
|
||||
@@ -318,7 +319,7 @@ int sha256_test(void)
|
||||
sha256_init(&md);
|
||||
sha256_process(&md, (unsigned char*)tests[i].msg, (unsigned long)strlen(tests[i].msg));
|
||||
sha256_done(&md, tmp);
|
||||
if (memcmp(tmp, tests[i].hash, 32) != 0) {
|
||||
if (XMEMCMP(tmp, tests[i].hash, 32) != 0) {
|
||||
return CRYPT_FAIL_TESTVECTOR;
|
||||
}
|
||||
}
|
||||
@@ -335,5 +336,5 @@ int sha256_test(void)
|
||||
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/hashes/sha2/sha256.c,v $ */
|
||||
/* $Revision: 1.5 $ */
|
||||
/* $Date: 2005/05/23 02:42:07 $ */
|
||||
/* $Revision: 1.9 $ */
|
||||
/* $Date: 2006/11/01 09:28:17 $ */
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
*/
|
||||
/**
|
||||
@param sha384.c
|
||||
@@ -27,7 +27,8 @@ const struct ltc_hash_descriptor sha384_desc =
|
||||
&sha384_init,
|
||||
&sha512_process,
|
||||
&sha384_done,
|
||||
&sha384_test
|
||||
&sha384_test,
|
||||
NULL
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -116,7 +117,7 @@ int sha384_test(void)
|
||||
sha384_init(&md);
|
||||
sha384_process(&md, (unsigned char*)tests[i].msg, (unsigned long)strlen(tests[i].msg));
|
||||
sha384_done(&md, tmp);
|
||||
if (memcmp(tmp, tests[i].hash, 48) != 0) {
|
||||
if (XMEMCMP(tmp, tests[i].hash, 48) != 0) {
|
||||
return CRYPT_FAIL_TESTVECTOR;
|
||||
}
|
||||
}
|
||||
@@ -130,5 +131,5 @@ int sha384_test(void)
|
||||
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/hashes/sha2/sha384.c,v $ */
|
||||
/* $Revision: 1.5 $ */
|
||||
/* $Date: 2005/05/23 02:42:07 $ */
|
||||
/* $Revision: 1.8 $ */
|
||||
/* $Date: 2006/11/01 09:28:17 $ */
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
@@ -31,7 +31,8 @@ const struct ltc_hash_descriptor sha512_desc =
|
||||
&sha512_init,
|
||||
&sha512_process,
|
||||
&sha512_done,
|
||||
&sha512_test
|
||||
&sha512_test,
|
||||
NULL
|
||||
};
|
||||
|
||||
/* the K array */
|
||||
@@ -296,7 +297,7 @@ int sha512_test(void)
|
||||
sha512_init(&md);
|
||||
sha512_process(&md, (unsigned char *)tests[i].msg, (unsigned long)strlen(tests[i].msg));
|
||||
sha512_done(&md, tmp);
|
||||
if (memcmp(tmp, tests[i].hash, 64) != 0) {
|
||||
if (XMEMCMP(tmp, tests[i].hash, 64) != 0) {
|
||||
return CRYPT_FAIL_TESTVECTOR;
|
||||
}
|
||||
}
|
||||
@@ -314,5 +315,5 @@ int sha512_test(void)
|
||||
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/hashes/sha2/sha512.c,v $ */
|
||||
/* $Revision: 1.5 $ */
|
||||
/* $Date: 2005/05/23 02:42:07 $ */
|
||||
/* $Revision: 1.8 $ */
|
||||
/* $Date: 2006/11/01 09:28:17 $ */
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
*/
|
||||
|
||||
#include "tomcrypt.h"
|
||||
@@ -32,7 +32,8 @@ const struct ltc_hash_descriptor tiger_desc =
|
||||
&tiger_init,
|
||||
&tiger_process,
|
||||
&tiger_done,
|
||||
&tiger_test
|
||||
&tiger_test,
|
||||
NULL
|
||||
};
|
||||
|
||||
#define t1 (table)
|
||||
@@ -774,7 +775,7 @@ int tiger_test(void)
|
||||
tiger_init(&md);
|
||||
tiger_process(&md, (unsigned char *)tests[i].msg, (unsigned long)strlen(tests[i].msg));
|
||||
tiger_done(&md, tmp);
|
||||
if (memcmp(tmp, tests[i].hash, 24) != 0) {
|
||||
if (XMEMCMP(tmp, tests[i].hash, 24) != 0) {
|
||||
return CRYPT_FAIL_TESTVECTOR;
|
||||
}
|
||||
}
|
||||
@@ -809,5 +810,5 @@ Hash of "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-ABCDEFG
|
||||
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/hashes/tiger.c,v $ */
|
||||
/* $Revision: 1.5 $ */
|
||||
/* $Date: 2005/05/23 02:42:07 $ */
|
||||
/* $Revision: 1.8 $ */
|
||||
/* $Date: 2006/11/01 09:28:17 $ */
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -32,7 +32,8 @@ const struct ltc_hash_descriptor whirlpool_desc =
|
||||
&whirlpool_init,
|
||||
&whirlpool_process,
|
||||
&whirlpool_done,
|
||||
&whirlpool_test
|
||||
&whirlpool_test,
|
||||
NULL
|
||||
};
|
||||
|
||||
/* the sboxes */
|
||||
@@ -289,7 +290,7 @@ int whirlpool_test(void)
|
||||
whirlpool_init(&md);
|
||||
whirlpool_process(&md, (unsigned char *)tests[i].msg, tests[i].len);
|
||||
whirlpool_done(&md, tmp);
|
||||
if (memcmp(tmp, tests[i].hash, 64) != 0) {
|
||||
if (XMEMCMP(tmp, tests[i].hash, 64) != 0) {
|
||||
#if 0
|
||||
printf("\nFailed test %d\n", i);
|
||||
for (i = 0; i < 64; ) {
|
||||
@@ -309,5 +310,5 @@ int whirlpool_test(void)
|
||||
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/hashes/whirl/whirl.c,v $ */
|
||||
/* $Revision: 1.5 $ */
|
||||
/* $Date: 2005/05/23 02:42:07 $ */
|
||||
/* $Revision: 1.8 $ */
|
||||
/* $Date: 2006/11/01 09:28:17 $ */
|
||||
|
||||
@@ -1,581 +0,0 @@
|
||||
/* LibTomMath, multiple-precision integer library -- Tom St Denis
|
||||
*
|
||||
* LibTomMath is a library that provides multiple-precision
|
||||
* integer arithmetic as well as number theoretic functionality.
|
||||
*
|
||||
* The library was designed directly after the MPI library by
|
||||
* Michael Fromberger but has been written from scratch with
|
||||
* additional optimizations in place.
|
||||
*
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
|
||||
*/
|
||||
#ifndef BN_H_
|
||||
#define BN_H_
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <ctype.h>
|
||||
#include <limits.h>
|
||||
|
||||
#include <tommath_class.h>
|
||||
|
||||
#undef MIN
|
||||
#define MIN(x,y) ((x)<(y)?(x):(y))
|
||||
#undef MAX
|
||||
#define MAX(x,y) ((x)>(y)?(x):(y))
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
||||
/* C++ compilers don't like assigning void * to mp_digit * */
|
||||
#define OPT_CAST(x) (x *)
|
||||
|
||||
#else
|
||||
|
||||
/* C on the other hand doesn't care */
|
||||
#define OPT_CAST(x)
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/* detect 64-bit mode if possible */
|
||||
#if defined(__x86_64__)
|
||||
#if !(defined(MP_64BIT) && defined(MP_16BIT) && defined(MP_8BIT))
|
||||
#define MP_64BIT
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* some default configurations.
|
||||
*
|
||||
* A "mp_digit" must be able to hold DIGIT_BIT + 1 bits
|
||||
* A "mp_word" must be able to hold 2*DIGIT_BIT + 1 bits
|
||||
*
|
||||
* At the very least a mp_digit must be able to hold 7 bits
|
||||
* [any size beyond that is ok provided it doesn't overflow the data type]
|
||||
*/
|
||||
#ifdef MP_8BIT
|
||||
typedef unsigned char mp_digit;
|
||||
typedef unsigned short mp_word;
|
||||
#elif defined(MP_16BIT)
|
||||
typedef unsigned short mp_digit;
|
||||
typedef unsigned long mp_word;
|
||||
#elif defined(MP_64BIT)
|
||||
/* for GCC only on supported platforms */
|
||||
#ifndef CRYPT
|
||||
typedef unsigned long long ulong64;
|
||||
typedef signed long long long64;
|
||||
#endif
|
||||
|
||||
typedef unsigned long mp_digit;
|
||||
typedef unsigned long mp_word __attribute__ ((mode(TI)));
|
||||
|
||||
#define DIGIT_BIT 60
|
||||
#else
|
||||
/* this is the default case, 28-bit digits */
|
||||
|
||||
/* this is to make porting into LibTomCrypt easier :-) */
|
||||
#ifndef CRYPT
|
||||
#if defined(_MSC_VER) || defined(__BORLANDC__)
|
||||
typedef unsigned __int64 ulong64;
|
||||
typedef signed __int64 long64;
|
||||
#else
|
||||
typedef unsigned long long ulong64;
|
||||
typedef signed long long long64;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
typedef unsigned long mp_digit;
|
||||
typedef ulong64 mp_word;
|
||||
|
||||
#ifdef MP_31BIT
|
||||
/* this is an extension that uses 31-bit digits */
|
||||
#define DIGIT_BIT 31
|
||||
#else
|
||||
/* default case is 28-bit digits, defines MP_28BIT as a handy macro to test */
|
||||
#define DIGIT_BIT 28
|
||||
#define MP_28BIT
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* define heap macros */
|
||||
#ifndef CRYPT
|
||||
/* default to libc stuff */
|
||||
#ifndef XMALLOC
|
||||
#define XMALLOC malloc
|
||||
#define XFREE free
|
||||
#define XREALLOC realloc
|
||||
#define XCALLOC calloc
|
||||
#else
|
||||
/* prototypes for our heap functions */
|
||||
extern void *XMALLOC(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
|
||||
#endif
|
||||
|
||||
|
||||
/* otherwise the bits per digit is calculated automatically from the size of a mp_digit */
|
||||
#ifndef DIGIT_BIT
|
||||
#define DIGIT_BIT ((int)((CHAR_BIT * sizeof(mp_digit) - 1))) /* bits per digit */
|
||||
#endif
|
||||
|
||||
#define MP_DIGIT_BIT DIGIT_BIT
|
||||
#define MP_MASK ((((mp_digit)1)<<((mp_digit)DIGIT_BIT))-((mp_digit)1))
|
||||
#define MP_DIGIT_MAX MP_MASK
|
||||
|
||||
/* equalities */
|
||||
#define MP_LT -1 /* less than */
|
||||
#define MP_EQ 0 /* equal to */
|
||||
#define MP_GT 1 /* greater than */
|
||||
|
||||
#define MP_ZPOS 0 /* positive integer */
|
||||
#define MP_NEG 1 /* negative */
|
||||
|
||||
#define MP_OKAY 0 /* ok result */
|
||||
#define MP_MEM -2 /* out of mem */
|
||||
#define MP_VAL -3 /* invalid input */
|
||||
#define MP_RANGE MP_VAL
|
||||
|
||||
#define MP_YES 1 /* yes response */
|
||||
#define MP_NO 0 /* no response */
|
||||
|
||||
/* 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_ON 0x0008 /* force 2nd MSB to 1 */
|
||||
|
||||
typedef int mp_err;
|
||||
|
||||
/* you'll have to tune these... */
|
||||
extern int KARATSUBA_MUL_CUTOFF,
|
||||
KARATSUBA_SQR_CUTOFF,
|
||||
TOOM_MUL_CUTOFF,
|
||||
TOOM_SQR_CUTOFF;
|
||||
|
||||
/* define this to use lower memory usage routines (exptmods mostly) */
|
||||
/* #define MP_LOW_MEM */
|
||||
|
||||
/* default precision */
|
||||
#ifndef MP_PREC
|
||||
#ifndef MP_LOW_MEM
|
||||
#define MP_PREC 64 /* default digits of precision */
|
||||
#else
|
||||
#define MP_PREC 8 /* default digits of precision */
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* size of comba arrays, should be at least 2 * 2**(BITS_PER_WORD - BITS_PER_DIGIT*2) */
|
||||
#define MP_WARRAY (1 << (sizeof(mp_word) * CHAR_BIT - 2 * DIGIT_BIT + 1))
|
||||
|
||||
/* the infamous mp_int structure */
|
||||
typedef struct {
|
||||
int used, alloc, sign;
|
||||
mp_digit *dp;
|
||||
} mp_int;
|
||||
|
||||
/* callback for mp_prime_random, should fill dst with random bytes and return how many read [upto len] */
|
||||
typedef int ltm_prime_callback(unsigned char *dst, int len, void *dat);
|
||||
|
||||
|
||||
#define USED(m) ((m)->used)
|
||||
#define DIGIT(m,k) ((m)->dp[(k)])
|
||||
#define SIGN(m) ((m)->sign)
|
||||
|
||||
/* error code to char* string */
|
||||
char *mp_error_to_string(int code);
|
||||
|
||||
/* ---> init and deinit bignum functions <--- */
|
||||
/* init a bignum */
|
||||
int mp_init(mp_int *a);
|
||||
|
||||
/* free a bignum */
|
||||
void mp_clear(mp_int *a);
|
||||
|
||||
/* init a null terminated series of arguments */
|
||||
int mp_init_multi(mp_int *mp, ...);
|
||||
|
||||
/* clear a null terminated series of arguments */
|
||||
void mp_clear_multi(mp_int *mp, ...);
|
||||
|
||||
/* exchange two ints */
|
||||
void mp_exch(mp_int *a, mp_int *b);
|
||||
|
||||
/* shrink ram required for a bignum */
|
||||
int mp_shrink(mp_int *a);
|
||||
|
||||
/* grow an int to a given size */
|
||||
int mp_grow(mp_int *a, int size);
|
||||
|
||||
/* init to a given number of digits */
|
||||
int mp_init_size(mp_int *a, int size);
|
||||
|
||||
/* ---> Basic Manipulations <--- */
|
||||
#define mp_iszero(a) (((a)->used == 0) ? MP_YES : MP_NO)
|
||||
#define mp_iseven(a) (((a)->used > 0 && (((a)->dp[0] & 1) == 0)) ? MP_YES : MP_NO)
|
||||
#define mp_isodd(a) (((a)->used > 0 && (((a)->dp[0] & 1) == 1)) ? MP_YES : MP_NO)
|
||||
|
||||
/* set to zero */
|
||||
void mp_zero(mp_int *a);
|
||||
|
||||
/* set to a digit */
|
||||
void mp_set(mp_int *a, mp_digit b);
|
||||
|
||||
/* set a 32-bit const */
|
||||
int mp_set_int(mp_int *a, unsigned long b);
|
||||
|
||||
/* get a 32-bit value */
|
||||
unsigned long mp_get_int(mp_int * a);
|
||||
|
||||
/* initialize and set a digit */
|
||||
int mp_init_set (mp_int * a, mp_digit b);
|
||||
|
||||
/* initialize and set 32-bit value */
|
||||
int mp_init_set_int (mp_int * a, unsigned long b);
|
||||
|
||||
/* copy, b = a */
|
||||
int mp_copy(mp_int *a, mp_int *b);
|
||||
|
||||
/* inits and copies, a = b */
|
||||
int mp_init_copy(mp_int *a, mp_int *b);
|
||||
|
||||
/* trim unused digits */
|
||||
void mp_clamp(mp_int *a);
|
||||
|
||||
/* ---> digit manipulation <--- */
|
||||
|
||||
/* right shift by "b" digits */
|
||||
void mp_rshd(mp_int *a, int b);
|
||||
|
||||
/* left shift by "b" digits */
|
||||
int mp_lshd(mp_int *a, int b);
|
||||
|
||||
/* c = a / 2**b */
|
||||
int mp_div_2d(mp_int *a, int b, mp_int *c, mp_int *d);
|
||||
|
||||
/* b = a/2 */
|
||||
int mp_div_2(mp_int *a, mp_int *b);
|
||||
|
||||
/* c = a * 2**b */
|
||||
int mp_mul_2d(mp_int *a, int b, mp_int *c);
|
||||
|
||||
/* b = a*2 */
|
||||
int mp_mul_2(mp_int *a, mp_int *b);
|
||||
|
||||
/* c = a mod 2**d */
|
||||
int mp_mod_2d(mp_int *a, int b, mp_int *c);
|
||||
|
||||
/* computes a = 2**b */
|
||||
int mp_2expt(mp_int *a, int b);
|
||||
|
||||
/* Counts the number of lsbs which are zero before the first zero bit */
|
||||
int mp_cnt_lsb(mp_int *a);
|
||||
|
||||
/* I Love Earth! */
|
||||
|
||||
/* makes a pseudo-random int of a given size */
|
||||
int mp_rand(mp_int *a, int digits);
|
||||
|
||||
/* ---> binary operations <--- */
|
||||
/* c = a XOR b */
|
||||
int mp_xor(mp_int *a, mp_int *b, mp_int *c);
|
||||
|
||||
/* c = a OR b */
|
||||
int mp_or(mp_int *a, mp_int *b, mp_int *c);
|
||||
|
||||
/* c = a AND b */
|
||||
int mp_and(mp_int *a, mp_int *b, mp_int *c);
|
||||
|
||||
/* ---> Basic arithmetic <--- */
|
||||
|
||||
/* b = -a */
|
||||
int mp_neg(mp_int *a, mp_int *b);
|
||||
|
||||
/* b = |a| */
|
||||
int mp_abs(mp_int *a, mp_int *b);
|
||||
|
||||
/* compare a to b */
|
||||
int mp_cmp(mp_int *a, mp_int *b);
|
||||
|
||||
/* compare |a| to |b| */
|
||||
int mp_cmp_mag(mp_int *a, mp_int *b);
|
||||
|
||||
/* c = a + b */
|
||||
int mp_add(mp_int *a, mp_int *b, mp_int *c);
|
||||
|
||||
/* c = a - b */
|
||||
int mp_sub(mp_int *a, mp_int *b, mp_int *c);
|
||||
|
||||
/* c = a * b */
|
||||
int mp_mul(mp_int *a, mp_int *b, mp_int *c);
|
||||
|
||||
/* b = a*a */
|
||||
int mp_sqr(mp_int *a, mp_int *b);
|
||||
|
||||
/* a/b => cb + d == a */
|
||||
int mp_div(mp_int *a, mp_int *b, mp_int *c, mp_int *d);
|
||||
|
||||
/* c = a mod b, 0 <= c < b */
|
||||
int mp_mod(mp_int *a, mp_int *b, mp_int *c);
|
||||
|
||||
/* ---> single digit functions <--- */
|
||||
|
||||
/* compare against a single digit */
|
||||
int mp_cmp_d(mp_int *a, mp_digit b);
|
||||
|
||||
/* c = a + b */
|
||||
int mp_add_d(mp_int *a, mp_digit b, mp_int *c);
|
||||
|
||||
/* c = a - b */
|
||||
int mp_sub_d(mp_int *a, mp_digit b, mp_int *c);
|
||||
|
||||
/* c = a * b */
|
||||
int mp_mul_d(mp_int *a, mp_digit b, mp_int *c);
|
||||
|
||||
/* a/b => cb + d == a */
|
||||
int mp_div_d(mp_int *a, mp_digit b, mp_int *c, mp_digit *d);
|
||||
|
||||
/* a/3 => 3c + d == a */
|
||||
int mp_div_3(mp_int *a, mp_int *c, mp_digit *d);
|
||||
|
||||
/* c = a**b */
|
||||
int mp_expt_d(mp_int *a, mp_digit b, mp_int *c);
|
||||
|
||||
/* c = a mod b, 0 <= c < b */
|
||||
int mp_mod_d(mp_int *a, mp_digit b, mp_digit *c);
|
||||
|
||||
/* ---> number theory <--- */
|
||||
|
||||
/* d = a + b (mod c) */
|
||||
int mp_addmod(mp_int *a, mp_int *b, mp_int *c, mp_int *d);
|
||||
|
||||
/* d = a - b (mod c) */
|
||||
int mp_submod(mp_int *a, mp_int *b, mp_int *c, mp_int *d);
|
||||
|
||||
/* d = a * b (mod c) */
|
||||
int mp_mulmod(mp_int *a, mp_int *b, mp_int *c, mp_int *d);
|
||||
|
||||
/* c = a * a (mod b) */
|
||||
int mp_sqrmod(mp_int *a, mp_int *b, mp_int *c);
|
||||
|
||||
/* c = 1/a (mod b) */
|
||||
int mp_invmod(mp_int *a, mp_int *b, mp_int *c);
|
||||
|
||||
/* c = (a, b) */
|
||||
int mp_gcd(mp_int *a, mp_int *b, mp_int *c);
|
||||
|
||||
/* produces value such that U1*a + U2*b = U3 */
|
||||
int mp_exteuclid(mp_int *a, mp_int *b, mp_int *U1, mp_int *U2, mp_int *U3);
|
||||
|
||||
/* c = [a, b] or (a*b)/(a, b) */
|
||||
int mp_lcm(mp_int *a, mp_int *b, mp_int *c);
|
||||
|
||||
/* finds one of the b'th root of a, such that |c|**b <= |a|
|
||||
*
|
||||
* returns error if a < 0 and b is even
|
||||
*/
|
||||
int mp_n_root(mp_int *a, mp_digit b, mp_int *c);
|
||||
|
||||
/* special sqrt algo */
|
||||
int mp_sqrt(mp_int *arg, mp_int *ret);
|
||||
|
||||
/* is number a square? */
|
||||
int mp_is_square(mp_int *arg, int *ret);
|
||||
|
||||
/* computes the jacobi c = (a | n) (or Legendre if b is prime) */
|
||||
int mp_jacobi(mp_int *a, mp_int *n, int *c);
|
||||
|
||||
/* used to setup the Barrett reduction for a given modulus b */
|
||||
int mp_reduce_setup(mp_int *a, mp_int *b);
|
||||
|
||||
/* Barrett Reduction, computes a (mod b) with a precomputed value c
|
||||
*
|
||||
* Assumes that 0 < a <= b*b, note if 0 > a > -(b*b) then you can merely
|
||||
* compute the reduction as -1 * mp_reduce(mp_abs(a)) [pseudo code].
|
||||
*/
|
||||
int mp_reduce(mp_int *a, mp_int *b, mp_int *c);
|
||||
|
||||
/* setups the montgomery reduction */
|
||||
int mp_montgomery_setup(mp_int *a, mp_digit *mp);
|
||||
|
||||
/* computes a = B**n mod b without division or multiplication useful for
|
||||
* normalizing numbers in a Montgomery system.
|
||||
*/
|
||||
int mp_montgomery_calc_normalization(mp_int *a, mp_int *b);
|
||||
|
||||
/* computes x/R == x (mod N) via Montgomery Reduction */
|
||||
int mp_montgomery_reduce(mp_int *a, mp_int *m, mp_digit mp);
|
||||
|
||||
/* returns 1 if a is a valid DR modulus */
|
||||
int mp_dr_is_modulus(mp_int *a);
|
||||
|
||||
/* sets the value of "d" required for mp_dr_reduce */
|
||||
void mp_dr_setup(mp_int *a, mp_digit *d);
|
||||
|
||||
/* reduces a modulo b using the Diminished Radix method */
|
||||
int mp_dr_reduce(mp_int *a, mp_int *b, mp_digit mp);
|
||||
|
||||
/* returns true if a can be reduced with mp_reduce_2k */
|
||||
int mp_reduce_is_2k(mp_int *a);
|
||||
|
||||
/* determines k value for 2k reduction */
|
||||
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);
|
||||
|
||||
/* ---> Primes <--- */
|
||||
|
||||
/* number of primes */
|
||||
#ifdef MP_8BIT
|
||||
#define PRIME_SIZE 31
|
||||
#else
|
||||
#define PRIME_SIZE 256
|
||||
#endif
|
||||
|
||||
/* table of first PRIME_SIZE primes */
|
||||
extern const mp_digit ltm_prime_tab[];
|
||||
|
||||
/* result=1 if a is divisible by one of the first PRIME_SIZE primes */
|
||||
int mp_prime_is_divisible(mp_int *a, int *result);
|
||||
|
||||
/* performs one Fermat test of "a" using base "b".
|
||||
* Sets result to 0 if composite or 1 if probable prime
|
||||
*/
|
||||
int mp_prime_fermat(mp_int *a, mp_int *b, int *result);
|
||||
|
||||
/* performs one Miller-Rabin test of "a" using base "b".
|
||||
* Sets result to 0 if composite or 1 if probable prime
|
||||
*/
|
||||
int mp_prime_miller_rabin(mp_int *a, mp_int *b, int *result);
|
||||
|
||||
/* This gives [for a given bit size] the number of trials required
|
||||
* such that Miller-Rabin gives a prob of failure lower than 2^-96
|
||||
*/
|
||||
int mp_prime_rabin_miller_trials(int size);
|
||||
|
||||
/* performs t rounds of Miller-Rabin on "a" using the first
|
||||
* t prime bases. Also performs an initial sieve of trial
|
||||
* division. Determines if "a" is prime with probability
|
||||
* of error no more than (1/4)**t.
|
||||
*
|
||||
* Sets result to 1 if probably prime, 0 otherwise
|
||||
*/
|
||||
int mp_prime_is_prime(mp_int *a, int t, int *result);
|
||||
|
||||
/* finds the next prime after the number "a" using "t" trials
|
||||
* of Miller-Rabin.
|
||||
*
|
||||
* bbs_style = 1 means the prime must be congruent to 3 mod 4
|
||||
*/
|
||||
int mp_prime_next_prime(mp_int *a, int t, int bbs_style);
|
||||
|
||||
/* makes a truly random prime of a given size (bytes),
|
||||
* call with bbs = 1 if you want it to be congruent to 3 mod 4
|
||||
*
|
||||
* You have to supply a callback which fills in a buffer with random bytes. "dat" is a parameter you can
|
||||
* have passed to the callback (e.g. a state or something). This function doesn't use "dat" itself
|
||||
* so it can be NULL
|
||||
*
|
||||
* The prime generated will be larger than 2^(8*size).
|
||||
*/
|
||||
#define mp_prime_random(a, t, size, bbs, cb, dat) mp_prime_random_ex(a, t, ((size) * 8) + 1, (bbs==1)?LTM_PRIME_BBS:0, cb, dat)
|
||||
|
||||
/* makes a truly random prime of a given size (bits),
|
||||
*
|
||||
* Flags are as follows:
|
||||
*
|
||||
* LTM_PRIME_BBS - make prime congruent to 3 mod 4
|
||||
* LTM_PRIME_SAFE - make sure (p-1)/2 is prime as well (implies LTM_PRIME_BBS)
|
||||
* LTM_PRIME_2MSB_OFF - make the 2nd highest bit zero
|
||||
* LTM_PRIME_2MSB_ON - make the 2nd highest bit one
|
||||
*
|
||||
* You have to supply a callback which fills in a buffer with random bytes. "dat" is a parameter you can
|
||||
* have passed to the callback (e.g. a state or something). This function doesn't use "dat" itself
|
||||
* so it can be NULL
|
||||
*
|
||||
*/
|
||||
int mp_prime_random_ex(mp_int *a, int t, int size, int flags, ltm_prime_callback cb, void *dat);
|
||||
|
||||
/* ---> radix conversion <--- */
|
||||
int mp_count_bits(mp_int *a);
|
||||
|
||||
int mp_unsigned_bin_size(mp_int *a);
|
||||
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, 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, 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);
|
||||
|
||||
int mp_fread(mp_int *a, int radix, FILE *stream);
|
||||
int mp_fwrite(mp_int *a, int radix, FILE *stream);
|
||||
|
||||
#define mp_read_raw(mp, str, len) mp_read_signed_bin((mp), (str), (len))
|
||||
#define mp_raw_size(mp) mp_signed_bin_size(mp)
|
||||
#define mp_toraw(mp, str) mp_to_signed_bin((mp), (str))
|
||||
#define mp_read_mag(mp, str, len) mp_read_unsigned_bin((mp), (str), (len))
|
||||
#define mp_mag_size(mp) mp_unsigned_bin_size(mp)
|
||||
#define mp_tomag(mp, str) mp_to_unsigned_bin((mp), (str))
|
||||
|
||||
#define mp_tobinary(M, S) mp_toradix((M), (S), 2)
|
||||
#define mp_tooctal(M, S) mp_toradix((M), (S), 8)
|
||||
#define mp_todecimal(M, S) mp_toradix((M), (S), 10)
|
||||
#define mp_tohex(M, S) mp_toradix((M), (S), 16)
|
||||
|
||||
/* lowlevel functions, do not call! */
|
||||
int s_mp_add(mp_int *a, mp_int *b, mp_int *c);
|
||||
int s_mp_sub(mp_int *a, mp_int *b, mp_int *c);
|
||||
#define s_mp_mul(a, b, c) s_mp_mul_digs(a, b, c, (a)->used + (b)->used + 1)
|
||||
int fast_s_mp_mul_digs(mp_int *a, mp_int *b, mp_int *c, int digs);
|
||||
int s_mp_mul_digs(mp_int *a, mp_int *b, mp_int *c, int digs);
|
||||
int fast_s_mp_mul_high_digs(mp_int *a, mp_int *b, mp_int *c, int digs);
|
||||
int s_mp_mul_high_digs(mp_int *a, mp_int *b, mp_int *c, int digs);
|
||||
int fast_s_mp_sqr(mp_int *a, mp_int *b);
|
||||
int s_mp_sqr(mp_int *a, mp_int *b);
|
||||
int mp_karatsuba_mul(mp_int *a, mp_int *b, mp_int *c);
|
||||
int mp_toom_mul(mp_int *a, mp_int *b, mp_int *c);
|
||||
int mp_karatsuba_sqr(mp_int *a, mp_int *b);
|
||||
int mp_toom_sqr(mp_int *a, mp_int *b);
|
||||
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 mode);
|
||||
void bn_reverse(unsigned char *s, int len);
|
||||
|
||||
extern const char *mp_s_rmap;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/headers/ltc_tommath.h,v $ */
|
||||
/* $Revision: 1.4 $ */
|
||||
/* $Date: 2005/05/05 14:35:58 $ */
|
||||
@@ -16,8 +16,8 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
/* version */
|
||||
#define CRYPT 0x0105
|
||||
#define SCRYPT "1.05"
|
||||
#define CRYPT 0x0116
|
||||
#define SCRYPT "1.16"
|
||||
|
||||
/* max size of either a cipher/hash block or symmetric key [largest of the two] */
|
||||
#define MAXBLOCKSIZE 128
|
||||
@@ -60,7 +60,8 @@ enum {
|
||||
CRYPT_PK_NOT_FOUND, /* Key not found in keyring */
|
||||
CRYPT_PK_INVALID_SIZE, /* Invalid size input for PK parameters */
|
||||
|
||||
CRYPT_INVALID_PRIME_SIZE/* Invalid size of prime requested */
|
||||
CRYPT_INVALID_PRIME_SIZE,/* Invalid size of prime requested */
|
||||
CRYPT_PK_INVALID_PADDING /* Invalid padding on input */
|
||||
};
|
||||
|
||||
#include <tomcrypt_cfg.h>
|
||||
@@ -70,6 +71,7 @@ enum {
|
||||
#include <tomcrypt_mac.h>
|
||||
#include <tomcrypt_prng.h>
|
||||
#include <tomcrypt_pk.h>
|
||||
#include <tomcrypt_math.h>
|
||||
#include <tomcrypt_misc.h>
|
||||
#include <tomcrypt_argchk.h>
|
||||
#include <tomcrypt_pkcs.h>
|
||||
@@ -82,5 +84,5 @@ enum {
|
||||
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/headers/tomcrypt.h,v $ */
|
||||
/* $Revision: 1.7 $ */
|
||||
/* $Date: 2005/06/19 18:03:25 $ */
|
||||
/* $Revision: 1.20 $ */
|
||||
/* $Date: 2006/11/26 01:45:14 $ */
|
||||
|
||||
@@ -7,19 +7,32 @@
|
||||
/* this is the default LibTomCrypt macro */
|
||||
void crypt_argchk(char *v, char *s, int d);
|
||||
#define LTC_ARGCHK(x) if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); }
|
||||
#define LTC_ARGCHKVD(x) LTC_ARGCHK(x)
|
||||
|
||||
#elif ARGTYPE == 1
|
||||
|
||||
/* fatal type of error */
|
||||
#define LTC_ARGCHK(x) assert((x))
|
||||
#define LTC_ARGCHKVD(x) LTC_ARGCHK(x)
|
||||
|
||||
#elif ARGTYPE == 2
|
||||
|
||||
#define LTC_ARGCHK(x) if (!(x)) { fprintf(stderr, "\nwarning: ARGCHK failed at %s:%d\n", __FILE__, __LINE__); }
|
||||
#define LTC_ARGCHKVD(x) LTC_ARGCHK(x)
|
||||
|
||||
#elif ARGTYPE == 3
|
||||
|
||||
#define LTC_ARGCHK(x)
|
||||
#define LTC_ARGCHKVD(x) LTC_ARGCHK(x)
|
||||
|
||||
#elif ARGTYPE == 4
|
||||
|
||||
#define LTC_ARGCHK(x) if (!(x)) return CRYPT_INVALID_ARG;
|
||||
#define LTC_ARGCHKVD(x) if (!(x)) return;
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/headers/tomcrypt_argchk.h,v $ */
|
||||
/* $Revision: 1.2 $ */
|
||||
/* $Date: 2005/05/05 14:35:58 $ */
|
||||
/* $Revision: 1.5 $ */
|
||||
/* $Date: 2006/08/27 20:50:21 $ */
|
||||
|
||||
@@ -7,21 +7,46 @@
|
||||
#ifndef TOMCRYPT_CFG_H
|
||||
#define TOMCRYPT_CFG_H
|
||||
|
||||
#if defined(_WIN32) || defined(_MSC_VER)
|
||||
#define LTC_CALL __cdecl
|
||||
#else
|
||||
#ifndef LTC_CALL
|
||||
#define LTC_CALL
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef LTC_EXPORT
|
||||
#define LTC_EXPORT
|
||||
#endif
|
||||
|
||||
/* certain platforms use macros for these, making the prototypes broken */
|
||||
#ifndef LTC_NO_PROTOTYPES
|
||||
|
||||
/* you can change how memory allocation works ... */
|
||||
void *XMALLOC(size_t n);
|
||||
void *XREALLOC(void *p, size_t n);
|
||||
void *XCALLOC(size_t n, size_t s);
|
||||
void XFREE(void *p);
|
||||
LTC_EXPORT void * LTC_CALL XMALLOC(size_t n);
|
||||
LTC_EXPORT void * LTC_CALL XREALLOC(void *p, size_t n);
|
||||
LTC_EXPORT void * LTC_CALL XCALLOC(size_t n, size_t s);
|
||||
LTC_EXPORT void LTC_CALL XFREE(void *p);
|
||||
|
||||
LTC_EXPORT void LTC_CALL XQSORT(void *base, size_t nmemb, size_t size, int(*compar)(const void *, const void *));
|
||||
|
||||
|
||||
/* change the clock function too */
|
||||
clock_t XCLOCK(void);
|
||||
LTC_EXPORT clock_t LTC_CALL XCLOCK(void);
|
||||
|
||||
/* various other functions */
|
||||
void *XMEMCPY(void *dest, const void *src, size_t n);
|
||||
int XMEMCMP(const void *s1, const void *s2, size_t n);
|
||||
LTC_EXPORT void * LTC_CALL XMEMCPY(void *dest, const void *src, size_t n);
|
||||
LTC_EXPORT int LTC_CALL XMEMCMP(const void *s1, const void *s2, size_t n);
|
||||
LTC_EXPORT void * LTC_CALL XMEMSET(void *s, int c, size_t n);
|
||||
|
||||
/* type of argument checking, 0=default, 1=fatal and 2=none */
|
||||
#define ARGTYPE 0
|
||||
LTC_EXPORT int LTC_CALL XSTRCMP(const char *s1, const char *s2);
|
||||
|
||||
#endif
|
||||
|
||||
/* type of argument checking, 0=default, 1=fatal and 2=error+continue, 3=nothing */
|
||||
#ifndef ARGTYPE
|
||||
#define ARGTYPE 0
|
||||
#endif
|
||||
|
||||
/* Controls endianess and size of registers. Leave uncommented to get platform neutral [slower] code
|
||||
*
|
||||
@@ -31,7 +56,7 @@ int XMEMCMP(const void *s1, const void *s2, size_t n);
|
||||
*/
|
||||
|
||||
/* detect x86-32 machines somewhat */
|
||||
#if defined(INTEL_CC) || (defined(_MSC_VER) && defined(WIN32)) || (defined(__GNUC__) && (defined(__DJGPP__) || defined(__CYGWIN__) || defined(__MINGW32__) || defined(__i386__)))
|
||||
#if !defined(__STRICT_ANSI__) && (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
|
||||
@@ -45,13 +70,32 @@ int XMEMCMP(const void *s1, const void *s2, size_t n);
|
||||
#endif
|
||||
|
||||
/* detect amd64 */
|
||||
#if defined(__x86_64__)
|
||||
#if !defined(__STRICT_ANSI__) && defined(__x86_64__)
|
||||
#define ENDIAN_LITTLE
|
||||
#define ENDIAN_64BITWORD
|
||||
#define LTC_FAST
|
||||
#define LTC_FAST_TYPE unsigned long
|
||||
#endif
|
||||
|
||||
/* detect PPC32 */
|
||||
#if !defined(__STRICT_ANSI__) && defined(LTC_PPC32)
|
||||
#define ENDIAN_BIG
|
||||
#define ENDIAN_32BITWORD
|
||||
#define LTC_FAST
|
||||
#define LTC_FAST_TYPE unsigned long
|
||||
#endif
|
||||
|
||||
/* detect sparc and sparc64 */
|
||||
#if defined(__sparc__)
|
||||
#define ENDIAN_BIG
|
||||
#if defined(__arch64__)
|
||||
#define ENDIAN_64BITWORD
|
||||
#else
|
||||
#define ENDIAN_32BITWORD
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef LTC_NO_FAST
|
||||
#ifdef LTC_FAST
|
||||
#undef LTC_FAST
|
||||
@@ -77,36 +121,16 @@ int XMEMCMP(const void *s1, const void *s2, size_t n);
|
||||
/* #define ENDIAN_64BITWORD */
|
||||
|
||||
#if (defined(ENDIAN_BIG) || defined(ENDIAN_LITTLE)) && !(defined(ENDIAN_32BITWORD) || defined(ENDIAN_64BITWORD))
|
||||
#error You must specify a word size as well as endianess in mycrypt_cfg.h
|
||||
#error You must specify a word size as well as endianess in tomcrypt_cfg.h
|
||||
#endif
|
||||
|
||||
#if !(defined(ENDIAN_BIG) || defined(ENDIAN_LITTLE))
|
||||
#define ENDIAN_NEUTRAL
|
||||
#endif
|
||||
|
||||
/* packet code */
|
||||
#if defined(MRSA) || defined(MDH) || defined(MECC)
|
||||
#define PACKET
|
||||
|
||||
/* size of a packet header in bytes */
|
||||
#define PACKET_SIZE 4
|
||||
|
||||
/* Section tags */
|
||||
#define PACKET_SECT_RSA 0
|
||||
#define PACKET_SECT_DH 1
|
||||
#define PACKET_SECT_ECC 2
|
||||
#define PACKET_SECT_DSA 3
|
||||
|
||||
/* Subsection Tags for the first three sections */
|
||||
#define PACKET_SUB_KEY 0
|
||||
#define PACKET_SUB_ENCRYPTED 1
|
||||
#define PACKET_SUB_SIGNED 2
|
||||
#define PACKET_SUB_ENC_KEY 3
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/headers/tomcrypt_cfg.h,v $ */
|
||||
/* $Revision: 1.7 $ */
|
||||
/* $Date: 2005/05/05 14:35:58 $ */
|
||||
/* $Revision: 1.19 $ */
|
||||
/* $Date: 2006/12/04 02:19:48 $ */
|
||||
|
||||
@@ -37,6 +37,20 @@ struct rijndael_key {
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifdef KSEED
|
||||
struct kseed_key {
|
||||
ulong32 K[32], dK[32];
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifdef LTC_KASUMI
|
||||
struct kasumi_key {
|
||||
ulong32 KLi1[8], KLi2[8],
|
||||
KOi1[8], KOi2[8], KOi3[8],
|
||||
KIi1[8], KIi2[8], KIi3[8];
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifdef XTEA
|
||||
struct xtea_key {
|
||||
unsigned long A[32], B[32];
|
||||
@@ -164,10 +178,17 @@ typedef union Symmetric_key {
|
||||
#ifdef ANUBIS
|
||||
struct anubis_key anubis;
|
||||
#endif
|
||||
#ifdef KSEED
|
||||
struct kseed_key kseed;
|
||||
#endif
|
||||
#ifdef LTC_KASUMI
|
||||
struct kasumi_key kasumi;
|
||||
#endif
|
||||
void *data;
|
||||
} symmetric_key;
|
||||
|
||||
/* A block cipher ECB structure */
|
||||
#ifdef LTC_ECB_MODE
|
||||
/** A block cipher ECB structure */
|
||||
typedef struct {
|
||||
/** The index of the cipher chosen */
|
||||
int cipher,
|
||||
@@ -176,8 +197,10 @@ typedef struct {
|
||||
/** The scheduled key */
|
||||
symmetric_key key;
|
||||
} symmetric_ECB;
|
||||
#endif
|
||||
|
||||
/* A block cipher CFB structure */
|
||||
#ifdef LTC_CFB_MODE
|
||||
/** A block cipher CFB structure */
|
||||
typedef struct {
|
||||
/** The index of the cipher chosen */
|
||||
int cipher,
|
||||
@@ -192,8 +215,10 @@ typedef struct {
|
||||
/** The scheduled key */
|
||||
symmetric_key key;
|
||||
} symmetric_CFB;
|
||||
#endif
|
||||
|
||||
/* A block cipher OFB structure */
|
||||
#ifdef LTC_OFB_MODE
|
||||
/** A block cipher OFB structure */
|
||||
typedef struct {
|
||||
/** The index of the cipher chosen */
|
||||
int cipher,
|
||||
@@ -206,8 +231,10 @@ typedef struct {
|
||||
/** The scheduled key */
|
||||
symmetric_key key;
|
||||
} symmetric_OFB;
|
||||
#endif
|
||||
|
||||
/* A block cipher CBC structure */
|
||||
#ifdef LTC_CBC_MODE
|
||||
/** A block cipher CBC structure */
|
||||
typedef struct {
|
||||
/** The index of the cipher chosen */
|
||||
int cipher,
|
||||
@@ -218,8 +245,11 @@ typedef struct {
|
||||
/** The scheduled key */
|
||||
symmetric_key key;
|
||||
} symmetric_CBC;
|
||||
#endif
|
||||
|
||||
/* A block cipher CTR structure */
|
||||
|
||||
#ifdef LTC_CTR_MODE
|
||||
/** A block cipher CTR structure */
|
||||
typedef struct {
|
||||
/** The index of the cipher chosen */
|
||||
int cipher,
|
||||
@@ -236,8 +266,55 @@ typedef struct {
|
||||
/** The scheduled key */
|
||||
symmetric_key key;
|
||||
} symmetric_CTR;
|
||||
#endif
|
||||
|
||||
/* cipher descriptor table, last entry has "name == NULL" to mark the end of table */
|
||||
|
||||
#ifdef LTC_LRW_MODE
|
||||
/** A LRW structure */
|
||||
typedef struct {
|
||||
/** The index of the cipher chosen (must be a 128-bit block cipher) */
|
||||
int cipher;
|
||||
|
||||
/** The current IV */
|
||||
unsigned char IV[16],
|
||||
|
||||
/** the tweak key */
|
||||
tweak[16],
|
||||
|
||||
/** The current pad, it's the product of the first 15 bytes against the tweak key */
|
||||
pad[16];
|
||||
|
||||
/** The scheduled symmetric key */
|
||||
symmetric_key key;
|
||||
|
||||
#ifdef LRW_TABLES
|
||||
/** The pre-computed multiplication table */
|
||||
unsigned char PC[16][256][16];
|
||||
#endif
|
||||
} symmetric_LRW;
|
||||
#endif
|
||||
|
||||
#ifdef LTC_F8_MODE
|
||||
/** A block cipher F8 structure */
|
||||
typedef struct {
|
||||
/** The index of the cipher chosen */
|
||||
int cipher,
|
||||
/** The block size of the given cipher */
|
||||
blocklen,
|
||||
/** The padding offset */
|
||||
padlen;
|
||||
/** The current IV */
|
||||
unsigned char IV[MAXBLOCKSIZE],
|
||||
MIV[MAXBLOCKSIZE];
|
||||
/** Current block count */
|
||||
ulong32 blockcnt;
|
||||
/** The scheduled key */
|
||||
symmetric_key key;
|
||||
} symmetric_F8;
|
||||
#endif
|
||||
|
||||
|
||||
/** cipher descriptor table, last entry has "name == NULL" to mark the end of table */
|
||||
extern struct ltc_cipher_descriptor {
|
||||
/** name of cipher */
|
||||
char *name;
|
||||
@@ -263,14 +340,16 @@ extern struct ltc_cipher_descriptor {
|
||||
@param pt The plaintext
|
||||
@param ct [out] The ciphertext
|
||||
@param skey The scheduled key
|
||||
@return CRYPT_OK if successful
|
||||
*/
|
||||
void (*ecb_encrypt)(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);
|
||||
int (*ecb_encrypt)(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);
|
||||
/** Decrypt a block
|
||||
@param ct The ciphertext
|
||||
@param pt [out] The plaintext
|
||||
@param skey The scheduled key
|
||||
@return CRYPT_OK if successful
|
||||
*/
|
||||
void (*ecb_decrypt)(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);
|
||||
int (*ecb_decrypt)(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);
|
||||
/** Test the block cipher
|
||||
@return CRYPT_OK if successful, CRYPT_NOP if self-testing has been disabled
|
||||
*/
|
||||
@@ -293,16 +372,18 @@ extern struct ltc_cipher_descriptor {
|
||||
@param ct Ciphertext
|
||||
@param blocks The number of complete blocks to process
|
||||
@param skey The scheduled key context
|
||||
@return CRYPT_OK if successful
|
||||
*/
|
||||
void (*accel_ecb_encrypt)(const unsigned char *pt, unsigned char *ct, unsigned long blocks, symmetric_key *skey);
|
||||
int (*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
|
||||
@return CRYPT_OK if successful
|
||||
*/
|
||||
void (*accel_ecb_decrypt)(const unsigned char *ct, unsigned char *pt, unsigned long blocks, symmetric_key *skey);
|
||||
int (*accel_ecb_decrypt)(const unsigned char *ct, unsigned char *pt, unsigned long blocks, symmetric_key *skey);
|
||||
|
||||
/** Accelerated CBC encryption
|
||||
@param pt Plaintext
|
||||
@@ -310,8 +391,9 @@ extern struct ltc_cipher_descriptor {
|
||||
@param blocks The number of complete blocks to process
|
||||
@param IV The initial value (input/output)
|
||||
@param skey The scheduled key context
|
||||
@return CRYPT_OK if successful
|
||||
*/
|
||||
void (*accel_cbc_encrypt)(const unsigned char *pt, unsigned char *ct, unsigned long blocks, unsigned char *IV, symmetric_key *skey);
|
||||
int (*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
|
||||
@@ -319,8 +401,9 @@ extern struct ltc_cipher_descriptor {
|
||||
@param blocks The number of complete blocks to process
|
||||
@param IV The initial value (input/output)
|
||||
@param skey The scheduled key context
|
||||
@return CRYPT_OK if successful
|
||||
*/
|
||||
void (*accel_cbc_decrypt)(const unsigned char *ct, unsigned char *pt, unsigned long blocks, unsigned char *IV, symmetric_key *skey);
|
||||
int (*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
|
||||
@@ -329,12 +412,36 @@ extern struct ltc_cipher_descriptor {
|
||||
@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
|
||||
@return CRYPT_OK if successful
|
||||
*/
|
||||
void (*accel_ctr_encrypt)(const unsigned char *pt, unsigned char *ct, unsigned long blocks, unsigned char *IV, int mode, symmetric_key *skey);
|
||||
int (*accel_ctr_encrypt)(const unsigned char *pt, unsigned char *ct, unsigned long blocks, unsigned char *IV, int mode, symmetric_key *skey);
|
||||
|
||||
/** Accelerated LRW
|
||||
@param pt Plaintext
|
||||
@param ct Ciphertext
|
||||
@param blocks The number of complete blocks to process
|
||||
@param IV The initial value (input/output)
|
||||
@param tweak The LRW tweak
|
||||
@param skey The scheduled key context
|
||||
@return CRYPT_OK if successful
|
||||
*/
|
||||
int (*accel_lrw_encrypt)(const unsigned char *pt, unsigned char *ct, unsigned long blocks, unsigned char *IV, const unsigned char *tweak, symmetric_key *skey);
|
||||
|
||||
/** Accelerated LRW
|
||||
@param ct Ciphertext
|
||||
@param pt Plaintext
|
||||
@param blocks The number of complete blocks to process
|
||||
@param IV The initial value (input/output)
|
||||
@param tweak The LRW tweak
|
||||
@param skey The scheduled key context
|
||||
@return CRYPT_OK if successful
|
||||
*/
|
||||
int (*accel_lrw_decrypt)(const unsigned char *ct, unsigned char *pt, unsigned long blocks, unsigned char *IV, const unsigned char *tweak, 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 uskey A previously scheduled key [optional can be NULL]
|
||||
@param nonce The session nonce [use once]
|
||||
@param noncelen The length of the nonce
|
||||
@param header The header for the session
|
||||
@@ -347,8 +454,9 @@ extern struct ltc_cipher_descriptor {
|
||||
@param direction Encrypt or Decrypt direction (0 or 1)
|
||||
@return CRYPT_OK if successful
|
||||
*/
|
||||
void (*accel_ccm_memory)(
|
||||
int (*accel_ccm_memory)(
|
||||
const unsigned char *key, unsigned long keylen,
|
||||
symmetric_key *uskey,
|
||||
const unsigned char *nonce, unsigned long noncelen,
|
||||
const unsigned char *header, unsigned long headerlen,
|
||||
unsigned char *pt, unsigned long ptlen,
|
||||
@@ -357,20 +465,21 @@ extern struct ltc_cipher_descriptor {
|
||||
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)
|
||||
@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)
|
||||
@return CRYPT_OK on success
|
||||
*/
|
||||
void (*accel_gcm_memory)(
|
||||
int (*accel_gcm_memory)(
|
||||
const unsigned char *key, unsigned long keylen,
|
||||
const unsigned char *IV, unsigned long IVlen,
|
||||
const unsigned char *adata, unsigned long adatalen,
|
||||
@@ -378,12 +487,55 @@ extern struct ltc_cipher_descriptor {
|
||||
unsigned char *ct,
|
||||
unsigned char *tag, unsigned long *taglen,
|
||||
int direction);
|
||||
|
||||
/** Accelerated one shot OMAC
|
||||
@param key The secret key
|
||||
@param keylen The key length (octets)
|
||||
@param in The message
|
||||
@param inlen Length of message (octets)
|
||||
@param out [out] Destination for tag
|
||||
@param outlen [in/out] Initial and final size of out
|
||||
@return CRYPT_OK on success
|
||||
*/
|
||||
int (*omac_memory)(
|
||||
const unsigned char *key, unsigned long keylen,
|
||||
const unsigned char *in, unsigned long inlen,
|
||||
unsigned char *out, unsigned long *outlen);
|
||||
|
||||
/** Accelerated one shot XCBC
|
||||
@param key The secret key
|
||||
@param keylen The key length (octets)
|
||||
@param in The message
|
||||
@param inlen Length of message (octets)
|
||||
@param out [out] Destination for tag
|
||||
@param outlen [in/out] Initial and final size of out
|
||||
@return CRYPT_OK on success
|
||||
*/
|
||||
int (*xcbc_memory)(
|
||||
const unsigned char *key, unsigned long keylen,
|
||||
const unsigned char *in, unsigned long inlen,
|
||||
unsigned char *out, unsigned long *outlen);
|
||||
|
||||
/** Accelerated one shot F9
|
||||
@param key The secret key
|
||||
@param keylen The key length (octets)
|
||||
@param in The message
|
||||
@param inlen Length of message (octets)
|
||||
@param out [out] Destination for tag
|
||||
@param outlen [in/out] Initial and final size of out
|
||||
@return CRYPT_OK on success
|
||||
@remark Requires manual padding
|
||||
*/
|
||||
int (*f9_memory)(
|
||||
const unsigned char *key, unsigned long keylen,
|
||||
const unsigned char *in, unsigned long inlen,
|
||||
unsigned char *out, unsigned long *outlen);
|
||||
} cipher_descriptor[];
|
||||
|
||||
#ifdef BLOWFISH
|
||||
int blowfish_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
|
||||
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_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);
|
||||
int 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);
|
||||
@@ -392,8 +544,8 @@ extern const struct ltc_cipher_descriptor blowfish_desc;
|
||||
|
||||
#ifdef RC5
|
||||
int rc5_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
|
||||
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_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);
|
||||
int 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);
|
||||
@@ -402,8 +554,8 @@ extern const struct ltc_cipher_descriptor rc5_desc;
|
||||
|
||||
#ifdef RC6
|
||||
int rc6_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
|
||||
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_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);
|
||||
int 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);
|
||||
@@ -412,8 +564,8 @@ extern const struct ltc_cipher_descriptor rc6_desc;
|
||||
|
||||
#ifdef RC2
|
||||
int rc2_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
|
||||
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_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);
|
||||
int 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);
|
||||
@@ -422,8 +574,8 @@ extern const struct ltc_cipher_descriptor rc2_desc;
|
||||
|
||||
#ifdef SAFERP
|
||||
int saferp_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
|
||||
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_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);
|
||||
int 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);
|
||||
@@ -435,8 +587,8 @@ int safer_k64_setup(const unsigned char *key, int keylen, int num_rounds, symmet
|
||||
int safer_sk64_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
|
||||
int safer_k128_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
|
||||
int safer_sk128_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
|
||||
void safer_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *key);
|
||||
void safer_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *key);
|
||||
int safer_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *key);
|
||||
int safer_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *key);
|
||||
int safer_k64_test(void);
|
||||
int safer_sk64_test(void);
|
||||
int safer_sk128_test(void);
|
||||
@@ -461,13 +613,13 @@ extern const struct ltc_cipher_descriptor safer_k64_desc, safer_k128_desc, safer
|
||||
#define aes_enc_keysize rijndael_enc_keysize
|
||||
|
||||
int rijndael_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
|
||||
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_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);
|
||||
int 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);
|
||||
int 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;
|
||||
@@ -476,8 +628,8 @@ extern const struct ltc_cipher_descriptor rijndael_enc_desc, aes_enc_desc;
|
||||
|
||||
#ifdef XTEA
|
||||
int xtea_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
|
||||
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_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);
|
||||
int 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);
|
||||
@@ -486,8 +638,8 @@ extern const struct ltc_cipher_descriptor xtea_desc;
|
||||
|
||||
#ifdef TWOFISH
|
||||
int twofish_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
|
||||
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_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);
|
||||
int 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);
|
||||
@@ -496,14 +648,14 @@ extern const struct ltc_cipher_descriptor twofish_desc;
|
||||
|
||||
#ifdef DES
|
||||
int des_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
|
||||
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_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);
|
||||
int 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_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);
|
||||
int 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);
|
||||
@@ -512,8 +664,8 @@ extern const struct ltc_cipher_descriptor des_desc, des3_desc;
|
||||
|
||||
#ifdef CAST5
|
||||
int cast5_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
|
||||
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_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);
|
||||
int 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);
|
||||
@@ -522,8 +674,8 @@ extern const struct ltc_cipher_descriptor cast5_desc;
|
||||
|
||||
#ifdef NOEKEON
|
||||
int noekeon_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
|
||||
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_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);
|
||||
int 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);
|
||||
@@ -532,8 +684,8 @@ extern const struct ltc_cipher_descriptor noekeon_desc;
|
||||
|
||||
#ifdef SKIPJACK
|
||||
int skipjack_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
|
||||
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_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);
|
||||
int 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);
|
||||
@@ -542,8 +694,8 @@ extern const struct ltc_cipher_descriptor skipjack_desc;
|
||||
|
||||
#ifdef KHAZAD
|
||||
int khazad_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
|
||||
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_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);
|
||||
int 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);
|
||||
@@ -552,15 +704,35 @@ extern const struct ltc_cipher_descriptor khazad_desc;
|
||||
|
||||
#ifdef ANUBIS
|
||||
int anubis_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
|
||||
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_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);
|
||||
int 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
|
||||
|
||||
#ifdef ECB
|
||||
#ifdef KSEED
|
||||
int kseed_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
|
||||
int kseed_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);
|
||||
int kseed_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);
|
||||
int kseed_test(void);
|
||||
void kseed_done(symmetric_key *skey);
|
||||
int kseed_keysize(int *keysize);
|
||||
extern const struct ltc_cipher_descriptor kseed_desc;
|
||||
#endif
|
||||
|
||||
#ifdef LTC_KASUMI
|
||||
int kasumi_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
|
||||
int kasumi_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);
|
||||
int kasumi_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);
|
||||
int kasumi_test(void);
|
||||
void kasumi_done(symmetric_key *skey);
|
||||
int kasumi_keysize(int *keysize);
|
||||
extern const struct ltc_cipher_descriptor kasumi_desc;
|
||||
#endif
|
||||
|
||||
#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);
|
||||
@@ -568,7 +740,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);
|
||||
@@ -578,7 +750,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);
|
||||
@@ -588,7 +760,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);
|
||||
@@ -598,10 +770,11 @@ 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
|
||||
#define LTC_CTR_RFC3686 2
|
||||
|
||||
int ctr_start( int cipher,
|
||||
const unsigned char *IV,
|
||||
@@ -613,8 +786,45 @@ int ctr_decrypt(const unsigned char *ct, unsigned char *pt, unsigned long len, s
|
||||
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);
|
||||
int ctr_test(void);
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef LTC_LRW_MODE
|
||||
|
||||
#define LRW_ENCRYPT 0
|
||||
#define LRW_DECRYPT 1
|
||||
|
||||
int lrw_start( int cipher,
|
||||
const unsigned char *IV,
|
||||
const unsigned char *key, int keylen,
|
||||
const unsigned char *tweak,
|
||||
int num_rounds,
|
||||
symmetric_LRW *lrw);
|
||||
int lrw_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, symmetric_LRW *lrw);
|
||||
int lrw_decrypt(const unsigned char *ct, unsigned char *pt, unsigned long len, symmetric_LRW *lrw);
|
||||
int lrw_getiv(unsigned char *IV, unsigned long *len, symmetric_LRW *lrw);
|
||||
int lrw_setiv(const unsigned char *IV, unsigned long len, symmetric_LRW *lrw);
|
||||
int lrw_done(symmetric_LRW *lrw);
|
||||
int lrw_test(void);
|
||||
|
||||
/* don't call */
|
||||
int lrw_process(const unsigned char *pt, unsigned char *ct, unsigned long len, int mode, symmetric_LRW *lrw);
|
||||
#endif
|
||||
|
||||
#ifdef LTC_F8_MODE
|
||||
int f8_start( int cipher, const unsigned char *IV,
|
||||
const unsigned char *key, int keylen,
|
||||
const unsigned char *salt_key, int skeylen,
|
||||
int num_rounds, symmetric_F8 *f8);
|
||||
int f8_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, symmetric_F8 *f8);
|
||||
int f8_decrypt(const unsigned char *ct, unsigned char *pt, unsigned long len, symmetric_F8 *f8);
|
||||
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
|
||||
|
||||
|
||||
int find_cipher(const char *name);
|
||||
int find_cipher_any(const char *name, int blocklen, int keylen);
|
||||
int find_cipher_id(unsigned char ID);
|
||||
@@ -622,8 +832,8 @@ int register_cipher(const struct ltc_cipher_descriptor *cipher);
|
||||
int unregister_cipher(const struct ltc_cipher_descriptor *cipher);
|
||||
int cipher_is_valid(int idx);
|
||||
|
||||
LTC_MUTEX_PROTO(ltc_cipher_mutex);
|
||||
LTC_MUTEX_PROTO(ltc_cipher_mutex)
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/headers/tomcrypt_cipher.h,v $ */
|
||||
/* $Revision: 1.16 $ */
|
||||
/* $Date: 2005/06/19 18:00:28 $ */
|
||||
/* $Revision: 1.46 $ */
|
||||
/* $Date: 2006/11/13 23:09:38 $ */
|
||||
|
||||
@@ -5,21 +5,68 @@
|
||||
#include "options.h"
|
||||
|
||||
/* macros for various libc functions you can change for embedded targets */
|
||||
#ifndef XMALLOC
|
||||
#ifdef malloc
|
||||
#define LTC_NO_PROTOTYPES
|
||||
#endif
|
||||
#define XMALLOC malloc
|
||||
#endif
|
||||
#ifndef XREALLOC
|
||||
#ifdef realloc
|
||||
#define LTC_NO_PROTOTYPES
|
||||
#endif
|
||||
#define XREALLOC realloc
|
||||
#endif
|
||||
#ifndef XCALLOC
|
||||
#ifdef calloc
|
||||
#define LTC_NO_PROTOTYPES
|
||||
#endif
|
||||
#define XCALLOC calloc
|
||||
#endif
|
||||
#ifndef XFREE
|
||||
#ifdef free
|
||||
#define LTC_NO_PROTOTYPES
|
||||
#endif
|
||||
#define XFREE free
|
||||
#endif
|
||||
|
||||
#ifndef XMEMSET
|
||||
#ifdef memset
|
||||
#define LTC_NO_PROTOTYPES
|
||||
#endif
|
||||
#define XMEMSET memset
|
||||
#endif
|
||||
#ifndef XMEMCPY
|
||||
#ifdef memcpy
|
||||
#define LTC_NO_PROTOTYPES
|
||||
#endif
|
||||
#define XMEMCPY memcpy
|
||||
#endif
|
||||
#ifndef XMEMCMP
|
||||
#ifdef memcmp
|
||||
#define LTC_NO_PROTOTYPES
|
||||
#endif
|
||||
#define XMEMCMP memcmp
|
||||
#endif
|
||||
#ifndef XSTRCMP
|
||||
#ifdef strcmp
|
||||
#define LTC_NO_PROTOTYPES
|
||||
#endif
|
||||
#define XSTRCMP strcmp
|
||||
#endif
|
||||
|
||||
#ifndef XCLOCK
|
||||
#define XCLOCK clock
|
||||
#endif
|
||||
#ifndef XCLOCKS_PER_SEC
|
||||
#define XCLOCKS_PER_SEC CLOCKS_PER_SEC
|
||||
#endif
|
||||
|
||||
#define LTC_NO_PRNGS
|
||||
#define LTC_NO_PK
|
||||
#ifdef DROPBEAR_SMALL_CODE
|
||||
#define LTC_SMALL_CODE
|
||||
#endif
|
||||
|
||||
/* These spit out warnings etc */
|
||||
#define LTC_NO_ROLC
|
||||
|
||||
@@ -84,13 +131,23 @@
|
||||
/* default no functions */
|
||||
#define LTC_MUTEX_GLOBAL(x)
|
||||
#define LTC_MUTEX_PROTO(x)
|
||||
#define LTC_MUTEX_TYPE(x)
|
||||
#define LTC_MUTEX_INIT(x)
|
||||
#define LTC_MUTEX_LOCK(x)
|
||||
#define LTC_MUTEX_UNLOCK(x)
|
||||
#define FORTUNA_POOLS 0
|
||||
|
||||
#endif
|
||||
|
||||
/* Debuggers */
|
||||
|
||||
/* define this if you use Valgrind, note: it CHANGES the way SOBER-128 and RC4 work (see the code) */
|
||||
/* #define LTC_VALGRIND */
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/headers/tomcrypt_custom.h,v $ */
|
||||
/* $Revision: 1.17 $ */
|
||||
/* $Date: 2005/06/19 18:00:28 $ */
|
||||
/* $Revision: 1.66 $ */
|
||||
/* $Date: 2006/12/04 02:50:11 $ */
|
||||
|
||||
@@ -70,6 +70,22 @@ struct rmd160_state {
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifdef RIPEMD256
|
||||
struct rmd256_state {
|
||||
ulong64 length;
|
||||
unsigned char buf[64];
|
||||
ulong32 curlen, state[8];
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifdef RIPEMD320
|
||||
struct rmd320_state {
|
||||
ulong64 length;
|
||||
unsigned char buf[64];
|
||||
ulong32 curlen, state[10];
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifdef WHIRLPOOL
|
||||
struct whirlpool_state {
|
||||
ulong64 length, state[8];
|
||||
@@ -87,6 +103,7 @@ struct chc_state {
|
||||
#endif
|
||||
|
||||
typedef union Hash_state {
|
||||
char dummy[1];
|
||||
#ifdef CHC_HASH
|
||||
struct chc_state chc;
|
||||
#endif
|
||||
@@ -119,10 +136,17 @@ typedef union Hash_state {
|
||||
#endif
|
||||
#ifdef RIPEMD160
|
||||
struct rmd160_state rmd160;
|
||||
#endif
|
||||
#ifdef RIPEMD256
|
||||
struct rmd256_state rmd256;
|
||||
#endif
|
||||
#ifdef RIPEMD320
|
||||
struct rmd320_state rmd320;
|
||||
#endif
|
||||
void *data;
|
||||
} hash_state;
|
||||
|
||||
/** hash descriptor */
|
||||
extern struct ltc_hash_descriptor {
|
||||
/** name of hash */
|
||||
char *name;
|
||||
@@ -159,6 +183,12 @@ extern struct ltc_hash_descriptor {
|
||||
@return CRYPT_OK if successful, CRYPT_NOP if self-tests have been disabled
|
||||
*/
|
||||
int (*test)(void);
|
||||
|
||||
/* accelerated hmac callback: if you need to-do multiple packets just use the generic hmac_memory and provide a hash callback */
|
||||
int (*hmac_block)(const unsigned char *key, unsigned long keylen,
|
||||
const unsigned char *in, unsigned long inlen,
|
||||
unsigned char *out, unsigned long *outlen);
|
||||
|
||||
} hash_descriptor[];
|
||||
|
||||
#ifdef CHC_HASH
|
||||
@@ -272,14 +302,32 @@ int rmd160_test(void);
|
||||
extern const struct ltc_hash_descriptor rmd160_desc;
|
||||
#endif
|
||||
|
||||
#ifdef RIPEMD256
|
||||
int rmd256_init(hash_state * md);
|
||||
int rmd256_process(hash_state * md, const unsigned char *in, unsigned long inlen);
|
||||
int rmd256_done(hash_state * md, unsigned char *hash);
|
||||
int rmd256_test(void);
|
||||
extern const struct ltc_hash_descriptor rmd256_desc;
|
||||
#endif
|
||||
|
||||
#ifdef RIPEMD320
|
||||
int rmd320_init(hash_state * md);
|
||||
int rmd320_process(hash_state * md, const unsigned char *in, unsigned long inlen);
|
||||
int rmd320_done(hash_state * md, unsigned char *hash);
|
||||
int rmd320_test(void);
|
||||
extern const struct ltc_hash_descriptor rmd320_desc;
|
||||
#endif
|
||||
|
||||
|
||||
int find_hash(const char *name);
|
||||
int find_hash_id(unsigned char ID);
|
||||
int find_hash_oid(const unsigned long *ID, unsigned long IDlen);
|
||||
int find_hash_any(const char *name, int digestlen);
|
||||
int register_hash(const struct ltc_hash_descriptor *hash);
|
||||
int unregister_hash(const struct ltc_hash_descriptor *hash);
|
||||
int hash_is_valid(int idx);
|
||||
|
||||
LTC_MUTEX_PROTO(ltc_hash_mutex);
|
||||
LTC_MUTEX_PROTO(ltc_hash_mutex)
|
||||
|
||||
int hash_memory(int hash,
|
||||
const unsigned char *in, unsigned long inlen,
|
||||
@@ -327,5 +375,5 @@ int func_name (hash_state * md, const unsigned char *in, unsigned long inlen)
|
||||
}
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/headers/tomcrypt_hash.h,v $ */
|
||||
/* $Revision: 1.12 $ */
|
||||
/* $Date: 2005/06/19 18:00:28 $ */
|
||||
/* $Revision: 1.19 $ */
|
||||
/* $Date: 2006/11/05 01:36:43 $ */
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#ifdef HMAC
|
||||
#ifdef LTC_HMAC
|
||||
typedef struct Hmac_state {
|
||||
hash_state md;
|
||||
int hash;
|
||||
@@ -23,7 +23,7 @@ int hmac_file(int hash, const char *fname, const unsigned char *key,
|
||||
unsigned char *dst, unsigned long *dstlen);
|
||||
#endif
|
||||
|
||||
#ifdef OMAC
|
||||
#ifdef LTC_OMAC
|
||||
|
||||
typedef struct {
|
||||
int cipher_idx,
|
||||
@@ -53,7 +53,7 @@ int omac_file(int cipher,
|
||||
int omac_test(void);
|
||||
#endif /* OMAC */
|
||||
|
||||
#ifdef PMAC
|
||||
#ifdef LTC_PMAC
|
||||
|
||||
typedef struct {
|
||||
unsigned char Ls[32][MAXBLOCKSIZE], /* L shifted by i bits to the left */
|
||||
@@ -98,7 +98,7 @@ void pmac_shift_xor(pmac_state *pmac);
|
||||
|
||||
#ifdef EAX_MODE
|
||||
|
||||
#if !(defined(OMAC) && defined(CTR))
|
||||
#if !(defined(LTC_OMAC) && defined(LTC_CTR_MODE))
|
||||
#error EAX_MODE requires OMAC and CTR
|
||||
#endif
|
||||
|
||||
@@ -200,6 +200,7 @@ int s_ocb_done(ocb_state *ocb, const unsigned char *pt, unsigned long ptlen,
|
||||
|
||||
int ccm_memory(int cipher,
|
||||
const unsigned char *key, unsigned long keylen,
|
||||
symmetric_key *uskey,
|
||||
const unsigned char *nonce, unsigned long noncelen,
|
||||
const unsigned char *header, unsigned long headerlen,
|
||||
unsigned char *pt, unsigned long ptlen,
|
||||
@@ -211,6 +212,16 @@ int ccm_test(void);
|
||||
|
||||
#endif /* CCM_MODE */
|
||||
|
||||
#if defined(LRW_MODE) || defined(GCM_MODE)
|
||||
void gcm_gf_mult(const unsigned char *a, const unsigned char *b, unsigned char *c);
|
||||
#endif
|
||||
|
||||
|
||||
/* table shared between GCM and LRW */
|
||||
#if defined(GCM_TABLES) || defined(LRW_TABLES) || ((defined(GCM_MODE) || defined(GCM_MODE)) && defined(LTC_FAST))
|
||||
extern const unsigned char gcm_shift_table[];
|
||||
#endif
|
||||
|
||||
#ifdef GCM_MODE
|
||||
|
||||
#define GCM_ENCRYPT 0
|
||||
@@ -237,12 +248,14 @@ 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_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,
|
||||
@@ -296,6 +309,73 @@ int pelican_memory(const unsigned char *key, unsigned long keylen,
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef LTC_XCBC
|
||||
|
||||
typedef struct {
|
||||
unsigned char K[3][MAXBLOCKSIZE],
|
||||
IV[MAXBLOCKSIZE];
|
||||
|
||||
symmetric_key key;
|
||||
|
||||
int cipher,
|
||||
buflen,
|
||||
blocksize;
|
||||
} xcbc_state;
|
||||
|
||||
int xcbc_init(xcbc_state *xcbc, int cipher, const unsigned char *key, unsigned long keylen);
|
||||
int xcbc_process(xcbc_state *xcbc, const unsigned char *in, unsigned long inlen);
|
||||
int xcbc_done(xcbc_state *xcbc, unsigned char *out, unsigned long *outlen);
|
||||
int xcbc_memory(int cipher,
|
||||
const unsigned char *key, unsigned long keylen,
|
||||
const unsigned char *in, unsigned long inlen,
|
||||
unsigned char *out, unsigned long *outlen);
|
||||
int xcbc_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 xcbc_file(int cipher,
|
||||
const unsigned char *key, unsigned long keylen,
|
||||
const char *filename,
|
||||
unsigned char *out, unsigned long *outlen);
|
||||
int xcbc_test(void);
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef LTC_F9_MODE
|
||||
|
||||
typedef struct {
|
||||
unsigned char akey[MAXBLOCKSIZE],
|
||||
ACC[MAXBLOCKSIZE],
|
||||
IV[MAXBLOCKSIZE];
|
||||
|
||||
symmetric_key key;
|
||||
|
||||
int cipher,
|
||||
buflen,
|
||||
keylen,
|
||||
blocksize;
|
||||
} f9_state;
|
||||
|
||||
int f9_init(f9_state *f9, int cipher, const unsigned char *key, unsigned long keylen);
|
||||
int f9_process(f9_state *f9, const unsigned char *in, unsigned long inlen);
|
||||
int f9_done(f9_state *f9, unsigned char *out, unsigned long *outlen);
|
||||
int f9_memory(int cipher,
|
||||
const unsigned char *key, unsigned long keylen,
|
||||
const unsigned char *in, unsigned long inlen,
|
||||
unsigned char *out, unsigned long *outlen);
|
||||
int f9_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 f9_file(int cipher,
|
||||
const unsigned char *key, unsigned long keylen,
|
||||
const char *filename,
|
||||
unsigned char *out, unsigned long *outlen);
|
||||
int f9_test(void);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/headers/tomcrypt_mac.h,v $ */
|
||||
/* $Revision: 1.7 $ */
|
||||
/* $Date: 2005/05/05 14:35:58 $ */
|
||||
/* $Revision: 1.20 $ */
|
||||
/* $Date: 2006/11/08 21:57:04 $ */
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
/* this is the "32-bit at least" data type
|
||||
* Re-define it to suit your platform but it must be at least 32-bits
|
||||
*/
|
||||
#if defined(__x86_64__)
|
||||
#if defined(__x86_64__) || (defined(__sparc__) && defined(__arch64__))
|
||||
typedef unsigned ulong32;
|
||||
#else
|
||||
typedef unsigned long ulong32;
|
||||
@@ -72,15 +72,15 @@
|
||||
#define STORE32H(x, y) \
|
||||
asm __volatile__ ( \
|
||||
"bswapl %0 \n\t" \
|
||||
"movl %0,(%2)\n\t" \
|
||||
"movl %0,(%1)\n\t" \
|
||||
"bswapl %0 \n\t" \
|
||||
:"=r"(x):"0"(x), "r"(y));
|
||||
::"r"(x), "r"(y));
|
||||
|
||||
#define LOAD32H(x, y) \
|
||||
asm __volatile__ ( \
|
||||
"movl (%2),%0\n\t" \
|
||||
"movl (%1),%0\n\t" \
|
||||
"bswapl %0\n\t" \
|
||||
:"=r"(x): "0"(x), "r"(y));
|
||||
:"=r"(x): "r"(y));
|
||||
|
||||
#else
|
||||
|
||||
@@ -103,15 +103,15 @@ asm __volatile__ ( \
|
||||
#define STORE64H(x, y) \
|
||||
asm __volatile__ ( \
|
||||
"bswapq %0 \n\t" \
|
||||
"movq %0,(%2)\n\t" \
|
||||
"movq %0,(%1)\n\t" \
|
||||
"bswapq %0 \n\t" \
|
||||
:"=r"(x):"0"(x), "r"(y):"0");
|
||||
::"r"(x), "r"(y));
|
||||
|
||||
#define LOAD64H(x, y) \
|
||||
asm __volatile__ ( \
|
||||
"movq (%2),%0\n\t" \
|
||||
"movq (%1),%0\n\t" \
|
||||
"bswapq %0\n\t" \
|
||||
:"=r"(x): "0"(x), "r"(y));
|
||||
:"=r"(x): "r"(y));
|
||||
|
||||
#else
|
||||
|
||||
@@ -132,10 +132,10 @@ asm __volatile__ ( \
|
||||
#ifdef ENDIAN_32BITWORD
|
||||
|
||||
#define STORE32L(x, y) \
|
||||
{ ulong32 __t = (x); memcpy(y, &__t, 4); }
|
||||
{ ulong32 __t = (x); XMEMCPY(y, &__t, 4); }
|
||||
|
||||
#define LOAD32L(x, y) \
|
||||
memcpy(&(x), y, 4);
|
||||
XMEMCPY(&(x), y, 4);
|
||||
|
||||
#define STORE64L(x, y) \
|
||||
{ (y)[7] = (unsigned char)(((x)>>56)&255); (y)[6] = (unsigned char)(((x)>>48)&255); \
|
||||
@@ -152,16 +152,16 @@ asm __volatile__ ( \
|
||||
#else /* 64-bit words then */
|
||||
|
||||
#define STORE32L(x, y) \
|
||||
{ ulong32 __t = (x); memcpy(y, &__t, 4); }
|
||||
{ ulong32 __t = (x); XMEMCPY(y, &__t, 4); }
|
||||
|
||||
#define LOAD32L(x, y) \
|
||||
{ memcpy(&(x), y, 4); x &= 0xFFFFFFFF; }
|
||||
{ XMEMCPY(&(x), y, 4); x &= 0xFFFFFFFF; }
|
||||
|
||||
#define STORE64L(x, y) \
|
||||
{ ulong64 __t = (x); memcpy(y, &__t, 8); }
|
||||
{ ulong64 __t = (x); XMEMCPY(y, &__t, 8); }
|
||||
|
||||
#define LOAD64L(x, y) \
|
||||
{ memcpy(&(x), y, 8); }
|
||||
{ XMEMCPY(&(x), y, 8); }
|
||||
|
||||
#endif /* ENDIAN_64BITWORD */
|
||||
|
||||
@@ -193,10 +193,10 @@ asm __volatile__ ( \
|
||||
#ifdef ENDIAN_32BITWORD
|
||||
|
||||
#define STORE32H(x, y) \
|
||||
{ ulong32 __t = (x); memcpy(y, &__t, 4); }
|
||||
{ ulong32 __t = (x); XMEMCPY(y, &__t, 4); }
|
||||
|
||||
#define LOAD32H(x, y) \
|
||||
memcpy(&(x), y, 4);
|
||||
XMEMCPY(&(x), y, 4);
|
||||
|
||||
#define STORE64H(x, y) \
|
||||
{ (y)[0] = (unsigned char)(((x)>>56)&255); (y)[1] = (unsigned char)(((x)>>48)&255); \
|
||||
@@ -213,16 +213,16 @@ asm __volatile__ ( \
|
||||
#else /* 64-bit words then */
|
||||
|
||||
#define STORE32H(x, y) \
|
||||
{ ulong32 __t = (x); memcpy(y, &__t, 4); }
|
||||
{ ulong32 __t = (x); XMEMCPY(y, &__t, 4); }
|
||||
|
||||
#define LOAD32H(x, y) \
|
||||
{ memcpy(&(x), y, 4); x &= 0xFFFFFFFF; }
|
||||
{ XMEMCPY(&(x), y, 4); x &= 0xFFFFFFFF; }
|
||||
|
||||
#define STORE64H(x, y) \
|
||||
{ ulong64 __t = (x); memcpy(y, &__t, 8); }
|
||||
{ ulong64 __t = (x); XMEMCPY(y, &__t, 8); }
|
||||
|
||||
#define LOAD64H(x, y) \
|
||||
{ memcpy(&(x), y, 8); }
|
||||
{ XMEMCPY(&(x), y, 8); }
|
||||
|
||||
#endif /* ENDIAN_64BITWORD */
|
||||
#endif /* ENDIAN_BIG */
|
||||
@@ -242,7 +242,7 @@ asm __volatile__ ( \
|
||||
#define RORc(x,n) _lrotr(x,n)
|
||||
#define ROLc(x,n) _lrotl(x,n)
|
||||
|
||||
#elif defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__)) && !defined(INTEL_CC) && !defined(LTC_NO_ASM)
|
||||
#elif !defined(__STRICT_ANSI__) && defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__)) && !defined(INTEL_CC) && !defined(LTC_NO_ASM)
|
||||
|
||||
static inline unsigned ROL(unsigned word, int i)
|
||||
{
|
||||
@@ -285,6 +285,50 @@ static inline unsigned RORc(unsigned word, const int i)
|
||||
|
||||
#endif
|
||||
|
||||
#elif !defined(__STRICT_ANSI__) && defined(LTC_PPC32)
|
||||
|
||||
static inline unsigned ROL(unsigned word, int i)
|
||||
{
|
||||
asm ("rotlw %0,%0,%2"
|
||||
:"=r" (word)
|
||||
:"0" (word),"r" (i));
|
||||
return word;
|
||||
}
|
||||
|
||||
static inline unsigned ROR(unsigned word, int i)
|
||||
{
|
||||
asm ("rotlw %0,%0,%2"
|
||||
:"=r" (word)
|
||||
:"0" (word),"r" (32-i));
|
||||
return word;
|
||||
}
|
||||
|
||||
#ifndef LTC_NO_ROLC
|
||||
|
||||
static inline unsigned ROLc(unsigned word, const int i)
|
||||
{
|
||||
asm ("rotlwi %0,%0,%2"
|
||||
:"=r" (word)
|
||||
:"0" (word),"I" (i));
|
||||
return word;
|
||||
}
|
||||
|
||||
static inline unsigned RORc(unsigned word, const int i)
|
||||
{
|
||||
asm ("rotrwi %0,%0,%2"
|
||||
:"=r" (word)
|
||||
:"0" (word),"I" (i));
|
||||
return word;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
#define ROLc ROL
|
||||
#define RORc ROR
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#else
|
||||
|
||||
/* rotates the hard way */
|
||||
@@ -297,7 +341,7 @@ static inline unsigned RORc(unsigned word, const int i)
|
||||
|
||||
|
||||
/* 64-bit Rotates */
|
||||
#if defined(__GNUC__) && defined(__x86_64__) && !defined(LTC_NO_ASM)
|
||||
#if !defined(__STRICT_ANSI__) && defined(__GNUC__) && defined(__x86_64__) && !defined(LTC_NO_ASM)
|
||||
|
||||
static inline unsigned long ROL64(unsigned long word, int i)
|
||||
{
|
||||
@@ -360,10 +404,13 @@ static inline unsigned long ROR64c(unsigned long word, const int i)
|
||||
|
||||
#endif
|
||||
|
||||
#undef MAX
|
||||
#undef MIN
|
||||
#define MAX(x, y) ( ((x)>(y))?(x):(y) )
|
||||
#define MIN(x, y) ( ((x)<(y))?(x):(y) )
|
||||
#ifndef MAX
|
||||
#define MAX(x, y) ( ((x)>(y))?(x):(y) )
|
||||
#endif
|
||||
|
||||
#ifndef MIN
|
||||
#define MIN(x, y) ( ((x)<(y))?(x):(y) )
|
||||
#endif
|
||||
|
||||
/* extract a byte portably */
|
||||
#ifdef _MSC_VER
|
||||
@@ -373,5 +420,5 @@ static inline unsigned long ROR64c(unsigned long word, const int i)
|
||||
#endif
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/headers/tomcrypt_macros.h,v $ */
|
||||
/* $Revision: 1.7 $ */
|
||||
/* $Date: 2005/05/05 14:35:58 $ */
|
||||
/* $Revision: 1.15 $ */
|
||||
/* $Date: 2006/11/29 23:43:57 $ */
|
||||
|
||||
500
libtomcrypt/src/headers/tomcrypt_math.h
Normal file
500
libtomcrypt/src/headers/tomcrypt_math.h
Normal file
@@ -0,0 +1,500 @@
|
||||
/** math functions **/
|
||||
|
||||
#define LTC_MP_LT -1
|
||||
#define LTC_MP_EQ 0
|
||||
#define LTC_MP_GT 1
|
||||
|
||||
#define LTC_MP_NO 0
|
||||
#define LTC_MP_YES 1
|
||||
|
||||
#ifndef MECC
|
||||
typedef void ecc_point;
|
||||
#endif
|
||||
|
||||
#ifndef MRSA
|
||||
typedef void rsa_key;
|
||||
#endif
|
||||
|
||||
/** math descriptor */
|
||||
typedef struct {
|
||||
/** Name of the math provider */
|
||||
char *name;
|
||||
|
||||
/** Bits per digit, amount of bits must fit in an unsigned long */
|
||||
int bits_per_digit;
|
||||
|
||||
/* ---- init/deinit functions ---- */
|
||||
|
||||
/** initialize a bignum
|
||||
@param a The number to initialize
|
||||
@return CRYPT_OK on success
|
||||
*/
|
||||
int (*init)(void **a);
|
||||
|
||||
/** init copy
|
||||
@param dst The number to initialize and write to
|
||||
@param src The number to copy from
|
||||
@return CRYPT_OK on success
|
||||
*/
|
||||
int (*init_copy)(void **dst, void *src);
|
||||
|
||||
/** deinit
|
||||
@param a The number to free
|
||||
@return CRYPT_OK on success
|
||||
*/
|
||||
void (*deinit)(void *a);
|
||||
|
||||
/* ---- data movement ---- */
|
||||
|
||||
/** negate
|
||||
@param src The number to negate
|
||||
@param dst The destination
|
||||
@return CRYPT_OK on success
|
||||
*/
|
||||
int (*neg)(void *src, void *dst);
|
||||
|
||||
/** copy
|
||||
@param src The number to copy from
|
||||
@param dst The number to write to
|
||||
@return CRYPT_OK on success
|
||||
*/
|
||||
int (*copy)(void *src, void *dst);
|
||||
|
||||
/* ---- trivial low level functions ---- */
|
||||
|
||||
/** set small constant
|
||||
@param a Number to write to
|
||||
@param n Source upto bits_per_digit (actually meant for very small constants)
|
||||
@return CRYPT_OK on succcess
|
||||
*/
|
||||
int (*set_int)(void *a, unsigned long n);
|
||||
|
||||
/** get small constant
|
||||
@param a Number to read, only fetches upto bits_per_digit from the number
|
||||
@return The lower bits_per_digit of the integer (unsigned)
|
||||
*/
|
||||
unsigned long (*get_int)(void *a);
|
||||
|
||||
/** get digit n
|
||||
@param a The number to read from
|
||||
@param n The number of the digit to fetch
|
||||
@return The bits_per_digit sized n'th digit of a
|
||||
*/
|
||||
unsigned long (*get_digit)(void *a, int n);
|
||||
|
||||
/** Get the number of digits that represent the number
|
||||
@param a The number to count
|
||||
@return The number of digits used to represent the number
|
||||
*/
|
||||
int (*get_digit_count)(void *a);
|
||||
|
||||
/** compare two integers
|
||||
@param a The left side integer
|
||||
@param b The right side integer
|
||||
@return LTC_MP_LT if a < b, LTC_MP_GT if a > b and LTC_MP_EQ otherwise. (signed comparison)
|
||||
*/
|
||||
int (*compare)(void *a, void *b);
|
||||
|
||||
/** compare against int
|
||||
@param a The left side integer
|
||||
@param b The right side integer (upto bits_per_digit)
|
||||
@return LTC_MP_LT if a < b, LTC_MP_GT if a > b and LTC_MP_EQ otherwise. (signed comparison)
|
||||
*/
|
||||
int (*compare_d)(void *a, unsigned long n);
|
||||
|
||||
/** Count the number of bits used to represent the integer
|
||||
@param a The integer to count
|
||||
@return The number of bits required to represent the integer
|
||||
*/
|
||||
int (*count_bits)(void * a);
|
||||
|
||||
/** Count the number of LSB bits which are zero
|
||||
@param a The integer to count
|
||||
@return The number of contiguous zero LSB bits
|
||||
*/
|
||||
int (*count_lsb_bits)(void *a);
|
||||
|
||||
/** Compute a power of two
|
||||
@param a The integer to store the power in
|
||||
@param n The power of two you want to store (a = 2^n)
|
||||
@return CRYPT_OK on success
|
||||
*/
|
||||
int (*twoexpt)(void *a , int n);
|
||||
|
||||
/* ---- radix conversions ---- */
|
||||
|
||||
/** read ascii string
|
||||
@param a The integer to store into
|
||||
@param str The string to read
|
||||
@param radix The radix the integer has been represented in (2-64)
|
||||
@return CRYPT_OK on success
|
||||
*/
|
||||
int (*read_radix)(void *a, const char *str, int radix);
|
||||
|
||||
/** write number to string
|
||||
@param a The integer to store
|
||||
@param str The destination for the string
|
||||
@param radix The radix the integer is to be represented in (2-64)
|
||||
@return CRYPT_OK on success
|
||||
*/
|
||||
int (*write_radix)(void *a, char *str, int radix);
|
||||
|
||||
/** get size as unsigned char string
|
||||
@param a The integer to get the size (when stored in array of octets)
|
||||
@return The length of the integer
|
||||
*/
|
||||
unsigned long (*unsigned_size)(void *a);
|
||||
|
||||
/** store an integer as an array of octets
|
||||
@param src The integer to store
|
||||
@param dst The buffer to store the integer in
|
||||
@return CRYPT_OK on success
|
||||
*/
|
||||
int (*unsigned_write)(void *src, unsigned char *dst);
|
||||
|
||||
/** read an array of octets and store as integer
|
||||
@param dst The integer to load
|
||||
@param src The array of octets
|
||||
@param len The number of octets
|
||||
@return CRYPT_OK on success
|
||||
*/
|
||||
int (*unsigned_read)(void *dst, unsigned char *src, unsigned long len);
|
||||
|
||||
/* ---- basic math ---- */
|
||||
|
||||
/** add two integers
|
||||
@param a The first source integer
|
||||
@param b The second source integer
|
||||
@param c The destination of "a + b"
|
||||
@return CRYPT_OK on success
|
||||
*/
|
||||
int (*add)(void *a, void *b, void *c);
|
||||
|
||||
|
||||
/** add two integers
|
||||
@param a The first source integer
|
||||
@param b The second source integer (single digit of upto bits_per_digit in length)
|
||||
@param c The destination of "a + b"
|
||||
@return CRYPT_OK on success
|
||||
*/
|
||||
int (*addi)(void *a, unsigned long b, void *c);
|
||||
|
||||
/** subtract two integers
|
||||
@param a The first source integer
|
||||
@param b The second source integer
|
||||
@param c The destination of "a - b"
|
||||
@return CRYPT_OK on success
|
||||
*/
|
||||
int (*sub)(void *a, void *b, void *c);
|
||||
|
||||
/** subtract two integers
|
||||
@param a The first source integer
|
||||
@param b The second source integer (single digit of upto bits_per_digit in length)
|
||||
@param c The destination of "a - b"
|
||||
@return CRYPT_OK on success
|
||||
*/
|
||||
int (*subi)(void *a, unsigned long b, void *c);
|
||||
|
||||
/** multiply two integers
|
||||
@param a The first source integer
|
||||
@param b The second source integer (single digit of upto bits_per_digit in length)
|
||||
@param c The destination of "a * b"
|
||||
@return CRYPT_OK on success
|
||||
*/
|
||||
int (*mul)(void *a, void *b, void *c);
|
||||
|
||||
/** multiply two integers
|
||||
@param a The first source integer
|
||||
@param b The second source integer (single digit of upto bits_per_digit in length)
|
||||
@param c The destination of "a * b"
|
||||
@return CRYPT_OK on success
|
||||
*/
|
||||
int (*muli)(void *a, unsigned long b, void *c);
|
||||
|
||||
/** Square an integer
|
||||
@param a The integer to square
|
||||
@param b The destination
|
||||
@return CRYPT_OK on success
|
||||
*/
|
||||
int (*sqr)(void *a, void *b);
|
||||
|
||||
/** Divide an integer
|
||||
@param a The dividend
|
||||
@param b The divisor
|
||||
@param c The quotient (can be NULL to signify don't care)
|
||||
@param d The remainder (can be NULL to signify don't care)
|
||||
@return CRYPT_OK on success
|
||||
*/
|
||||
int (*mpdiv)(void *a, void *b, void *c, void *d);
|
||||
|
||||
/** divide by two
|
||||
@param a The integer to divide (shift right)
|
||||
@param b The destination
|
||||
@return CRYPT_OK on success
|
||||
*/
|
||||
int (*div_2)(void *a, void *b);
|
||||
|
||||
/** Get remainder (small value)
|
||||
@param a The integer to reduce
|
||||
@param b The modulus (upto bits_per_digit in length)
|
||||
@param c The destination for the residue
|
||||
@return CRYPT_OK on success
|
||||
*/
|
||||
int (*modi)(void *a, unsigned long b, unsigned long *c);
|
||||
|
||||
/** gcd
|
||||
@param a The first integer
|
||||
@param b The second integer
|
||||
@param c The destination for (a, b)
|
||||
@return CRYPT_OK on success
|
||||
*/
|
||||
int (*gcd)(void *a, void *b, void *c);
|
||||
|
||||
/** lcm
|
||||
@param a The first integer
|
||||
@param b The second integer
|
||||
@param c The destination for [a, b]
|
||||
@return CRYPT_OK on success
|
||||
*/
|
||||
int (*lcm)(void *a, void *b, void *c);
|
||||
|
||||
/** Modular multiplication
|
||||
@param a The first source
|
||||
@param b The second source
|
||||
@param c The modulus
|
||||
@param d The destination (a*b mod c)
|
||||
@return CRYPT_OK on success
|
||||
*/
|
||||
int (*mulmod)(void *a, void *b, void *c, void *d);
|
||||
|
||||
/** Modular squaring
|
||||
@param a The first source
|
||||
@param b The modulus
|
||||
@param c The destination (a*a mod b)
|
||||
@return CRYPT_OK on success
|
||||
*/
|
||||
int (*sqrmod)(void *a, void *b, void *c);
|
||||
|
||||
/** Modular inversion
|
||||
@param a The value to invert
|
||||
@param b The modulus
|
||||
@param c The destination (1/a mod b)
|
||||
@return CRYPT_OK on success
|
||||
*/
|
||||
int (*invmod)(void *, void *, void *);
|
||||
|
||||
/* ---- reduction ---- */
|
||||
|
||||
/** setup montgomery
|
||||
@param a The modulus
|
||||
@param b The destination for the reduction digit
|
||||
@return CRYPT_OK on success
|
||||
*/
|
||||
int (*montgomery_setup)(void *a, void **b);
|
||||
|
||||
/** get normalization value
|
||||
@param a The destination for the normalization value
|
||||
@param b The modulus
|
||||
@return CRYPT_OK on success
|
||||
*/
|
||||
int (*montgomery_normalization)(void *a, void *b);
|
||||
|
||||
/** reduce a number
|
||||
@param a The number [and dest] to reduce
|
||||
@param b The modulus
|
||||
@param c The value "b" from montgomery_setup()
|
||||
@return CRYPT_OK on success
|
||||
*/
|
||||
int (*montgomery_reduce)(void *a, void *b, void *c);
|
||||
|
||||
/** clean up (frees memory)
|
||||
@param a The value "b" from montgomery_setup()
|
||||
@return CRYPT_OK on success
|
||||
*/
|
||||
void (*montgomery_deinit)(void *a);
|
||||
|
||||
/* ---- exponentiation ---- */
|
||||
|
||||
/** Modular exponentiation
|
||||
@param a The base integer
|
||||
@param b The power (can be negative) integer
|
||||
@param c The modulus integer
|
||||
@param d The destination
|
||||
@return CRYPT_OK on success
|
||||
*/
|
||||
int (*exptmod)(void *a, void *b, void *c, void *d);
|
||||
|
||||
/** Primality testing
|
||||
@param a The integer to test
|
||||
@param b The destination of the result (FP_YES if prime)
|
||||
@return CRYPT_OK on success
|
||||
*/
|
||||
int (*isprime)(void *a, int *b);
|
||||
|
||||
/* ---- (optional) ecc point math ---- */
|
||||
|
||||
/** ECC GF(p) point multiplication (from the NIST curves)
|
||||
@param k The integer to multiply the point by
|
||||
@param G The point to multiply
|
||||
@param R The destination for kG
|
||||
@param modulus The modulus for the field
|
||||
@param map Boolean indicated whether to map back to affine or not (can be ignored if you work in affine only)
|
||||
@return CRYPT_OK on success
|
||||
*/
|
||||
int (*ecc_ptmul)(void *k, ecc_point *G, ecc_point *R, void *modulus, int map);
|
||||
|
||||
/** ECC GF(p) point addition
|
||||
@param P The first point
|
||||
@param Q The second point
|
||||
@param R The destination of P + Q
|
||||
@param modulus The modulus
|
||||
@param mp The "b" value from montgomery_setup()
|
||||
@return CRYPT_OK on success
|
||||
*/
|
||||
int (*ecc_ptadd)(ecc_point *P, ecc_point *Q, ecc_point *R, void *modulus, void *mp);
|
||||
|
||||
/** ECC GF(p) point double
|
||||
@param P The first point
|
||||
@param R The destination of 2P
|
||||
@param modulus The modulus
|
||||
@param mp The "b" value from montgomery_setup()
|
||||
@return CRYPT_OK on success
|
||||
*/
|
||||
int (*ecc_ptdbl)(ecc_point *P, ecc_point *R, void *modulus, void *mp);
|
||||
|
||||
/** ECC mapping from projective to affine, currently uses (x,y,z) => (x/z^2, y/z^3, 1)
|
||||
@param P The point to map
|
||||
@param modulus The modulus
|
||||
@param mp The "b" value from montgomery_setup()
|
||||
@return CRYPT_OK on success
|
||||
@remark The mapping can be different but keep in mind a ecc_point only has three
|
||||
integers (x,y,z) so if you use a different mapping you have to make it fit.
|
||||
*/
|
||||
int (*ecc_map)(ecc_point *P, void *modulus, void *mp);
|
||||
|
||||
/** Computes kA*A + kB*B = C using Shamir's Trick
|
||||
@param A First point to multiply
|
||||
@param kA What to multiple A by
|
||||
@param B Second point to multiply
|
||||
@param kB What to multiple B by
|
||||
@param C [out] Destination point (can overlap with A or B
|
||||
@param modulus Modulus for curve
|
||||
@return CRYPT_OK on success
|
||||
*/
|
||||
int (*ecc_mul2add)(ecc_point *A, void *kA,
|
||||
ecc_point *B, void *kB,
|
||||
ecc_point *C,
|
||||
void *modulus);
|
||||
|
||||
/* ---- (optional) rsa optimized math (for internal CRT) ---- */
|
||||
|
||||
/** RSA Key Generation
|
||||
@param prng An active PRNG state
|
||||
@param wprng The index of the PRNG desired
|
||||
@param size The size of the modulus (key size) desired (octets)
|
||||
@param e The "e" value (public key). e==65537 is a good choice
|
||||
@param key [out] Destination of a newly created private key pair
|
||||
@return CRYPT_OK if successful, upon error all allocated ram is freed
|
||||
*/
|
||||
int (*rsa_keygen)(prng_state *prng, int wprng, int size, long e, rsa_key *key);
|
||||
|
||||
|
||||
/** RSA exponentiation
|
||||
@param in The octet array representing the base
|
||||
@param inlen The length of the input
|
||||
@param out The destination (to be stored in an octet array format)
|
||||
@param outlen The length of the output buffer and the resulting size (zero padded to the size of the modulus)
|
||||
@param which PK_PUBLIC for public RSA and PK_PRIVATE for private RSA
|
||||
@param key The RSA key to use
|
||||
@return CRYPT_OK on success
|
||||
*/
|
||||
int (*rsa_me)(const unsigned char *in, unsigned long inlen,
|
||||
unsigned char *out, unsigned long *outlen, int which,
|
||||
rsa_key *key);
|
||||
} ltc_math_descriptor;
|
||||
|
||||
extern ltc_math_descriptor ltc_mp;
|
||||
|
||||
int ltc_init_multi(void **a, ...);
|
||||
void ltc_deinit_multi(void *a, ...);
|
||||
|
||||
#ifdef LTM_DESC
|
||||
extern const ltc_math_descriptor ltm_desc;
|
||||
#endif
|
||||
|
||||
#ifdef TFM_DESC
|
||||
extern const ltc_math_descriptor tfm_desc;
|
||||
#endif
|
||||
|
||||
#ifdef GMP_DESC
|
||||
extern const ltc_math_descriptor gmp_desc;
|
||||
#endif
|
||||
|
||||
#if !defined(DESC_DEF_ONLY) && defined(LTC_SOURCE)
|
||||
|
||||
#define MP_DIGIT_BIT ltc_mp.bits_per_digit
|
||||
|
||||
/* some handy macros */
|
||||
#define mp_init(a) ltc_mp.init(a)
|
||||
#define mp_init_multi ltc_init_multi
|
||||
#define mp_clear(a) ltc_mp.deinit(a)
|
||||
#define mp_clear_multi ltc_deinit_multi
|
||||
#define mp_init_copy(a, b) ltc_mp.init_copy(a, b)
|
||||
|
||||
#define mp_neg(a, b) ltc_mp.neg(a, b)
|
||||
#define mp_copy(a, b) ltc_mp.copy(a, b)
|
||||
|
||||
#define mp_set(a, b) ltc_mp.set_int(a, b)
|
||||
#define mp_set_int(a, b) ltc_mp.set_int(a, b)
|
||||
#define mp_get_int(a) ltc_mp.get_int(a)
|
||||
#define mp_get_digit(a, n) ltc_mp.get_digit(a, n)
|
||||
#define mp_get_digit_count(a) ltc_mp.get_digit_count(a)
|
||||
#define mp_cmp(a, b) ltc_mp.compare(a, b)
|
||||
#define mp_cmp_d(a, b) ltc_mp.compare_d(a, b)
|
||||
#define mp_count_bits(a) ltc_mp.count_bits(a)
|
||||
#define mp_cnt_lsb(a) ltc_mp.count_lsb_bits(a)
|
||||
#define mp_2expt(a, b) ltc_mp.twoexpt(a, b)
|
||||
|
||||
#define mp_read_radix(a, b, c) ltc_mp.read_radix(a, b, c)
|
||||
#define mp_toradix(a, b, c) ltc_mp.write_radix(a, b, c)
|
||||
#define mp_unsigned_bin_size(a) ltc_mp.unsigned_size(a)
|
||||
#define mp_to_unsigned_bin(a, b) ltc_mp.unsigned_write(a, b)
|
||||
#define mp_read_unsigned_bin(a, b, c) ltc_mp.unsigned_read(a, b, c)
|
||||
|
||||
#define mp_add(a, b, c) ltc_mp.add(a, b, c)
|
||||
#define mp_add_d(a, b, c) ltc_mp.addi(a, b, c)
|
||||
#define mp_sub(a, b, c) ltc_mp.sub(a, b, c)
|
||||
#define mp_sub_d(a, b, c) ltc_mp.subi(a, b, c)
|
||||
#define mp_mul(a, b, c) ltc_mp.mul(a, b, c)
|
||||
#define mp_mul_d(a, b, c) ltc_mp.muli(a, b, c)
|
||||
#define mp_sqr(a, b) ltc_mp.sqr(a, b)
|
||||
#define mp_div(a, b, c, d) ltc_mp.mpdiv(a, b, c, d)
|
||||
#define mp_div_2(a, b) ltc_mp.div_2(a, b)
|
||||
#define mp_mod(a, b, c) ltc_mp.mpdiv(a, b, NULL, c)
|
||||
#define mp_mod_d(a, b, c) ltc_mp.modi(a, b, c)
|
||||
#define mp_gcd(a, b, c) ltc_mp.gcd(a, b, c)
|
||||
#define mp_lcm(a, b, c) ltc_mp.lcm(a, b, c)
|
||||
|
||||
#define mp_mulmod(a, b, c, d) ltc_mp.mulmod(a, b, c, d)
|
||||
#define mp_sqrmod(a, b, c) ltc_mp.sqrmod(a, b, c)
|
||||
#define mp_invmod(a, b, c) ltc_mp.invmod(a, b, c)
|
||||
|
||||
#define mp_montgomery_setup(a, b) ltc_mp.montgomery_setup(a, b)
|
||||
#define mp_montgomery_normalization(a, b) ltc_mp.montgomery_normalization(a, b)
|
||||
#define mp_montgomery_reduce(a, b, c) ltc_mp.montgomery_reduce(a, b, c)
|
||||
#define mp_montgomery_free(a) ltc_mp.montgomery_deinit(a)
|
||||
|
||||
#define mp_exptmod(a,b,c,d) ltc_mp.exptmod(a,b,c,d)
|
||||
#define mp_prime_is_prime(a, b, c) ltc_mp.isprime(a, c)
|
||||
|
||||
#define mp_iszero(a) (mp_cmp_d(a, 0) == LTC_MP_EQ ? LTC_MP_YES : LTC_MP_NO)
|
||||
#define mp_isodd(a) (mp_get_digit_count(a) > 0 ? (mp_get_digit(a, 0) & 1 ? LTC_MP_YES : LTC_MP_NO) : LTC_MP_NO)
|
||||
#define mp_exch(a, b) do { void *ABC__tmp = a; a = b; b = ABC__tmp; } while(0);
|
||||
|
||||
#define mp_tohex(a, b) mp_toradix(a, b, 16)
|
||||
|
||||
#endif
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/headers/tomcrypt_math.h,v $ */
|
||||
/* $Revision: 1.43 $ */
|
||||
/* $Date: 2006/12/02 19:23:13 $ */
|
||||
@@ -12,10 +12,12 @@ void zeromem(void *dst, size_t len);
|
||||
void burn_stack(unsigned long len);
|
||||
|
||||
const char *error_to_string(int err);
|
||||
int mpi_to_ltc_error(int err);
|
||||
|
||||
extern const char *crypt_build_settings;
|
||||
|
||||
/* ---- HMM ---- */
|
||||
int crypt_fsa(void *mp, ...);
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/headers/tomcrypt_misc.h,v $ */
|
||||
/* $Revision: 1.2 $ */
|
||||
/* $Date: 2005/05/05 14:35:58 $ */
|
||||
/* $Revision: 1.4 $ */
|
||||
/* $Date: 2006/11/06 03:03:01 $ */
|
||||
|
||||
@@ -1,81 +1,11 @@
|
||||
/* ---- NUMBER THEORY ---- */
|
||||
#ifdef MPI
|
||||
|
||||
#include "ltc_tommath.h"
|
||||
|
||||
/* in/out macros */
|
||||
#define OUTPUT_BIGNUM(num, out, y, z) \
|
||||
{ \
|
||||
if ((y + 4) > *outlen) { return CRYPT_BUFFER_OVERFLOW; } \
|
||||
z = (unsigned long)mp_unsigned_bin_size(num); \
|
||||
STORE32L(z, out+y); \
|
||||
y += 4; \
|
||||
if ((y + z) > *outlen) { return CRYPT_BUFFER_OVERFLOW; } \
|
||||
if ((err = mp_to_unsigned_bin(num, out+y)) != MP_OKAY) { return mpi_to_ltc_error(err); } \
|
||||
y += z; \
|
||||
}
|
||||
|
||||
|
||||
#define INPUT_BIGNUM(num, in, x, y, inlen) \
|
||||
{ \
|
||||
/* load value */ \
|
||||
if ((y + 4) > inlen) { \
|
||||
err = CRYPT_INVALID_PACKET; \
|
||||
goto error; \
|
||||
} \
|
||||
LOAD32L(x, in+y); \
|
||||
y += 4; \
|
||||
\
|
||||
/* sanity check... */ \
|
||||
if ((x+y) > inlen) { \
|
||||
err = CRYPT_INVALID_PACKET; \
|
||||
goto error; \
|
||||
} \
|
||||
\
|
||||
/* load it */ \
|
||||
if ((err = mp_read_unsigned_bin(num, (unsigned char *)in+y, (int)x)) != MP_OKAY) {\
|
||||
err = mpi_to_ltc_error(err); \
|
||||
goto error; \
|
||||
} \
|
||||
y += x; \
|
||||
if ((err = mp_shrink(num)) != MP_OKAY) { \
|
||||
err = mpi_to_ltc_error(err); \
|
||||
goto error; \
|
||||
} \
|
||||
}
|
||||
|
||||
int is_prime(mp_int *, int *);
|
||||
int rand_prime(mp_int *N, long len, prng_state *prng, int wprng);
|
||||
|
||||
#else
|
||||
#ifdef MRSA
|
||||
#error RSA requires the big int library
|
||||
#endif
|
||||
#ifdef MECC
|
||||
#error ECC requires the big int library
|
||||
#endif
|
||||
#ifdef MDH
|
||||
#error DH requires the big int library
|
||||
#endif
|
||||
#ifdef MDSA
|
||||
#error DSA requires the big int library
|
||||
#endif
|
||||
#endif /* MPI */
|
||||
|
||||
|
||||
/* ---- PUBLIC KEY CRYPTO ---- */
|
||||
|
||||
#define PK_PRIVATE 0 /* PK private keys */
|
||||
#define PK_PUBLIC 1 /* PK public keys */
|
||||
|
||||
/* ---- PACKET ---- */
|
||||
#ifdef PACKET
|
||||
|
||||
void packet_store_header(unsigned char *dst, int section, int subsection);
|
||||
int packet_valid_header(unsigned char *src, int section, int subsection);
|
||||
|
||||
#endif
|
||||
enum {
|
||||
PK_PUBLIC=0,
|
||||
PK_PRIVATE=1
|
||||
};
|
||||
|
||||
int rand_prime(void *N, long len, prng_state *prng, int wprng);
|
||||
|
||||
/* ---- RSA ---- */
|
||||
#ifdef MRSA
|
||||
@@ -84,9 +14,26 @@ int packet_valid_header(unsigned char *src, int section, int subsection);
|
||||
#define MIN_RSA_SIZE 1024
|
||||
#define MAX_RSA_SIZE 4096
|
||||
|
||||
/** RSA PKCS style key */
|
||||
typedef struct Rsa_key {
|
||||
/** Type of key, PK_PRIVATE or PK_PUBLIC */
|
||||
int type;
|
||||
mp_int e, d, N, p, q, qP, dP, dQ;
|
||||
/** The public exponent */
|
||||
void *e;
|
||||
/** The private exponent */
|
||||
void *d;
|
||||
/** The modulus */
|
||||
void *N;
|
||||
/** The p factor of N */
|
||||
void *p;
|
||||
/** The q factor of N */
|
||||
void *q;
|
||||
/** The 1/q mod p CRT param */
|
||||
void *qP;
|
||||
/** The d mod (p - 1) CRT param */
|
||||
void *dP;
|
||||
/** The d mod (q - 1) CRT param */
|
||||
void *dQ;
|
||||
} rsa_key;
|
||||
|
||||
int rsa_make_key(prng_state *prng, int wprng, int size, long e, rsa_key *key);
|
||||
@@ -98,27 +45,42 @@ int rsa_exptmod(const unsigned char *in, unsigned long inlen,
|
||||
void rsa_free(rsa_key *key);
|
||||
|
||||
/* These use PKCS #1 v2.0 padding */
|
||||
int rsa_encrypt_key(const unsigned char *in, unsigned long inlen,
|
||||
unsigned char *out, unsigned long *outlen,
|
||||
const unsigned char *lparam, unsigned long lparamlen,
|
||||
prng_state *prng, int prng_idx, int hash_idx, rsa_key *key);
|
||||
|
||||
int rsa_decrypt_key(const unsigned char *in, unsigned long inlen,
|
||||
unsigned char *out, unsigned long *outlen,
|
||||
const unsigned char *lparam, unsigned long lparamlen,
|
||||
int hash_idx, int *stat,
|
||||
rsa_key *key);
|
||||
#define rsa_encrypt_key(_in, _inlen, _out, _outlen, _lparam, _lparamlen, _prng, _prng_idx, _hash_idx, _key) \
|
||||
rsa_encrypt_key_ex(_in, _inlen, _out, _outlen, _lparam, _lparamlen, _prng, _prng_idx, _hash_idx, LTC_PKCS_1_OAEP, _key)
|
||||
|
||||
int rsa_sign_hash(const unsigned char *in, unsigned long inlen,
|
||||
unsigned char *out, unsigned long *outlen,
|
||||
prng_state *prng, int prng_idx,
|
||||
int hash_idx, unsigned long saltlen,
|
||||
rsa_key *key);
|
||||
#define rsa_decrypt_key(_in, _inlen, _out, _outlen, _lparam, _lparamlen, _hash_idx, _stat, _key) \
|
||||
rsa_decrypt_key_ex(_in, _inlen, _out, _outlen, _lparam, _lparamlen, _hash_idx, LTC_PKCS_1_OAEP, _stat, _key)
|
||||
|
||||
int rsa_verify_hash(const unsigned char *sig, unsigned long siglen,
|
||||
const unsigned char *hash, unsigned long hashlen,
|
||||
int hash_idx, unsigned long saltlen,
|
||||
int *stat, rsa_key *key);
|
||||
#define rsa_sign_hash(_in, _inlen, _out, _outlen, _prng, _prng_idx, _hash_idx, _saltlen, _key) \
|
||||
rsa_sign_hash_ex(_in, _inlen, _out, _outlen, LTC_PKCS_1_PSS, _prng, _prng_idx, _hash_idx, _saltlen, _key)
|
||||
|
||||
#define rsa_verify_hash(_sig, _siglen, _hash, _hashlen, _hash_idx, _saltlen, _stat, _key) \
|
||||
rsa_verify_hash_ex(_sig, _siglen, _hash, _hashlen, LTC_PKCS_1_PSS, _hash_idx, _saltlen, _stat, _key)
|
||||
|
||||
/* These can be switched between PKCS #1 v2.x and PKCS #1 v1.5 paddings */
|
||||
int rsa_encrypt_key_ex(const unsigned char *in, unsigned long inlen,
|
||||
unsigned char *out, unsigned long *outlen,
|
||||
const unsigned char *lparam, unsigned long lparamlen,
|
||||
prng_state *prng, int prng_idx, int hash_idx, int padding, rsa_key *key);
|
||||
|
||||
int rsa_decrypt_key_ex(const unsigned char *in, unsigned long inlen,
|
||||
unsigned char *out, unsigned long *outlen,
|
||||
const unsigned char *lparam, unsigned long lparamlen,
|
||||
int hash_idx, int padding,
|
||||
int *stat, rsa_key *key);
|
||||
|
||||
int rsa_sign_hash_ex(const unsigned char *in, unsigned long inlen,
|
||||
unsigned char *out, unsigned long *outlen,
|
||||
int padding,
|
||||
prng_state *prng, int prng_idx,
|
||||
int hash_idx, unsigned long saltlen,
|
||||
rsa_key *key);
|
||||
|
||||
int rsa_verify_hash_ex(const unsigned char *sig, unsigned long siglen,
|
||||
const unsigned char *hash, unsigned long hashlen,
|
||||
int padding,
|
||||
int hash_idx, unsigned long saltlen,
|
||||
int *stat, rsa_key *key);
|
||||
|
||||
/* PKCS #1 import/export */
|
||||
int rsa_export(unsigned char *out, unsigned long *outlen, int type, rsa_key *key);
|
||||
@@ -126,111 +88,252 @@ int rsa_import(const unsigned char *in, unsigned long inlen, rsa_key *key);
|
||||
|
||||
#endif
|
||||
|
||||
/* ---- DH Routines ---- */
|
||||
#ifdef MDH
|
||||
/* ---- Katja ---- */
|
||||
#ifdef MKAT
|
||||
|
||||
typedef struct Dh_key {
|
||||
int idx, type;
|
||||
mp_int x, y;
|
||||
} dh_key;
|
||||
/* Min and Max KAT key sizes (in bits) */
|
||||
#define MIN_KAT_SIZE 1024
|
||||
#define MAX_KAT_SIZE 4096
|
||||
|
||||
int dh_test(void);
|
||||
void dh_sizes(int *low, int *high);
|
||||
int dh_get_size(dh_key *key);
|
||||
/** Katja PKCS style key */
|
||||
typedef struct KAT_key {
|
||||
/** Type of key, PK_PRIVATE or PK_PUBLIC */
|
||||
int type;
|
||||
/** The private exponent */
|
||||
void *d;
|
||||
/** The modulus */
|
||||
void *N;
|
||||
/** The p factor of N */
|
||||
void *p;
|
||||
/** The q factor of N */
|
||||
void *q;
|
||||
/** The 1/q mod p CRT param */
|
||||
void *qP;
|
||||
/** The d mod (p - 1) CRT param */
|
||||
void *dP;
|
||||
/** The d mod (q - 1) CRT param */
|
||||
void *dQ;
|
||||
/** The pq param */
|
||||
void *pq;
|
||||
} katja_key;
|
||||
|
||||
int dh_make_key(prng_state *prng, int wprng, int keysize, dh_key *key);
|
||||
void dh_free(dh_key *key);
|
||||
int katja_make_key(prng_state *prng, int wprng, int size, katja_key *key);
|
||||
|
||||
int dh_export(unsigned char *out, unsigned long *outlen, int type, dh_key *key);
|
||||
int dh_import(const unsigned char *in, unsigned long inlen, dh_key *key);
|
||||
int katja_exptmod(const unsigned char *in, unsigned long inlen,
|
||||
unsigned char *out, unsigned long *outlen, int which,
|
||||
katja_key *key);
|
||||
|
||||
int dh_shared_secret(dh_key *private_key, dh_key *public_key,
|
||||
unsigned char *out, unsigned long *outlen);
|
||||
|
||||
int dh_encrypt_key(const unsigned char *in, unsigned long keylen,
|
||||
unsigned char *out, unsigned long *outlen,
|
||||
prng_state *prng, int wprng, int hash,
|
||||
dh_key *key);
|
||||
|
||||
int dh_decrypt_key(const unsigned char *in, unsigned long inlen,
|
||||
unsigned char *out, unsigned long *outlen,
|
||||
dh_key *key);
|
||||
|
||||
int dh_sign_hash(const unsigned char *in, unsigned long inlen,
|
||||
unsigned char *out, unsigned long *outlen,
|
||||
prng_state *prng, int wprng, dh_key *key);
|
||||
|
||||
int dh_verify_hash(const unsigned char *sig, unsigned long siglen,
|
||||
const unsigned char *hash, unsigned long hashlen,
|
||||
int *stat, dh_key *key);
|
||||
void katja_free(katja_key *key);
|
||||
|
||||
/* These use PKCS #1 v2.0 padding */
|
||||
int katja_encrypt_key(const unsigned char *in, unsigned long inlen,
|
||||
unsigned char *out, unsigned long *outlen,
|
||||
const unsigned char *lparam, unsigned long lparamlen,
|
||||
prng_state *prng, int prng_idx, int hash_idx, katja_key *key);
|
||||
|
||||
int katja_decrypt_key(const unsigned char *in, unsigned long inlen,
|
||||
unsigned char *out, unsigned long *outlen,
|
||||
const unsigned char *lparam, unsigned long lparamlen,
|
||||
int hash_idx, int *stat,
|
||||
katja_key *key);
|
||||
|
||||
/* PKCS #1 import/export */
|
||||
int katja_export(unsigned char *out, unsigned long *outlen, int type, katja_key *key);
|
||||
int katja_import(const unsigned char *in, unsigned long inlen, katja_key *key);
|
||||
|
||||
#endif
|
||||
|
||||
/* ---- ECC Routines ---- */
|
||||
#ifdef MECC
|
||||
|
||||
/* size of our temp buffers for exported keys */
|
||||
#define ECC_BUF_SIZE 256
|
||||
|
||||
/* max private key size */
|
||||
#define ECC_MAXSIZE 66
|
||||
|
||||
/** Structure defines a NIST GF(p) curve */
|
||||
typedef struct {
|
||||
mp_int x, y, z;
|
||||
/** The size of the curve in octets */
|
||||
int size;
|
||||
|
||||
/** name of curve */
|
||||
char *name;
|
||||
|
||||
/** The prime that defines the field the curve is in (encoded in hex) */
|
||||
char *prime;
|
||||
|
||||
/** The fields B param (hex) */
|
||||
char *B;
|
||||
|
||||
/** The order of the curve (hex) */
|
||||
char *order;
|
||||
|
||||
/** The x co-ordinate of the base point on the curve (hex) */
|
||||
char *Gx;
|
||||
|
||||
/** The y co-ordinate of the base point on the curve (hex) */
|
||||
char *Gy;
|
||||
} ltc_ecc_set_type;
|
||||
|
||||
/** A point on a ECC curve, stored in Jacbobian format such that (x,y,z) => (x/z^2, y/z^3, 1) when interpretted as affine */
|
||||
typedef struct {
|
||||
/** The x co-ordinate */
|
||||
void *x;
|
||||
|
||||
/** The y co-ordinate */
|
||||
void *y;
|
||||
|
||||
/** The z co-ordinate */
|
||||
void *z;
|
||||
} ecc_point;
|
||||
|
||||
/** An ECC key */
|
||||
typedef struct {
|
||||
int type, idx;
|
||||
/** Type of key, PK_PRIVATE or PK_PUBLIC */
|
||||
int type;
|
||||
|
||||
/** Index into the ltc_ecc_sets[] for the parameters of this curve; if -1, then this key is using user supplied curve in dp */
|
||||
int idx;
|
||||
|
||||
/** pointer to domain parameters; either points to NIST curves (identified by idx >= 0) or user supplied curve */
|
||||
const ltc_ecc_set_type *dp;
|
||||
|
||||
/** The public key */
|
||||
ecc_point pubkey;
|
||||
mp_int k;
|
||||
|
||||
/** The private key */
|
||||
void *k;
|
||||
} ecc_key;
|
||||
|
||||
int ecc_test(void);
|
||||
void ecc_sizes(int *low, int *high);
|
||||
int ecc_get_size(ecc_key *key);
|
||||
/** the ECC params provided */
|
||||
extern const ltc_ecc_set_type ltc_ecc_sets[];
|
||||
|
||||
int ecc_make_key(prng_state *prng, int wprng, int keysize, ecc_key *key);
|
||||
int ecc_test(void);
|
||||
void ecc_sizes(int *low, int *high);
|
||||
int ecc_get_size(ecc_key *key);
|
||||
|
||||
int ecc_make_key(prng_state *prng, int wprng, int keysize, ecc_key *key);
|
||||
int ecc_make_key_ex(prng_state *prng, int wprng, ecc_key *key, const ltc_ecc_set_type *dp);
|
||||
void ecc_free(ecc_key *key);
|
||||
|
||||
int ecc_export(unsigned char *out, unsigned long *outlen, int type, ecc_key *key);
|
||||
int ecc_import(const unsigned char *in, unsigned long inlen, ecc_key *key);
|
||||
int ecc_export(unsigned char *out, unsigned long *outlen, int type, ecc_key *key);
|
||||
int ecc_import(const unsigned char *in, unsigned long inlen, ecc_key *key);
|
||||
int ecc_import_ex(const unsigned char *in, unsigned long inlen, ecc_key *key, const ltc_ecc_set_type *dp);
|
||||
|
||||
int ecc_shared_secret(ecc_key *private_key, ecc_key *public_key,
|
||||
unsigned char *out, unsigned long *outlen);
|
||||
int ecc_ansi_x963_export(ecc_key *key, unsigned char *out, unsigned long *outlen);
|
||||
int ecc_ansi_x963_import(const unsigned char *in, unsigned long inlen, ecc_key *key);
|
||||
int ecc_ansi_x963_import_ex(const unsigned char *in, unsigned long inlen, ecc_key *key, ltc_ecc_set_type *dp);
|
||||
|
||||
int ecc_encrypt_key(const unsigned char *in, unsigned long inlen,
|
||||
unsigned char *out, unsigned long *outlen,
|
||||
prng_state *prng, int wprng, int hash,
|
||||
ecc_key *key);
|
||||
int ecc_shared_secret(ecc_key *private_key, ecc_key *public_key,
|
||||
unsigned char *out, unsigned long *outlen);
|
||||
|
||||
int ecc_decrypt_key(const unsigned char *in, unsigned long inlen,
|
||||
unsigned char *out, unsigned long *outlen,
|
||||
ecc_key *key);
|
||||
int ecc_encrypt_key(const unsigned char *in, unsigned long inlen,
|
||||
unsigned char *out, unsigned long *outlen,
|
||||
prng_state *prng, int wprng, int hash,
|
||||
ecc_key *key);
|
||||
|
||||
int ecc_sign_hash(const unsigned char *in, unsigned long inlen,
|
||||
unsigned char *out, unsigned long *outlen,
|
||||
prng_state *prng, int wprng, ecc_key *key);
|
||||
int ecc_decrypt_key(const unsigned char *in, unsigned long inlen,
|
||||
unsigned char *out, unsigned long *outlen,
|
||||
ecc_key *key);
|
||||
|
||||
int ecc_verify_hash(const unsigned char *sig, unsigned long siglen,
|
||||
const unsigned char *hash, unsigned long hashlen,
|
||||
int *stat, ecc_key *key);
|
||||
int ecc_sign_hash(const unsigned char *in, unsigned long inlen,
|
||||
unsigned char *out, unsigned long *outlen,
|
||||
prng_state *prng, int wprng, ecc_key *key);
|
||||
|
||||
int ecc_verify_hash(const unsigned char *sig, unsigned long siglen,
|
||||
const unsigned char *hash, unsigned long hashlen,
|
||||
int *stat, ecc_key *key);
|
||||
|
||||
/* low level functions */
|
||||
ecc_point *ltc_ecc_new_point(void);
|
||||
void ltc_ecc_del_point(ecc_point *p);
|
||||
int ltc_ecc_is_valid_idx(int n);
|
||||
|
||||
/* point ops (mp == montgomery digit) */
|
||||
#if !defined(MECC_ACCEL) || defined(LTM_DESC) || defined(GMP_DESC)
|
||||
/* R = 2P */
|
||||
int ltc_ecc_projective_dbl_point(ecc_point *P, ecc_point *R, void *modulus, void *mp);
|
||||
|
||||
/* R = P + Q */
|
||||
int ltc_ecc_projective_add_point(ecc_point *P, ecc_point *Q, ecc_point *R, void *modulus, void *mp);
|
||||
#endif
|
||||
|
||||
#if defined(MECC_FP)
|
||||
int ltc_ecc_fp_mulmod(void *k, ecc_point *G, ecc_point *R, void *modulus, int map);
|
||||
int ltc_ecc_fp_save_state(unsigned char **out, unsigned long *outlen);
|
||||
int ltc_ecc_fp_restore_state(unsigned char *in, unsigned long inlen);
|
||||
void ltc_ecc_fp_free(void);
|
||||
#endif
|
||||
|
||||
/* R = kG */
|
||||
int ltc_ecc_mulmod(void *k, ecc_point *G, ecc_point *R, void *modulus, int map);
|
||||
|
||||
#ifdef LTC_ECC_SHAMIR
|
||||
/* kA*A + kB*B = C */
|
||||
int ltc_ecc_mul2add(ecc_point *A, void *kA,
|
||||
ecc_point *B, void *kB,
|
||||
ecc_point *C,
|
||||
void *modulus);
|
||||
|
||||
#ifdef MECC_FP
|
||||
int ltc_ecc_fp_mul2add(ecc_point *A, void *kA,
|
||||
ecc_point *B, void *kB,
|
||||
ecc_point *C, void *modulus);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/* map P to affine from projective */
|
||||
int ltc_ecc_map(ecc_point *P, void *modulus, void *mp);
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef MDSA
|
||||
|
||||
/* Max diff between group and modulus size in bytes */
|
||||
#define MDSA_DELTA 512
|
||||
|
||||
/* Max DSA group size in bytes (default allows 4k-bit groups) */
|
||||
#define MDSA_MAX_GROUP 512
|
||||
|
||||
/** DSA key structure */
|
||||
typedef struct {
|
||||
int type, qord;
|
||||
mp_int g, q, p, x, y;
|
||||
/** The key type, PK_PRIVATE or PK_PUBLIC */
|
||||
int type;
|
||||
|
||||
/** The order of the sub-group used in octets */
|
||||
int qord;
|
||||
|
||||
/** The generator */
|
||||
void *g;
|
||||
|
||||
/** The prime used to generate the sub-group */
|
||||
void *q;
|
||||
|
||||
/** The large prime that generats the field the contains the sub-group */
|
||||
void *p;
|
||||
|
||||
/** The private key */
|
||||
void *x;
|
||||
|
||||
/** The public key */
|
||||
void *y;
|
||||
} dsa_key;
|
||||
|
||||
int dsa_make_key(prng_state *prng, int wprng, int group_size, int modulus_size, dsa_key *key);
|
||||
void dsa_free(dsa_key *key);
|
||||
|
||||
|
||||
int dsa_sign_hash_raw(const unsigned char *in, unsigned long inlen,
|
||||
mp_int *r, mp_int *s,
|
||||
void *r, void *s,
|
||||
prng_state *prng, int wprng, dsa_key *key);
|
||||
|
||||
int dsa_sign_hash(const unsigned char *in, unsigned long inlen,
|
||||
unsigned char *out, unsigned long *outlen,
|
||||
prng_state *prng, int wprng, dsa_key *key);
|
||||
|
||||
int dsa_verify_hash_raw( mp_int *r, mp_int *s,
|
||||
int dsa_verify_hash_raw( void *r, void *s,
|
||||
const unsigned char *hash, unsigned long hashlen,
|
||||
int *stat, dsa_key *key);
|
||||
|
||||
@@ -238,12 +341,22 @@ int dsa_verify_hash(const unsigned char *sig, unsigned long siglen,
|
||||
const unsigned char *hash, unsigned long hashlen,
|
||||
int *stat, dsa_key *key);
|
||||
|
||||
int dsa_encrypt_key(const unsigned char *in, unsigned long inlen,
|
||||
unsigned char *out, unsigned long *outlen,
|
||||
prng_state *prng, int wprng, int hash,
|
||||
dsa_key *key);
|
||||
|
||||
int dsa_decrypt_key(const unsigned char *in, unsigned long inlen,
|
||||
unsigned char *out, unsigned long *outlen,
|
||||
dsa_key *key);
|
||||
|
||||
int dsa_import(const unsigned char *in, unsigned long inlen, dsa_key *key);
|
||||
|
||||
int dsa_export(unsigned char *out, unsigned long *outlen, int type, dsa_key *key);
|
||||
|
||||
int dsa_verify_key(dsa_key *key, int *stat);
|
||||
|
||||
int dsa_shared_secret(void *private_key, void *base,
|
||||
dsa_key *public_key,
|
||||
unsigned char *out, unsigned long *outlen);
|
||||
#endif
|
||||
|
||||
#ifdef LTC_DER
|
||||
@@ -251,6 +364,7 @@ int dsa_verify_key(dsa_key *key, int *stat);
|
||||
|
||||
enum {
|
||||
LTC_ASN1_EOL,
|
||||
LTC_ASN1_BOOLEAN,
|
||||
LTC_ASN1_INTEGER,
|
||||
LTC_ASN1_SHORT_INTEGER,
|
||||
LTC_ASN1_BIT_STRING,
|
||||
@@ -259,17 +373,26 @@ enum {
|
||||
LTC_ASN1_OBJECT_IDENTIFIER,
|
||||
LTC_ASN1_IA5_STRING,
|
||||
LTC_ASN1_PRINTABLE_STRING,
|
||||
LTC_ASN1_UTF8_STRING,
|
||||
LTC_ASN1_UTCTIME,
|
||||
|
||||
LTC_ASN1_CHOICE,
|
||||
LTC_ASN1_SEQUENCE
|
||||
LTC_ASN1_SEQUENCE,
|
||||
LTC_ASN1_SET,
|
||||
LTC_ASN1_SETOF
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
/** A LTC ASN.1 list type */
|
||||
typedef struct ltc_asn1_list_ {
|
||||
/** The LTC ASN.1 enumerated type identifier */
|
||||
int type;
|
||||
/** The data to encode or place for decoding */
|
||||
void *data;
|
||||
/** The size of the input or resulting output */
|
||||
unsigned long size;
|
||||
/** The used flag, this is used by the CHOICE ASN.1 type to indicate which choice was made */
|
||||
int used;
|
||||
/** prev/next entry in the list */
|
||||
struct ltc_asn1_list_ *prev, *next, *child, *parent;
|
||||
} ltc_asn1_list;
|
||||
|
||||
#define LTC_SET_ASN1(list, index, Type, Data, Size) \
|
||||
@@ -277,29 +400,53 @@ typedef struct {
|
||||
int LTC_MACRO_temp = (index); \
|
||||
ltc_asn1_list *LTC_MACRO_list = (list); \
|
||||
LTC_MACRO_list[LTC_MACRO_temp].type = (Type); \
|
||||
LTC_MACRO_list[LTC_MACRO_temp].data = (Data); \
|
||||
LTC_MACRO_list[LTC_MACRO_temp].data = (void*)(Data); \
|
||||
LTC_MACRO_list[LTC_MACRO_temp].size = (Size); \
|
||||
LTC_MACRO_list[LTC_MACRO_temp].used = 0; \
|
||||
} while (0);
|
||||
|
||||
/* SEQUENCE */
|
||||
int der_encode_sequence(ltc_asn1_list *list, unsigned long inlen,
|
||||
unsigned char *out, unsigned long *outlen);
|
||||
int der_encode_sequence_ex(ltc_asn1_list *list, unsigned long inlen,
|
||||
unsigned char *out, unsigned long *outlen, int type_of);
|
||||
|
||||
#define der_encode_sequence(list, inlen, out, outlen) der_encode_sequence_ex(list, inlen, out, outlen, LTC_ASN1_SEQUENCE)
|
||||
|
||||
int der_decode_sequence(const unsigned char *in, unsigned long inlen,
|
||||
ltc_asn1_list *list, unsigned long outlen);
|
||||
int der_decode_sequence_ex(const unsigned char *in, unsigned long inlen,
|
||||
ltc_asn1_list *list, unsigned long outlen, int ordered);
|
||||
|
||||
#define der_decode_sequence(in, inlen, list, outlen) der_decode_sequence_ex(in, inlen, list, outlen, 1)
|
||||
|
||||
int der_length_sequence(ltc_asn1_list *list, unsigned long inlen,
|
||||
unsigned long *outlen);
|
||||
|
||||
/* VA list handy helpers */
|
||||
/* SET */
|
||||
#define der_decode_set(in, inlen, list, outlen) der_decode_sequence_ex(in, inlen, list, outlen, 0)
|
||||
#define der_length_set der_length_sequence
|
||||
int der_encode_set(ltc_asn1_list *list, unsigned long inlen,
|
||||
unsigned char *out, unsigned long *outlen);
|
||||
|
||||
int der_encode_setof(ltc_asn1_list *list, unsigned long inlen,
|
||||
unsigned char *out, unsigned long *outlen);
|
||||
|
||||
/* VA list handy helpers with triplets of <type, size, data> */
|
||||
int der_encode_sequence_multi(unsigned char *out, unsigned long *outlen, ...);
|
||||
int der_decode_sequence_multi(const unsigned char *in, unsigned long inlen, ...);
|
||||
|
||||
/* FLEXI DECODER handle unknown list decoder */
|
||||
int der_decode_sequence_flexi(const unsigned char *in, unsigned long *inlen, ltc_asn1_list **out);
|
||||
void der_free_sequence_flexi(ltc_asn1_list *list);
|
||||
void der_sequence_free(ltc_asn1_list *in);
|
||||
|
||||
/* BOOLEAN */
|
||||
int der_length_boolean(unsigned long *outlen);
|
||||
int der_encode_boolean(int in,
|
||||
unsigned char *out, unsigned long *outlen);
|
||||
int der_decode_boolean(const unsigned char *in, unsigned long inlen,
|
||||
int *out);
|
||||
/* INTEGER */
|
||||
int der_encode_integer(mp_int *num, unsigned char *out, unsigned long *outlen);
|
||||
int der_decode_integer(const unsigned char *in, unsigned long inlen, mp_int *num);
|
||||
int der_length_integer(mp_int *num, unsigned long *len);
|
||||
int der_encode_integer(void *num, unsigned char *out, unsigned long *outlen);
|
||||
int der_decode_integer(const unsigned char *in, unsigned long inlen, void *num);
|
||||
int der_length_integer(void *num, unsigned long *len);
|
||||
|
||||
/* INTEGER -- handy for 0..2^32-1 values */
|
||||
int der_decode_short_integer(const unsigned char *in, unsigned long inlen, unsigned long *num);
|
||||
@@ -348,6 +495,22 @@ int der_length_printable_string(const unsigned char *octets, unsigned long nocte
|
||||
int der_printable_char_encode(int c);
|
||||
int der_printable_value_decode(int v);
|
||||
|
||||
/* UTF-8 */
|
||||
#if (defined(SIZE_MAX) || __STDC_VERSION__ >= 199901L || defined(WCHAR_MAX) || defined(_WCHAR_T) || defined(_WCHAR_T_DEFINED)) && !defined(LTC_NO_WCHAR)
|
||||
#include <wchar.h>
|
||||
#else
|
||||
typedef ulong32 wchar_t;
|
||||
#endif
|
||||
|
||||
int der_encode_utf8_string(const wchar_t *in, unsigned long inlen,
|
||||
unsigned char *out, unsigned long *outlen);
|
||||
|
||||
int der_decode_utf8_string(const unsigned char *in, unsigned long inlen,
|
||||
wchar_t *out, unsigned long *outlen);
|
||||
unsigned long der_utf8_charsize(const wchar_t c);
|
||||
int der_length_utf8_string(const wchar_t *in, unsigned long noctets, unsigned long *outlen);
|
||||
|
||||
|
||||
/* CHOICE */
|
||||
int der_decode_choice(const unsigned char *in, unsigned long *inlen,
|
||||
ltc_asn1_list *list, unsigned long outlen);
|
||||
@@ -377,5 +540,5 @@ int der_length_utctime(ltc_utctime *utctime, unsigned long *outlen);
|
||||
#endif
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/headers/tomcrypt_pk.h,v $ */
|
||||
/* $Revision: 1.30 $ */
|
||||
/* $Date: 2005/06/19 11:23:03 $ */
|
||||
/* $Revision: 1.77 $ */
|
||||
/* $Date: 2006/12/03 00:39:56 $ */
|
||||
|
||||
@@ -3,12 +3,43 @@
|
||||
/* ===> PKCS #1 -- RSA Cryptography <=== */
|
||||
#ifdef PKCS_1
|
||||
|
||||
int pkcs_1_mgf1(const unsigned char *seed, unsigned long seedlen,
|
||||
int hash_idx,
|
||||
enum ltc_pkcs_1_v1_5_blocks
|
||||
{
|
||||
LTC_PKCS_1_EMSA = 1, /* Block type 1 (PKCS #1 v1.5 signature padding) */
|
||||
LTC_PKCS_1_EME = 2 /* Block type 2 (PKCS #1 v1.5 encryption padding) */
|
||||
};
|
||||
|
||||
enum ltc_pkcs_1_paddings
|
||||
{
|
||||
LTC_PKCS_1_V1_5 = 1, /* PKCS #1 v1.5 padding (\sa ltc_pkcs_1_v1_5_blocks) */
|
||||
LTC_PKCS_1_OAEP = 2, /* PKCS #1 v2.0 encryption padding */
|
||||
LTC_PKCS_1_PSS = 3 /* PKCS #1 v2.1 signature padding */
|
||||
};
|
||||
|
||||
int pkcs_1_mgf1( int hash_idx,
|
||||
const unsigned char *seed, unsigned long seedlen,
|
||||
unsigned char *mask, unsigned long masklen);
|
||||
|
||||
int pkcs_1_i2osp(mp_int *n, unsigned long modulus_len, unsigned char *out);
|
||||
int pkcs_1_os2ip(mp_int *n, unsigned char *in, unsigned long inlen);
|
||||
int pkcs_1_i2osp(void *n, unsigned long modulus_len, unsigned char *out);
|
||||
int pkcs_1_os2ip(void *n, unsigned char *in, unsigned long inlen);
|
||||
|
||||
/* *** v1.5 padding */
|
||||
int pkcs_1_v1_5_encode(const unsigned char *msg,
|
||||
unsigned long msglen,
|
||||
int block_type,
|
||||
unsigned long modulus_bitlen,
|
||||
prng_state *prng,
|
||||
int prng_idx,
|
||||
unsigned char *out,
|
||||
unsigned long *outlen);
|
||||
|
||||
int pkcs_1_v1_5_decode(const unsigned char *msg,
|
||||
unsigned long msglen,
|
||||
int block_type,
|
||||
unsigned long modulus_bitlen,
|
||||
unsigned char *out,
|
||||
unsigned long *outlen,
|
||||
int *is_valid);
|
||||
|
||||
/* *** v2.1 padding */
|
||||
int pkcs_1_oaep_encode(const unsigned char *msg, unsigned long msglen,
|
||||
@@ -54,5 +85,5 @@ int pkcs_5_alg2(const unsigned char *password, unsigned long password_len,
|
||||
#endif /* PKCS_5 */
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/headers/tomcrypt_pkcs.h,v $ */
|
||||
/* $Revision: 1.3 $ */
|
||||
/* $Date: 2005/05/14 11:46:08 $ */
|
||||
/* $Revision: 1.7 $ */
|
||||
/* $Date: 2006/11/15 12:44:59 $ */
|
||||
|
||||
@@ -4,6 +4,7 @@ struct yarrow_prng {
|
||||
int cipher, hash;
|
||||
unsigned char pool[MAXBLOCKSIZE];
|
||||
symmetric_CTR ctr;
|
||||
LTC_MUTEX_TYPE(prng_lock)
|
||||
};
|
||||
#endif
|
||||
|
||||
@@ -28,6 +29,7 @@ struct fortuna_prng {
|
||||
wd;
|
||||
|
||||
ulong64 reset_cnt; /* number of times we have reset */
|
||||
LTC_MUTEX_TYPE(prng_lock)
|
||||
};
|
||||
#endif
|
||||
|
||||
@@ -46,6 +48,7 @@ struct sober128_prng {
|
||||
#endif
|
||||
|
||||
typedef union Prng_state {
|
||||
char dummy[1];
|
||||
#ifdef YARROW
|
||||
struct yarrow_prng yarrow;
|
||||
#endif
|
||||
@@ -60,6 +63,7 @@ typedef union Prng_state {
|
||||
#endif
|
||||
} prng_state;
|
||||
|
||||
/** PRNG descriptor */
|
||||
extern struct ltc_prng_descriptor {
|
||||
/** Name of the PRNG */
|
||||
char *name;
|
||||
@@ -178,7 +182,7 @@ int find_prng(const char *name);
|
||||
int register_prng(const struct ltc_prng_descriptor *prng);
|
||||
int unregister_prng(const struct ltc_prng_descriptor *prng);
|
||||
int prng_is_valid(int idx);
|
||||
LTC_MUTEX_PROTO(ltc_prng_mutex);
|
||||
LTC_MUTEX_PROTO(ltc_prng_mutex)
|
||||
|
||||
/* Slow RNG you **might** be able to use to seed a PRNG with. Be careful as this
|
||||
* might not work on all platforms as planned
|
||||
@@ -191,5 +195,5 @@ int rng_make_prng(int bits, int wprng, prng_state *prng, void (*callback)(void))
|
||||
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/headers/tomcrypt_prng.h,v $ */
|
||||
/* $Revision: 1.3 $ */
|
||||
/* $Date: 2005/06/19 18:00:28 $ */
|
||||
/* $Revision: 1.8 $ */
|
||||
/* $Date: 2006/11/05 01:36:43 $ */
|
||||
|
||||
@@ -1,998 +0,0 @@
|
||||
#if !(defined(LTM1) && defined(LTM2) && defined(LTM3))
|
||||
#if defined(LTM2)
|
||||
#define LTM3
|
||||
#endif
|
||||
#if defined(LTM1)
|
||||
#define LTM2
|
||||
#endif
|
||||
#define LTM1
|
||||
|
||||
#if defined(LTM_ALL)
|
||||
#define BN_ERROR_C
|
||||
#define BN_FAST_MP_INVMOD_C
|
||||
#define BN_FAST_MP_MONTGOMERY_REDUCE_C
|
||||
#define BN_FAST_S_MP_MUL_DIGS_C
|
||||
#define BN_FAST_S_MP_MUL_HIGH_DIGS_C
|
||||
#define BN_FAST_S_MP_SQR_C
|
||||
#define BN_MP_2EXPT_C
|
||||
#define BN_MP_ABS_C
|
||||
#define BN_MP_ADD_C
|
||||
#define BN_MP_ADD_D_C
|
||||
#define BN_MP_ADDMOD_C
|
||||
#define BN_MP_AND_C
|
||||
#define BN_MP_CLAMP_C
|
||||
#define BN_MP_CLEAR_C
|
||||
#define BN_MP_CLEAR_MULTI_C
|
||||
#define BN_MP_CMP_C
|
||||
#define BN_MP_CMP_D_C
|
||||
#define BN_MP_CMP_MAG_C
|
||||
#define BN_MP_CNT_LSB_C
|
||||
#define BN_MP_COPY_C
|
||||
#define BN_MP_COUNT_BITS_C
|
||||
#define BN_MP_DIV_C
|
||||
#define BN_MP_DIV_2_C
|
||||
#define BN_MP_DIV_2D_C
|
||||
#define BN_MP_DIV_3_C
|
||||
#define BN_MP_DIV_D_C
|
||||
#define BN_MP_DR_IS_MODULUS_C
|
||||
#define BN_MP_DR_REDUCE_C
|
||||
#define BN_MP_DR_SETUP_C
|
||||
#define BN_MP_EXCH_C
|
||||
#define BN_MP_EXPT_D_C
|
||||
#define BN_MP_EXPTMOD_C
|
||||
#define BN_MP_EXPTMOD_FAST_C
|
||||
#define BN_MP_EXTEUCLID_C
|
||||
#define BN_MP_FREAD_C
|
||||
#define BN_MP_FWRITE_C
|
||||
#define BN_MP_GCD_C
|
||||
#define BN_MP_GET_INT_C
|
||||
#define BN_MP_GROW_C
|
||||
#define BN_MP_INIT_C
|
||||
#define BN_MP_INIT_COPY_C
|
||||
#define BN_MP_INIT_MULTI_C
|
||||
#define BN_MP_INIT_SET_C
|
||||
#define BN_MP_INIT_SET_INT_C
|
||||
#define BN_MP_INIT_SIZE_C
|
||||
#define BN_MP_INVMOD_C
|
||||
#define BN_MP_INVMOD_SLOW_C
|
||||
#define BN_MP_IS_SQUARE_C
|
||||
#define BN_MP_JACOBI_C
|
||||
#define BN_MP_KARATSUBA_MUL_C
|
||||
#define BN_MP_KARATSUBA_SQR_C
|
||||
#define BN_MP_LCM_C
|
||||
#define BN_MP_LSHD_C
|
||||
#define BN_MP_MOD_C
|
||||
#define BN_MP_MOD_2D_C
|
||||
#define BN_MP_MOD_D_C
|
||||
#define BN_MP_MONTGOMERY_CALC_NORMALIZATION_C
|
||||
#define BN_MP_MONTGOMERY_REDUCE_C
|
||||
#define BN_MP_MONTGOMERY_SETUP_C
|
||||
#define BN_MP_MUL_C
|
||||
#define BN_MP_MUL_2_C
|
||||
#define BN_MP_MUL_2D_C
|
||||
#define BN_MP_MUL_D_C
|
||||
#define BN_MP_MULMOD_C
|
||||
#define BN_MP_N_ROOT_C
|
||||
#define BN_MP_NEG_C
|
||||
#define BN_MP_OR_C
|
||||
#define BN_MP_PRIME_FERMAT_C
|
||||
#define BN_MP_PRIME_IS_DIVISIBLE_C
|
||||
#define BN_MP_PRIME_IS_PRIME_C
|
||||
#define BN_MP_PRIME_MILLER_RABIN_C
|
||||
#define BN_MP_PRIME_NEXT_PRIME_C
|
||||
#define BN_MP_PRIME_RABIN_MILLER_TRIALS_C
|
||||
#define BN_MP_PRIME_RANDOM_EX_C
|
||||
#define BN_MP_RADIX_SIZE_C
|
||||
#define BN_MP_RADIX_SMAP_C
|
||||
#define BN_MP_RAND_C
|
||||
#define BN_MP_READ_RADIX_C
|
||||
#define BN_MP_READ_SIGNED_BIN_C
|
||||
#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
|
||||
#define BN_MP_SET_INT_C
|
||||
#define BN_MP_SHRINK_C
|
||||
#define BN_MP_SIGNED_BIN_SIZE_C
|
||||
#define BN_MP_SQR_C
|
||||
#define BN_MP_SQRMOD_C
|
||||
#define BN_MP_SQRT_C
|
||||
#define BN_MP_SUB_C
|
||||
#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
|
||||
#define BN_MP_TORADIX_N_C
|
||||
#define BN_MP_UNSIGNED_BIN_SIZE_C
|
||||
#define BN_MP_XOR_C
|
||||
#define BN_MP_ZERO_C
|
||||
#define BN_PRIME_TAB_C
|
||||
#define BN_REVERSE_C
|
||||
#define BN_S_MP_ADD_C
|
||||
#define BN_S_MP_EXPTMOD_C
|
||||
#define BN_S_MP_MUL_DIGS_C
|
||||
#define BN_S_MP_MUL_HIGH_DIGS_C
|
||||
#define BN_S_MP_SQR_C
|
||||
#define BN_S_MP_SUB_C
|
||||
#define BNCORE_C
|
||||
#endif
|
||||
|
||||
#if defined(BN_ERROR_C)
|
||||
#define BN_MP_ERROR_TO_STRING_C
|
||||
#endif
|
||||
|
||||
#if defined(BN_FAST_MP_INVMOD_C)
|
||||
#define BN_MP_ISEVEN_C
|
||||
#define BN_MP_INIT_MULTI_C
|
||||
#define BN_MP_COPY_C
|
||||
#define BN_MP_MOD_C
|
||||
#define BN_MP_SET_C
|
||||
#define BN_MP_DIV_2_C
|
||||
#define BN_MP_ISODD_C
|
||||
#define BN_MP_SUB_C
|
||||
#define BN_MP_CMP_C
|
||||
#define BN_MP_ISZERO_C
|
||||
#define BN_MP_CMP_D_C
|
||||
#define BN_MP_ADD_C
|
||||
#define BN_MP_EXCH_C
|
||||
#define BN_MP_CLEAR_MULTI_C
|
||||
#endif
|
||||
|
||||
#if defined(BN_FAST_MP_MONTGOMERY_REDUCE_C)
|
||||
#define BN_MP_GROW_C
|
||||
#define BN_MP_RSHD_C
|
||||
#define BN_MP_CLAMP_C
|
||||
#define BN_MP_CMP_MAG_C
|
||||
#define BN_S_MP_SUB_C
|
||||
#endif
|
||||
|
||||
#if defined(BN_FAST_S_MP_MUL_DIGS_C)
|
||||
#define BN_MP_GROW_C
|
||||
#define BN_MP_CLAMP_C
|
||||
#endif
|
||||
|
||||
#if defined(BN_FAST_S_MP_MUL_HIGH_DIGS_C)
|
||||
#define BN_MP_GROW_C
|
||||
#define BN_MP_CLAMP_C
|
||||
#endif
|
||||
|
||||
#if defined(BN_FAST_S_MP_SQR_C)
|
||||
#define BN_MP_GROW_C
|
||||
#define BN_MP_CLAMP_C
|
||||
#endif
|
||||
|
||||
#if defined(BN_MP_2EXPT_C)
|
||||
#define BN_MP_ZERO_C
|
||||
#define BN_MP_GROW_C
|
||||
#endif
|
||||
|
||||
#if defined(BN_MP_ABS_C)
|
||||
#define BN_MP_COPY_C
|
||||
#endif
|
||||
|
||||
#if defined(BN_MP_ADD_C)
|
||||
#define BN_S_MP_ADD_C
|
||||
#define BN_MP_CMP_MAG_C
|
||||
#define BN_S_MP_SUB_C
|
||||
#endif
|
||||
|
||||
#if defined(BN_MP_ADD_D_C)
|
||||
#define BN_MP_GROW_C
|
||||
#define BN_MP_SUB_D_C
|
||||
#define BN_MP_CLAMP_C
|
||||
#endif
|
||||
|
||||
#if defined(BN_MP_ADDMOD_C)
|
||||
#define BN_MP_INIT_C
|
||||
#define BN_MP_ADD_C
|
||||
#define BN_MP_CLEAR_C
|
||||
#define BN_MP_MOD_C
|
||||
#endif
|
||||
|
||||
#if defined(BN_MP_AND_C)
|
||||
#define BN_MP_INIT_COPY_C
|
||||
#define BN_MP_CLAMP_C
|
||||
#define BN_MP_EXCH_C
|
||||
#define BN_MP_CLEAR_C
|
||||
#endif
|
||||
|
||||
#if defined(BN_MP_CLAMP_C)
|
||||
#endif
|
||||
|
||||
#if defined(BN_MP_CLEAR_C)
|
||||
#endif
|
||||
|
||||
#if defined(BN_MP_CLEAR_MULTI_C)
|
||||
#define BN_MP_CLEAR_C
|
||||
#endif
|
||||
|
||||
#if defined(BN_MP_CMP_C)
|
||||
#define BN_MP_CMP_MAG_C
|
||||
#endif
|
||||
|
||||
#if defined(BN_MP_CMP_D_C)
|
||||
#endif
|
||||
|
||||
#if defined(BN_MP_CMP_MAG_C)
|
||||
#endif
|
||||
|
||||
#if defined(BN_MP_CNT_LSB_C)
|
||||
#define BN_MP_ISZERO_C
|
||||
#endif
|
||||
|
||||
#if defined(BN_MP_COPY_C)
|
||||
#define BN_MP_GROW_C
|
||||
#endif
|
||||
|
||||
#if defined(BN_MP_COUNT_BITS_C)
|
||||
#endif
|
||||
|
||||
#if defined(BN_MP_DIV_C)
|
||||
#define BN_MP_ISZERO_C
|
||||
#define BN_MP_CMP_MAG_C
|
||||
#define BN_MP_COPY_C
|
||||
#define BN_MP_ZERO_C
|
||||
#define BN_MP_INIT_MULTI_C
|
||||
#define BN_MP_SET_C
|
||||
#define BN_MP_COUNT_BITS_C
|
||||
#define BN_MP_ABS_C
|
||||
#define BN_MP_MUL_2D_C
|
||||
#define BN_MP_CMP_C
|
||||
#define BN_MP_SUB_C
|
||||
#define BN_MP_ADD_C
|
||||
#define BN_MP_DIV_2D_C
|
||||
#define BN_MP_EXCH_C
|
||||
#define BN_MP_CLEAR_MULTI_C
|
||||
#define BN_MP_INIT_SIZE_C
|
||||
#define BN_MP_INIT_C
|
||||
#define BN_MP_INIT_COPY_C
|
||||
#define BN_MP_LSHD_C
|
||||
#define BN_MP_RSHD_C
|
||||
#define BN_MP_MUL_D_C
|
||||
#define BN_MP_CLAMP_C
|
||||
#define BN_MP_CLEAR_C
|
||||
#endif
|
||||
|
||||
#if defined(BN_MP_DIV_2_C)
|
||||
#define BN_MP_GROW_C
|
||||
#define BN_MP_CLAMP_C
|
||||
#endif
|
||||
|
||||
#if defined(BN_MP_DIV_2D_C)
|
||||
#define BN_MP_COPY_C
|
||||
#define BN_MP_ZERO_C
|
||||
#define BN_MP_INIT_C
|
||||
#define BN_MP_MOD_2D_C
|
||||
#define BN_MP_CLEAR_C
|
||||
#define BN_MP_RSHD_C
|
||||
#define BN_MP_CLAMP_C
|
||||
#define BN_MP_EXCH_C
|
||||
#endif
|
||||
|
||||
#if defined(BN_MP_DIV_3_C)
|
||||
#define BN_MP_INIT_SIZE_C
|
||||
#define BN_MP_CLAMP_C
|
||||
#define BN_MP_EXCH_C
|
||||
#define BN_MP_CLEAR_C
|
||||
#endif
|
||||
|
||||
#if defined(BN_MP_DIV_D_C)
|
||||
#define BN_MP_ISZERO_C
|
||||
#define BN_MP_COPY_C
|
||||
#define BN_MP_DIV_2D_C
|
||||
#define BN_MP_DIV_3_C
|
||||
#define BN_MP_INIT_SIZE_C
|
||||
#define BN_MP_CLAMP_C
|
||||
#define BN_MP_EXCH_C
|
||||
#define BN_MP_CLEAR_C
|
||||
#endif
|
||||
|
||||
#if defined(BN_MP_DR_IS_MODULUS_C)
|
||||
#endif
|
||||
|
||||
#if defined(BN_MP_DR_REDUCE_C)
|
||||
#define BN_MP_GROW_C
|
||||
#define BN_MP_CLAMP_C
|
||||
#define BN_MP_CMP_MAG_C
|
||||
#define BN_S_MP_SUB_C
|
||||
#endif
|
||||
|
||||
#if defined(BN_MP_DR_SETUP_C)
|
||||
#endif
|
||||
|
||||
#if defined(BN_MP_EXCH_C)
|
||||
#endif
|
||||
|
||||
#if defined(BN_MP_EXPT_D_C)
|
||||
#define BN_MP_INIT_COPY_C
|
||||
#define BN_MP_SET_C
|
||||
#define BN_MP_SQR_C
|
||||
#define BN_MP_CLEAR_C
|
||||
#define BN_MP_MUL_C
|
||||
#endif
|
||||
|
||||
#if defined(BN_MP_EXPTMOD_C)
|
||||
#define BN_MP_INIT_C
|
||||
#define BN_MP_INVMOD_C
|
||||
#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
|
||||
#endif
|
||||
|
||||
#if defined(BN_MP_EXPTMOD_FAST_C)
|
||||
#define BN_MP_COUNT_BITS_C
|
||||
#define BN_MP_INIT_C
|
||||
#define BN_MP_CLEAR_C
|
||||
#define BN_MP_MONTGOMERY_SETUP_C
|
||||
#define BN_FAST_MP_MONTGOMERY_REDUCE_C
|
||||
#define BN_MP_MONTGOMERY_REDUCE_C
|
||||
#define BN_MP_DR_SETUP_C
|
||||
#define BN_MP_DR_REDUCE_C
|
||||
#define BN_MP_REDUCE_2K_SETUP_C
|
||||
#define BN_MP_REDUCE_2K_C
|
||||
#define BN_MP_MONTGOMERY_CALC_NORMALIZATION_C
|
||||
#define BN_MP_MULMOD_C
|
||||
#define BN_MP_SET_C
|
||||
#define BN_MP_MOD_C
|
||||
#define BN_MP_COPY_C
|
||||
#define BN_MP_SQR_C
|
||||
#define BN_MP_MUL_C
|
||||
#define BN_MP_EXCH_C
|
||||
#endif
|
||||
|
||||
#if defined(BN_MP_EXTEUCLID_C)
|
||||
#define BN_MP_INIT_MULTI_C
|
||||
#define BN_MP_SET_C
|
||||
#define BN_MP_COPY_C
|
||||
#define BN_MP_ISZERO_C
|
||||
#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
|
||||
|
||||
#if defined(BN_MP_FREAD_C)
|
||||
#define BN_MP_ZERO_C
|
||||
#define BN_MP_S_RMAP_C
|
||||
#define BN_MP_MUL_D_C
|
||||
#define BN_MP_ADD_D_C
|
||||
#define BN_MP_CMP_D_C
|
||||
#endif
|
||||
|
||||
#if defined(BN_MP_FWRITE_C)
|
||||
#define BN_MP_RADIX_SIZE_C
|
||||
#define BN_MP_TORADIX_C
|
||||
#endif
|
||||
|
||||
#if defined(BN_MP_GCD_C)
|
||||
#define BN_MP_ISZERO_C
|
||||
#define BN_MP_ABS_C
|
||||
#define BN_MP_ZERO_C
|
||||
#define BN_MP_INIT_COPY_C
|
||||
#define BN_MP_CNT_LSB_C
|
||||
#define BN_MP_DIV_2D_C
|
||||
#define BN_MP_CMP_MAG_C
|
||||
#define BN_MP_EXCH_C
|
||||
#define BN_S_MP_SUB_C
|
||||
#define BN_MP_MUL_2D_C
|
||||
#define BN_MP_CLEAR_C
|
||||
#endif
|
||||
|
||||
#if defined(BN_MP_GET_INT_C)
|
||||
#endif
|
||||
|
||||
#if defined(BN_MP_GROW_C)
|
||||
#endif
|
||||
|
||||
#if defined(BN_MP_INIT_C)
|
||||
#endif
|
||||
|
||||
#if defined(BN_MP_INIT_COPY_C)
|
||||
#define BN_MP_COPY_C
|
||||
#endif
|
||||
|
||||
#if defined(BN_MP_INIT_MULTI_C)
|
||||
#define BN_MP_ERR_C
|
||||
#define BN_MP_INIT_C
|
||||
#define BN_MP_CLEAR_C
|
||||
#endif
|
||||
|
||||
#if defined(BN_MP_INIT_SET_C)
|
||||
#define BN_MP_INIT_C
|
||||
#define BN_MP_SET_C
|
||||
#endif
|
||||
|
||||
#if defined(BN_MP_INIT_SET_INT_C)
|
||||
#define BN_MP_INIT_C
|
||||
#define BN_MP_SET_INT_C
|
||||
#endif
|
||||
|
||||
#if defined(BN_MP_INIT_SIZE_C)
|
||||
#define BN_MP_INIT_C
|
||||
#endif
|
||||
|
||||
#if defined(BN_MP_INVMOD_C)
|
||||
#define BN_MP_ISZERO_C
|
||||
#define BN_MP_ISODD_C
|
||||
#define BN_FAST_MP_INVMOD_C
|
||||
#define BN_MP_INVMOD_SLOW_C
|
||||
#endif
|
||||
|
||||
#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
|
||||
#define BN_MP_DIV_2_C
|
||||
#define BN_MP_ISODD_C
|
||||
#define BN_MP_ADD_C
|
||||
#define BN_MP_SUB_C
|
||||
#define BN_MP_CMP_C
|
||||
#define BN_MP_CMP_D_C
|
||||
#define BN_MP_CMP_MAG_C
|
||||
#define BN_MP_EXCH_C
|
||||
#define BN_MP_CLEAR_MULTI_C
|
||||
#endif
|
||||
|
||||
#if defined(BN_MP_IS_SQUARE_C)
|
||||
#define BN_MP_MOD_D_C
|
||||
#define BN_MP_INIT_SET_INT_C
|
||||
#define BN_MP_MOD_C
|
||||
#define BN_MP_GET_INT_C
|
||||
#define BN_MP_SQRT_C
|
||||
#define BN_MP_SQR_C
|
||||
#define BN_MP_CMP_MAG_C
|
||||
#define BN_MP_CLEAR_C
|
||||
#endif
|
||||
|
||||
#if defined(BN_MP_JACOBI_C)
|
||||
#define BN_MP_CMP_D_C
|
||||
#define BN_MP_ISZERO_C
|
||||
#define BN_MP_INIT_COPY_C
|
||||
#define BN_MP_CNT_LSB_C
|
||||
#define BN_MP_DIV_2D_C
|
||||
#define BN_MP_MOD_C
|
||||
#define BN_MP_CLEAR_C
|
||||
#endif
|
||||
|
||||
#if defined(BN_MP_KARATSUBA_MUL_C)
|
||||
#define BN_MP_MUL_C
|
||||
#define BN_MP_INIT_SIZE_C
|
||||
#define BN_MP_CLAMP_C
|
||||
#define BN_MP_SUB_C
|
||||
#define BN_MP_ADD_C
|
||||
#define BN_MP_LSHD_C
|
||||
#define BN_MP_CLEAR_C
|
||||
#endif
|
||||
|
||||
#if defined(BN_MP_KARATSUBA_SQR_C)
|
||||
#define BN_MP_INIT_SIZE_C
|
||||
#define BN_MP_CLAMP_C
|
||||
#define BN_MP_SQR_C
|
||||
#define BN_MP_SUB_C
|
||||
#define BN_S_MP_ADD_C
|
||||
#define BN_MP_LSHD_C
|
||||
#define BN_MP_ADD_C
|
||||
#define BN_MP_CLEAR_C
|
||||
#endif
|
||||
|
||||
#if defined(BN_MP_LCM_C)
|
||||
#define BN_MP_INIT_MULTI_C
|
||||
#define BN_MP_GCD_C
|
||||
#define BN_MP_CMP_MAG_C
|
||||
#define BN_MP_DIV_C
|
||||
#define BN_MP_MUL_C
|
||||
#define BN_MP_CLEAR_MULTI_C
|
||||
#endif
|
||||
|
||||
#if defined(BN_MP_LSHD_C)
|
||||
#define BN_MP_GROW_C
|
||||
#define BN_MP_RSHD_C
|
||||
#endif
|
||||
|
||||
#if defined(BN_MP_MOD_C)
|
||||
#define BN_MP_INIT_C
|
||||
#define BN_MP_DIV_C
|
||||
#define BN_MP_CLEAR_C
|
||||
#define BN_MP_ADD_C
|
||||
#define BN_MP_EXCH_C
|
||||
#endif
|
||||
|
||||
#if defined(BN_MP_MOD_2D_C)
|
||||
#define BN_MP_ZERO_C
|
||||
#define BN_MP_COPY_C
|
||||
#define BN_MP_CLAMP_C
|
||||
#endif
|
||||
|
||||
#if defined(BN_MP_MOD_D_C)
|
||||
#define BN_MP_DIV_D_C
|
||||
#endif
|
||||
|
||||
#if defined(BN_MP_MONTGOMERY_CALC_NORMALIZATION_C)
|
||||
#define BN_MP_COUNT_BITS_C
|
||||
#define BN_MP_2EXPT_C
|
||||
#define BN_MP_SET_C
|
||||
#define BN_MP_MUL_2_C
|
||||
#define BN_MP_CMP_MAG_C
|
||||
#define BN_S_MP_SUB_C
|
||||
#endif
|
||||
|
||||
#if defined(BN_MP_MONTGOMERY_REDUCE_C)
|
||||
#define BN_FAST_MP_MONTGOMERY_REDUCE_C
|
||||
#define BN_MP_GROW_C
|
||||
#define BN_MP_CLAMP_C
|
||||
#define BN_MP_RSHD_C
|
||||
#define BN_MP_CMP_MAG_C
|
||||
#define BN_S_MP_SUB_C
|
||||
#endif
|
||||
|
||||
#if defined(BN_MP_MONTGOMERY_SETUP_C)
|
||||
#endif
|
||||
|
||||
#if defined(BN_MP_MUL_C)
|
||||
#define BN_MP_TOOM_MUL_C
|
||||
#define BN_MP_KARATSUBA_MUL_C
|
||||
#define BN_FAST_S_MP_MUL_DIGS_C
|
||||
#define BN_S_MP_MUL_C
|
||||
#define BN_S_MP_MUL_DIGS_C
|
||||
#endif
|
||||
|
||||
#if defined(BN_MP_MUL_2_C)
|
||||
#define BN_MP_GROW_C
|
||||
#endif
|
||||
|
||||
#if defined(BN_MP_MUL_2D_C)
|
||||
#define BN_MP_COPY_C
|
||||
#define BN_MP_GROW_C
|
||||
#define BN_MP_LSHD_C
|
||||
#define BN_MP_CLAMP_C
|
||||
#endif
|
||||
|
||||
#if defined(BN_MP_MUL_D_C)
|
||||
#define BN_MP_GROW_C
|
||||
#define BN_MP_CLAMP_C
|
||||
#endif
|
||||
|
||||
#if defined(BN_MP_MULMOD_C)
|
||||
#define BN_MP_INIT_C
|
||||
#define BN_MP_MUL_C
|
||||
#define BN_MP_CLEAR_C
|
||||
#define BN_MP_MOD_C
|
||||
#endif
|
||||
|
||||
#if defined(BN_MP_N_ROOT_C)
|
||||
#define BN_MP_INIT_C
|
||||
#define BN_MP_SET_C
|
||||
#define BN_MP_COPY_C
|
||||
#define BN_MP_EXPT_D_C
|
||||
#define BN_MP_MUL_C
|
||||
#define BN_MP_SUB_C
|
||||
#define BN_MP_MUL_D_C
|
||||
#define BN_MP_DIV_C
|
||||
#define BN_MP_CMP_C
|
||||
#define BN_MP_SUB_D_C
|
||||
#define BN_MP_EXCH_C
|
||||
#define BN_MP_CLEAR_C
|
||||
#endif
|
||||
|
||||
#if defined(BN_MP_NEG_C)
|
||||
#define BN_MP_COPY_C
|
||||
#define BN_MP_ISZERO_C
|
||||
#endif
|
||||
|
||||
#if defined(BN_MP_OR_C)
|
||||
#define BN_MP_INIT_COPY_C
|
||||
#define BN_MP_CLAMP_C
|
||||
#define BN_MP_EXCH_C
|
||||
#define BN_MP_CLEAR_C
|
||||
#endif
|
||||
|
||||
#if defined(BN_MP_PRIME_FERMAT_C)
|
||||
#define BN_MP_CMP_D_C
|
||||
#define BN_MP_INIT_C
|
||||
#define BN_MP_EXPTMOD_C
|
||||
#define BN_MP_CMP_C
|
||||
#define BN_MP_CLEAR_C
|
||||
#endif
|
||||
|
||||
#if defined(BN_MP_PRIME_IS_DIVISIBLE_C)
|
||||
#define BN_MP_MOD_D_C
|
||||
#endif
|
||||
|
||||
#if defined(BN_MP_PRIME_IS_PRIME_C)
|
||||
#define BN_MP_CMP_D_C
|
||||
#define BN_MP_PRIME_IS_DIVISIBLE_C
|
||||
#define BN_MP_INIT_C
|
||||
#define BN_MP_SET_C
|
||||
#define BN_MP_PRIME_MILLER_RABIN_C
|
||||
#define BN_MP_CLEAR_C
|
||||
#endif
|
||||
|
||||
#if defined(BN_MP_PRIME_MILLER_RABIN_C)
|
||||
#define BN_MP_CMP_D_C
|
||||
#define BN_MP_INIT_COPY_C
|
||||
#define BN_MP_SUB_D_C
|
||||
#define BN_MP_CNT_LSB_C
|
||||
#define BN_MP_DIV_2D_C
|
||||
#define BN_MP_EXPTMOD_C
|
||||
#define BN_MP_CMP_C
|
||||
#define BN_MP_SQRMOD_C
|
||||
#define BN_MP_CLEAR_C
|
||||
#endif
|
||||
|
||||
#if defined(BN_MP_PRIME_NEXT_PRIME_C)
|
||||
#define BN_MP_CMP_D_C
|
||||
#define BN_MP_SET_C
|
||||
#define BN_MP_SUB_D_C
|
||||
#define BN_MP_ISEVEN_C
|
||||
#define BN_MP_MOD_D_C
|
||||
#define BN_MP_INIT_C
|
||||
#define BN_MP_ADD_D_C
|
||||
#define BN_MP_PRIME_MILLER_RABIN_C
|
||||
#define BN_MP_CLEAR_C
|
||||
#endif
|
||||
|
||||
#if defined(BN_MP_PRIME_RABIN_MILLER_TRIALS_C)
|
||||
#endif
|
||||
|
||||
#if defined(BN_MP_PRIME_RANDOM_EX_C)
|
||||
#define BN_MP_READ_UNSIGNED_BIN_C
|
||||
#define BN_MP_PRIME_IS_PRIME_C
|
||||
#define BN_MP_SUB_D_C
|
||||
#define BN_MP_DIV_2_C
|
||||
#define BN_MP_MUL_2_C
|
||||
#define BN_MP_ADD_D_C
|
||||
#endif
|
||||
|
||||
#if defined(BN_MP_RADIX_SIZE_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
|
||||
|
||||
#if defined(BN_MP_RADIX_SMAP_C)
|
||||
#define BN_MP_S_RMAP_C
|
||||
#endif
|
||||
|
||||
#if defined(BN_MP_RAND_C)
|
||||
#define BN_MP_ZERO_C
|
||||
#define BN_MP_ADD_D_C
|
||||
#define BN_MP_LSHD_C
|
||||
#endif
|
||||
|
||||
#if defined(BN_MP_READ_RADIX_C)
|
||||
#define BN_MP_ZERO_C
|
||||
#define BN_MP_S_RMAP_C
|
||||
#define BN_MP_MUL_D_C
|
||||
#define BN_MP_ADD_D_C
|
||||
#define BN_MP_ISZERO_C
|
||||
#endif
|
||||
|
||||
#if defined(BN_MP_READ_SIGNED_BIN_C)
|
||||
#define BN_MP_READ_UNSIGNED_BIN_C
|
||||
#endif
|
||||
|
||||
#if defined(BN_MP_READ_UNSIGNED_BIN_C)
|
||||
#define BN_MP_GROW_C
|
||||
#define BN_MP_ZERO_C
|
||||
#define BN_MP_MUL_2D_C
|
||||
#define BN_MP_CLAMP_C
|
||||
#endif
|
||||
|
||||
#if defined(BN_MP_REDUCE_C)
|
||||
#define BN_MP_REDUCE_SETUP_C
|
||||
#define BN_MP_INIT_COPY_C
|
||||
#define BN_MP_RSHD_C
|
||||
#define BN_MP_MUL_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
|
||||
#define BN_MP_CMP_D_C
|
||||
#define BN_MP_SET_C
|
||||
#define BN_MP_LSHD_C
|
||||
#define BN_MP_ADD_C
|
||||
#define BN_MP_CMP_C
|
||||
#define BN_S_MP_SUB_C
|
||||
#define BN_MP_CLEAR_C
|
||||
#endif
|
||||
|
||||
#if defined(BN_MP_REDUCE_2K_C)
|
||||
#define BN_MP_INIT_C
|
||||
#define BN_MP_COUNT_BITS_C
|
||||
#define BN_MP_DIV_2D_C
|
||||
#define BN_MP_MUL_D_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_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
|
||||
#define BN_MP_2EXPT_C
|
||||
#define BN_MP_CLEAR_C
|
||||
#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
|
||||
#endif
|
||||
|
||||
#if defined(BN_MP_RSHD_C)
|
||||
#define BN_MP_ZERO_C
|
||||
#endif
|
||||
|
||||
#if defined(BN_MP_SET_C)
|
||||
#define BN_MP_ZERO_C
|
||||
#endif
|
||||
|
||||
#if defined(BN_MP_SET_INT_C)
|
||||
#define BN_MP_ZERO_C
|
||||
#define BN_MP_MUL_2D_C
|
||||
#define BN_MP_CLAMP_C
|
||||
#endif
|
||||
|
||||
#if defined(BN_MP_SHRINK_C)
|
||||
#endif
|
||||
|
||||
#if defined(BN_MP_SIGNED_BIN_SIZE_C)
|
||||
#define BN_MP_UNSIGNED_BIN_SIZE_C
|
||||
#endif
|
||||
|
||||
#if defined(BN_MP_SQR_C)
|
||||
#define BN_MP_TOOM_SQR_C
|
||||
#define BN_MP_KARATSUBA_SQR_C
|
||||
#define BN_FAST_S_MP_SQR_C
|
||||
#define BN_S_MP_SQR_C
|
||||
#endif
|
||||
|
||||
#if defined(BN_MP_SQRMOD_C)
|
||||
#define BN_MP_INIT_C
|
||||
#define BN_MP_SQR_C
|
||||
#define BN_MP_CLEAR_C
|
||||
#define BN_MP_MOD_C
|
||||
#endif
|
||||
|
||||
#if defined(BN_MP_SQRT_C)
|
||||
#define BN_MP_N_ROOT_C
|
||||
#define BN_MP_ISZERO_C
|
||||
#define BN_MP_ZERO_C
|
||||
#define BN_MP_INIT_COPY_C
|
||||
#define BN_MP_RSHD_C
|
||||
#define BN_MP_DIV_C
|
||||
#define BN_MP_ADD_C
|
||||
#define BN_MP_DIV_2_C
|
||||
#define BN_MP_CMP_MAG_C
|
||||
#define BN_MP_EXCH_C
|
||||
#define BN_MP_CLEAR_C
|
||||
#endif
|
||||
|
||||
#if defined(BN_MP_SUB_C)
|
||||
#define BN_S_MP_ADD_C
|
||||
#define BN_MP_CMP_MAG_C
|
||||
#define BN_S_MP_SUB_C
|
||||
#endif
|
||||
|
||||
#if defined(BN_MP_SUB_D_C)
|
||||
#define BN_MP_GROW_C
|
||||
#define BN_MP_ADD_D_C
|
||||
#define BN_MP_CLAMP_C
|
||||
#endif
|
||||
|
||||
#if defined(BN_MP_SUBMOD_C)
|
||||
#define BN_MP_INIT_C
|
||||
#define BN_MP_SUB_C
|
||||
#define BN_MP_CLEAR_C
|
||||
#define BN_MP_MOD_C
|
||||
#endif
|
||||
|
||||
#if defined(BN_MP_TO_SIGNED_BIN_C)
|
||||
#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
|
||||
#define BN_MP_DIV_2D_C
|
||||
#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
|
||||
#define BN_MP_COPY_C
|
||||
#define BN_MP_RSHD_C
|
||||
#define BN_MP_MUL_C
|
||||
#define BN_MP_MUL_2_C
|
||||
#define BN_MP_ADD_C
|
||||
#define BN_MP_SUB_C
|
||||
#define BN_MP_DIV_2_C
|
||||
#define BN_MP_MUL_2D_C
|
||||
#define BN_MP_MUL_D_C
|
||||
#define BN_MP_DIV_3_C
|
||||
#define BN_MP_LSHD_C
|
||||
#define BN_MP_CLEAR_MULTI_C
|
||||
#endif
|
||||
|
||||
#if defined(BN_MP_TOOM_SQR_C)
|
||||
#define BN_MP_INIT_MULTI_C
|
||||
#define BN_MP_MOD_2D_C
|
||||
#define BN_MP_COPY_C
|
||||
#define BN_MP_RSHD_C
|
||||
#define BN_MP_SQR_C
|
||||
#define BN_MP_MUL_2_C
|
||||
#define BN_MP_ADD_C
|
||||
#define BN_MP_SUB_C
|
||||
#define BN_MP_DIV_2_C
|
||||
#define BN_MP_MUL_2D_C
|
||||
#define BN_MP_MUL_D_C
|
||||
#define BN_MP_DIV_3_C
|
||||
#define BN_MP_LSHD_C
|
||||
#define BN_MP_CLEAR_MULTI_C
|
||||
#endif
|
||||
|
||||
#if defined(BN_MP_TORADIX_C)
|
||||
#define BN_MP_ISZERO_C
|
||||
#define BN_MP_INIT_COPY_C
|
||||
#define BN_MP_DIV_D_C
|
||||
#define BN_MP_CLEAR_C
|
||||
#define BN_MP_S_RMAP_C
|
||||
#endif
|
||||
|
||||
#if defined(BN_MP_TORADIX_N_C)
|
||||
#define BN_MP_ISZERO_C
|
||||
#define BN_MP_INIT_COPY_C
|
||||
#define BN_MP_DIV_D_C
|
||||
#define BN_MP_CLEAR_C
|
||||
#define BN_MP_S_RMAP_C
|
||||
#endif
|
||||
|
||||
#if defined(BN_MP_UNSIGNED_BIN_SIZE_C)
|
||||
#define BN_MP_COUNT_BITS_C
|
||||
#endif
|
||||
|
||||
#if defined(BN_MP_XOR_C)
|
||||
#define BN_MP_INIT_COPY_C
|
||||
#define BN_MP_CLAMP_C
|
||||
#define BN_MP_EXCH_C
|
||||
#define BN_MP_CLEAR_C
|
||||
#endif
|
||||
|
||||
#if defined(BN_MP_ZERO_C)
|
||||
#endif
|
||||
|
||||
#if defined(BN_PRIME_TAB_C)
|
||||
#endif
|
||||
|
||||
#if defined(BN_REVERSE_C)
|
||||
#endif
|
||||
|
||||
#if defined(BN_S_MP_ADD_C)
|
||||
#define BN_MP_GROW_C
|
||||
#define BN_MP_CLAMP_C
|
||||
#endif
|
||||
|
||||
#if defined(BN_S_MP_EXPTMOD_C)
|
||||
#define BN_MP_COUNT_BITS_C
|
||||
#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_MUL_C
|
||||
#define BN_MP_SET_C
|
||||
#define BN_MP_EXCH_C
|
||||
#endif
|
||||
|
||||
#if defined(BN_S_MP_MUL_DIGS_C)
|
||||
#define BN_FAST_S_MP_MUL_DIGS_C
|
||||
#define BN_MP_INIT_SIZE_C
|
||||
#define BN_MP_CLAMP_C
|
||||
#define BN_MP_EXCH_C
|
||||
#define BN_MP_CLEAR_C
|
||||
#endif
|
||||
|
||||
#if defined(BN_S_MP_MUL_HIGH_DIGS_C)
|
||||
#define BN_FAST_S_MP_MUL_HIGH_DIGS_C
|
||||
#define BN_MP_INIT_SIZE_C
|
||||
#define BN_MP_CLAMP_C
|
||||
#define BN_MP_EXCH_C
|
||||
#define BN_MP_CLEAR_C
|
||||
#endif
|
||||
|
||||
#if defined(BN_S_MP_SQR_C)
|
||||
#define BN_MP_INIT_SIZE_C
|
||||
#define BN_MP_CLAMP_C
|
||||
#define BN_MP_EXCH_C
|
||||
#define BN_MP_CLEAR_C
|
||||
#endif
|
||||
|
||||
#if defined(BN_S_MP_SUB_C)
|
||||
#define BN_MP_GROW_C
|
||||
#define BN_MP_CLAMP_C
|
||||
#endif
|
||||
|
||||
#if defined(BNCORE_C)
|
||||
#endif
|
||||
|
||||
#ifdef LTM3
|
||||
#define LTM_LAST
|
||||
#endif
|
||||
#include <tommath_superclass.h>
|
||||
#include <tommath_class.h>
|
||||
#else
|
||||
#define LTM_LAST
|
||||
#endif
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/headers/tommath_class.h,v $ */
|
||||
/* $Revision: 1.2 $ */
|
||||
/* $Date: 2005/05/05 14:35:58 $ */
|
||||
@@ -1,80 +0,0 @@
|
||||
/* super class file for PK algos */
|
||||
|
||||
/* default ... include all MPI */
|
||||
#ifndef SC_RSA_1
|
||||
|
||||
#define LTM_ALL
|
||||
|
||||
#endif
|
||||
|
||||
/* RSA only (does not support DH/DSA/ECC) */
|
||||
/* #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 */
|
||||
#ifdef SC_RSA_1
|
||||
#define BN_MP_SHRINK_C
|
||||
#define BN_MP_LCM_C
|
||||
#define BN_MP_PRIME_RANDOM_EX_C
|
||||
#define BN_MP_INVMOD_C
|
||||
#define BN_MP_GCD_C
|
||||
#define BN_MP_MOD_C
|
||||
#define BN_MP_MULMOD_C
|
||||
#define BN_MP_ADDMOD_C
|
||||
#define BN_MP_EXPTMOD_C
|
||||
#define BN_MP_SET_INT_C
|
||||
#define BN_MP_INIT_MULTI_C
|
||||
#define BN_MP_CLEAR_MULTI_C
|
||||
#define BN_MP_UNSIGNED_BIN_SIZE_C
|
||||
#define BN_MP_TO_UNSIGNED_BIN_C
|
||||
#define BN_MP_MOD_D_C
|
||||
#define BN_MP_PRIME_RABIN_MILLER_TRIALS_C
|
||||
#define BN_REVERSE_C
|
||||
#define BN_PRIME_TAB_C
|
||||
|
||||
/* other modifiers */
|
||||
#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
|
||||
* like removing support for even moduli, etc...
|
||||
*/
|
||||
#ifdef LTM_LAST
|
||||
#undef BN_MP_TOOM_MUL_C
|
||||
#undef BN_MP_TOOM_SQR_C
|
||||
#undef BN_MP_KARATSUBA_MUL_C
|
||||
#undef BN_MP_KARATSUBA_SQR_C
|
||||
#undef BN_MP_REDUCE_C
|
||||
#undef BN_MP_REDUCE_SETUP_C
|
||||
#undef BN_MP_DR_IS_MODULUS_C
|
||||
#undef BN_MP_DR_SETUP_C
|
||||
#undef BN_MP_DR_REDUCE_C
|
||||
#undef BN_MP_REDUCE_IS_2K_C
|
||||
#undef BN_MP_REDUCE_2K_SETUP_C
|
||||
#undef BN_MP_REDUCE_2K_C
|
||||
#undef BN_S_MP_EXPTMOD_C
|
||||
#undef BN_MP_DIV_3_C
|
||||
#undef BN_S_MP_MUL_HIGH_DIGS_C
|
||||
#undef BN_FAST_S_MP_MUL_HIGH_DIGS_C
|
||||
#undef BN_FAST_MP_INVMOD_C
|
||||
|
||||
/* To safely undefine these you have to make sure your RSA key won't exceed the Comba threshold
|
||||
* which is roughly 255 digits [7140 bits for 32-bit machines, 15300 bits for 64-bit machines]
|
||||
* which means roughly speaking you can handle upto 2536-bit RSA keys with these defined without
|
||||
* trouble.
|
||||
*/
|
||||
#undef BN_S_MP_MUL_DIGS_C
|
||||
#undef BN_S_MP_SQR_C
|
||||
#undef BN_MP_MONTGOMERY_REDUCE_C
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/headers/tommath_superclass.h,v $ */
|
||||
/* $Revision: 1.4 $ */
|
||||
/* $Date: 2005/05/14 13:27:20 $ */
|
||||
77
libtomcrypt/src/mac/f9/f9_done.c
Normal file
77
libtomcrypt/src/mac/f9/f9_done.c
Normal file
@@ -0,0 +1,77 @@
|
||||
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
|
||||
*
|
||||
* LibTomCrypt is a library that provides various cryptographic
|
||||
* algorithms in a highly modular and flexible manner.
|
||||
*
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
/**
|
||||
@file f9_done.c
|
||||
f9 Support, terminate the state
|
||||
*/
|
||||
|
||||
#ifdef LTC_F9_MODE
|
||||
|
||||
/** Terminate the f9-MAC state
|
||||
@param f9 f9 state to terminate
|
||||
@param out [out] Destination for the MAC tag
|
||||
@param outlen [in/out] Destination size and final tag size
|
||||
Return CRYPT_OK on success
|
||||
*/
|
||||
int f9_done(f9_state *f9, unsigned char *out, unsigned long *outlen)
|
||||
{
|
||||
int err, x;
|
||||
LTC_ARGCHK(f9 != NULL);
|
||||
LTC_ARGCHK(out != NULL);
|
||||
|
||||
/* check structure */
|
||||
if ((err = cipher_is_valid(f9->cipher)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
if ((f9->blocksize > cipher_descriptor[f9->cipher].block_length) || (f9->blocksize < 0) ||
|
||||
(f9->buflen > f9->blocksize) || (f9->buflen < 0)) {
|
||||
return CRYPT_INVALID_ARG;
|
||||
}
|
||||
|
||||
if (f9->buflen != 0) {
|
||||
/* encrypt */
|
||||
cipher_descriptor[f9->cipher].ecb_encrypt(f9->IV, f9->IV, &f9->key);
|
||||
f9->buflen = 0;
|
||||
for (x = 0; x < f9->blocksize; x++) {
|
||||
f9->ACC[x] ^= f9->IV[x];
|
||||
}
|
||||
}
|
||||
|
||||
/* schedule modified key */
|
||||
if ((err = cipher_descriptor[f9->cipher].setup(f9->akey, f9->keylen, 0, &f9->key)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
/* encrypt the ACC */
|
||||
cipher_descriptor[f9->cipher].ecb_encrypt(f9->ACC, f9->ACC, &f9->key);
|
||||
cipher_descriptor[f9->cipher].done(&f9->key);
|
||||
|
||||
/* extract tag */
|
||||
for (x = 0; x < f9->blocksize && (unsigned long)x < *outlen; x++) {
|
||||
out[x] = f9->ACC[x];
|
||||
}
|
||||
*outlen = x;
|
||||
|
||||
#ifdef LTC_CLEAN_STACK
|
||||
zeromem(f9, sizeof(*f9));
|
||||
#endif
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/mac/f9/f9_done.c,v $ */
|
||||
/* $Revision: 1.5 $ */
|
||||
/* $Date: 2006/11/09 01:53:32 $ */
|
||||
|
||||
83
libtomcrypt/src/mac/f9/f9_file.c
Normal file
83
libtomcrypt/src/mac/f9/f9_file.c
Normal file
@@ -0,0 +1,83 @@
|
||||
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
|
||||
*
|
||||
* LibTomCrypt is a library that provides various cryptographic
|
||||
* algorithms in a highly modular and flexible manner.
|
||||
*
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
/**
|
||||
@file f9_file.c
|
||||
f9 support, process a file, Tom St Denis
|
||||
*/
|
||||
|
||||
#ifdef LTC_F9_MODE
|
||||
|
||||
/**
|
||||
f9 a file
|
||||
@param cipher The index of the cipher desired
|
||||
@param key The secret key
|
||||
@param keylen The length of the secret key (octets)
|
||||
@param filename The name of the file you wish to f9
|
||||
@param out [out] Where the authentication tag is to be stored
|
||||
@param outlen [in/out] The max size and resulting size of the authentication tag
|
||||
@return CRYPT_OK if successful, CRYPT_NOP if file support has been disabled
|
||||
*/
|
||||
int f9_file(int cipher,
|
||||
const unsigned char *key, unsigned long keylen,
|
||||
const char *filename,
|
||||
unsigned char *out, unsigned long *outlen)
|
||||
{
|
||||
#ifdef LTC_NO_FILE
|
||||
return CRYPT_NOP;
|
||||
#else
|
||||
int err, x;
|
||||
f9_state f9;
|
||||
FILE *in;
|
||||
unsigned char buf[512];
|
||||
|
||||
LTC_ARGCHK(key != NULL);
|
||||
LTC_ARGCHK(filename != NULL);
|
||||
LTC_ARGCHK(out != NULL);
|
||||
LTC_ARGCHK(outlen != NULL);
|
||||
|
||||
in = fopen(filename, "rb");
|
||||
if (in == NULL) {
|
||||
return CRYPT_FILE_NOTFOUND;
|
||||
}
|
||||
|
||||
if ((err = f9_init(&f9, cipher, key, keylen)) != CRYPT_OK) {
|
||||
fclose(in);
|
||||
return err;
|
||||
}
|
||||
|
||||
do {
|
||||
x = fread(buf, 1, sizeof(buf), in);
|
||||
if ((err = f9_process(&f9, buf, x)) != CRYPT_OK) {
|
||||
fclose(in);
|
||||
return err;
|
||||
}
|
||||
} while (x == sizeof(buf));
|
||||
fclose(in);
|
||||
|
||||
if ((err = f9_done(&f9, out, outlen)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
#ifdef LTC_CLEAN_STACK
|
||||
zeromem(buf, sizeof(buf));
|
||||
#endif
|
||||
|
||||
return CRYPT_OK;
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/mac/f9/f9_file.c,v $ */
|
||||
/* $Revision: 1.4 $ */
|
||||
/* $Date: 2006/11/21 00:18:23 $ */
|
||||
70
libtomcrypt/src/mac/f9/f9_init.c
Normal file
70
libtomcrypt/src/mac/f9/f9_init.c
Normal file
@@ -0,0 +1,70 @@
|
||||
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
|
||||
*
|
||||
* LibTomCrypt is a library that provides various cryptographic
|
||||
* algorithms in a highly modular and flexible manner.
|
||||
*
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
/**
|
||||
@file f9_init.c
|
||||
F9 Support, start an F9 state
|
||||
*/
|
||||
|
||||
#ifdef LTC_F9_MODE
|
||||
|
||||
/** Initialize F9-MAC state
|
||||
@param f9 [out] f9 state to initialize
|
||||
@param cipher Index of cipher to use
|
||||
@param key [in] Secret key
|
||||
@param keylen Length of secret key in octets
|
||||
Return CRYPT_OK on success
|
||||
*/
|
||||
int f9_init(f9_state *f9, int cipher, const unsigned char *key, unsigned long keylen)
|
||||
{
|
||||
int x, err;
|
||||
|
||||
LTC_ARGCHK(f9 != NULL);
|
||||
LTC_ARGCHK(key != NULL);
|
||||
|
||||
/* schedule the key */
|
||||
if ((err = cipher_is_valid(cipher)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
#ifdef LTC_FAST
|
||||
if (cipher_descriptor[cipher].block_length % sizeof(LTC_FAST_TYPE)) {
|
||||
return CRYPT_INVALID_ARG;
|
||||
}
|
||||
#endif
|
||||
|
||||
if ((err = cipher_descriptor[cipher].setup(key, keylen, 0, &f9->key)) != CRYPT_OK) {
|
||||
goto done;
|
||||
}
|
||||
|
||||
/* make the second key */
|
||||
for (x = 0; (unsigned)x < keylen; x++) {
|
||||
f9->akey[x] = key[x] ^ 0xAA;
|
||||
}
|
||||
|
||||
/* setup struct */
|
||||
zeromem(f9->IV, cipher_descriptor[cipher].block_length);
|
||||
zeromem(f9->ACC, cipher_descriptor[cipher].block_length);
|
||||
f9->blocksize = cipher_descriptor[cipher].block_length;
|
||||
f9->cipher = cipher;
|
||||
f9->buflen = 0;
|
||||
f9->keylen = keylen;
|
||||
done:
|
||||
return err;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/mac/f9/f9_init.c,v $ */
|
||||
/* $Revision: 1.4 $ */
|
||||
/* $Date: 2006/11/08 22:54:18 $ */
|
||||
|
||||
71
libtomcrypt/src/mac/f9/f9_memory.c
Normal file
71
libtomcrypt/src/mac/f9/f9_memory.c
Normal file
@@ -0,0 +1,71 @@
|
||||
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
|
||||
*
|
||||
* LibTomCrypt is a library that provides various cryptographic
|
||||
* algorithms in a highly modular and flexible manner.
|
||||
*
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
/**
|
||||
@file f9_process.c
|
||||
f9 Support, Process a block through F9-MAC
|
||||
*/
|
||||
|
||||
#ifdef LTC_F9_MODE
|
||||
|
||||
/** f9-MAC a block of memory
|
||||
@param cipher Index of cipher to use
|
||||
@param key [in] Secret key
|
||||
@param keylen Length of key in octets
|
||||
@param in [in] Message to MAC
|
||||
@param inlen Length of input in octets
|
||||
@param out [out] Destination for the MAC tag
|
||||
@param outlen [in/out] Output size and final tag size
|
||||
Return CRYPT_OK on success.
|
||||
*/
|
||||
int f9_memory(int cipher,
|
||||
const unsigned char *key, unsigned long keylen,
|
||||
const unsigned char *in, unsigned long inlen,
|
||||
unsigned char *out, unsigned long *outlen)
|
||||
{
|
||||
f9_state *f9;
|
||||
int err;
|
||||
|
||||
/* is the cipher valid? */
|
||||
if ((err = cipher_is_valid(cipher)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
/* Use accelerator if found */
|
||||
if (cipher_descriptor[cipher].f9_memory != NULL) {
|
||||
return cipher_descriptor[cipher].f9_memory(key, keylen, in, inlen, out, outlen);
|
||||
}
|
||||
|
||||
f9 = XCALLOC(1, sizeof(*f9));
|
||||
if (f9 == NULL) {
|
||||
return CRYPT_MEM;
|
||||
}
|
||||
|
||||
if ((err = f9_init(f9, cipher, key, keylen)) != CRYPT_OK) {
|
||||
goto done;
|
||||
}
|
||||
|
||||
if ((err = f9_process(f9, in, inlen)) != CRYPT_OK) {
|
||||
goto done;
|
||||
}
|
||||
|
||||
err = f9_done(f9, out, outlen);
|
||||
done:
|
||||
XFREE(f9);
|
||||
return err;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/mac/f9/f9_memory.c,v $ */
|
||||
/* $Revision: 1.4 $ */
|
||||
/* $Date: 2006/11/21 23:02:42 $ */
|
||||
90
libtomcrypt/src/mac/f9/f9_memory_multi.c
Normal file
90
libtomcrypt/src/mac/f9/f9_memory_multi.c
Normal file
@@ -0,0 +1,90 @@
|
||||
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
|
||||
*
|
||||
* LibTomCrypt is a library that provides various cryptographic
|
||||
* algorithms in a highly modular and flexible manner.
|
||||
*
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
#include <stdarg.h>
|
||||
|
||||
/**
|
||||
@file f9_memory_multi.c
|
||||
f9 support, process multiple blocks of memory, Tom St Denis
|
||||
*/
|
||||
|
||||
#ifdef LTC_F9_MODE
|
||||
|
||||
/**
|
||||
f9 multiple blocks of memory
|
||||
@param cipher The index of the desired cipher
|
||||
@param key The secret key
|
||||
@param keylen The length of the secret key (octets)
|
||||
@param out [out] The destination of the authentication tag
|
||||
@param outlen [in/out] The max size and resulting size of the authentication tag (octets)
|
||||
@param in The data to send through f9
|
||||
@param inlen The length of the data to send through f9 (octets)
|
||||
@param ... tuples of (data,len) pairs to f9, terminated with a (NULL,x) (x=don't care)
|
||||
@return CRYPT_OK if successful
|
||||
*/
|
||||
int f9_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 err;
|
||||
f9_state *f9;
|
||||
va_list args;
|
||||
const unsigned char *curptr;
|
||||
unsigned long curlen;
|
||||
|
||||
LTC_ARGCHK(key != NULL);
|
||||
LTC_ARGCHK(in != NULL);
|
||||
LTC_ARGCHK(out != NULL);
|
||||
LTC_ARGCHK(outlen != NULL);
|
||||
|
||||
/* allocate ram for f9 state */
|
||||
f9 = XMALLOC(sizeof(f9_state));
|
||||
if (f9 == NULL) {
|
||||
return CRYPT_MEM;
|
||||
}
|
||||
|
||||
/* f9 process the message */
|
||||
if ((err = f9_init(f9, cipher, key, keylen)) != CRYPT_OK) {
|
||||
goto LBL_ERR;
|
||||
}
|
||||
va_start(args, inlen);
|
||||
curptr = in;
|
||||
curlen = inlen;
|
||||
for (;;) {
|
||||
/* process buf */
|
||||
if ((err = f9_process(f9, curptr, curlen)) != CRYPT_OK) {
|
||||
goto LBL_ERR;
|
||||
}
|
||||
/* step to next */
|
||||
curptr = va_arg(args, const unsigned char*);
|
||||
if (curptr == NULL) {
|
||||
break;
|
||||
}
|
||||
curlen = va_arg(args, unsigned long);
|
||||
}
|
||||
if ((err = f9_done(f9, out, outlen)) != CRYPT_OK) {
|
||||
goto LBL_ERR;
|
||||
}
|
||||
LBL_ERR:
|
||||
#ifdef LTC_CLEAN_STACK
|
||||
zeromem(f9, sizeof(f9_state));
|
||||
#endif
|
||||
XFREE(f9);
|
||||
va_end(args);
|
||||
return err;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/mac/f9/f9_memory_multi.c,v $ */
|
||||
/* $Revision: 1.2 $ */
|
||||
/* $Date: 2006/11/08 21:50:13 $ */
|
||||
78
libtomcrypt/src/mac/f9/f9_process.c
Normal file
78
libtomcrypt/src/mac/f9/f9_process.c
Normal file
@@ -0,0 +1,78 @@
|
||||
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
|
||||
*
|
||||
* LibTomCrypt is a library that provides various cryptographic
|
||||
* algorithms in a highly modular and flexible manner.
|
||||
*
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
/**
|
||||
@file f9_process.c
|
||||
f9 Support, process blocks with f9
|
||||
*/
|
||||
|
||||
#ifdef LTC_F9_MODE
|
||||
|
||||
/** Process data through f9-MAC
|
||||
@param f9 The f9-MAC state
|
||||
@param in Input data to process
|
||||
@param inlen Length of input in octets
|
||||
Return CRYPT_OK on success
|
||||
*/
|
||||
int f9_process(f9_state *f9, const unsigned char *in, unsigned long inlen)
|
||||
{
|
||||
int err, x;
|
||||
|
||||
LTC_ARGCHK(f9 != NULL);
|
||||
LTC_ARGCHK(in != NULL);
|
||||
|
||||
/* check structure */
|
||||
if ((err = cipher_is_valid(f9->cipher)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
if ((f9->blocksize > cipher_descriptor[f9->cipher].block_length) || (f9->blocksize < 0) ||
|
||||
(f9->buflen > f9->blocksize) || (f9->buflen < 0)) {
|
||||
return CRYPT_INVALID_ARG;
|
||||
}
|
||||
|
||||
#ifdef LTC_FAST
|
||||
if (f9->buflen == 0) {
|
||||
while (inlen >= (unsigned long)f9->blocksize) {
|
||||
for (x = 0; x < f9->blocksize; x += sizeof(LTC_FAST_TYPE)) {
|
||||
*((LTC_FAST_TYPE*)&(f9->IV[x])) ^= *((LTC_FAST_TYPE*)&(in[x]));
|
||||
}
|
||||
cipher_descriptor[f9->cipher].ecb_encrypt(f9->IV, f9->IV, &f9->key);
|
||||
for (x = 0; x < f9->blocksize; x += sizeof(LTC_FAST_TYPE)) {
|
||||
*((LTC_FAST_TYPE*)&(f9->ACC[x])) ^= *((LTC_FAST_TYPE*)&(f9->IV[x]));
|
||||
}
|
||||
in += f9->blocksize;
|
||||
inlen -= f9->blocksize;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
while (inlen) {
|
||||
if (f9->buflen == f9->blocksize) {
|
||||
cipher_descriptor[f9->cipher].ecb_encrypt(f9->IV, f9->IV, &f9->key);
|
||||
for (x = 0; x < f9->blocksize; x++) {
|
||||
f9->ACC[x] ^= f9->IV[x];
|
||||
}
|
||||
f9->buflen = 0;
|
||||
}
|
||||
f9->IV[f9->buflen++] ^= *in++;
|
||||
--inlen;
|
||||
}
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/mac/f9/f9_process.c,v $ */
|
||||
/* $Revision: 1.3 $ */
|
||||
/* $Date: 2006/12/16 17:41:21 $ */
|
||||
|
||||
78
libtomcrypt/src/mac/f9/f9_test.c
Normal file
78
libtomcrypt/src/mac/f9/f9_test.c
Normal file
@@ -0,0 +1,78 @@
|
||||
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
|
||||
*
|
||||
* LibTomCrypt is a library that provides various cryptographic
|
||||
* algorithms in a highly modular and flexible manner.
|
||||
*
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
/**
|
||||
@file f9_test.c
|
||||
f9 Support, Test F9 mode
|
||||
*/
|
||||
|
||||
#ifdef LTC_F9_MODE
|
||||
|
||||
/** Test f9-MAC mode
|
||||
Return CRYPT_OK on succes
|
||||
*/
|
||||
int f9_test(void)
|
||||
{
|
||||
#ifdef LTC_NO_TEST
|
||||
return CRYPT_NOP;
|
||||
#else
|
||||
static const struct {
|
||||
int msglen;
|
||||
unsigned char K[16], M[128], T[4];
|
||||
} tests[] = {
|
||||
{
|
||||
20,
|
||||
{ 0x2B, 0xD6, 0x45, 0x9F, 0x82, 0xC5, 0xB3, 0x00, 0x95, 0x2C, 0x49, 0x10, 0x48, 0x81, 0xFF, 0x48 },
|
||||
{ 0x38, 0xA6, 0xF0, 0x56, 0xB8, 0xAE, 0xFD, 0xA9, 0x33, 0x32, 0x34, 0x62, 0x63, 0x39, 0x38, 0x61, 0x37, 0x34, 0x79, 0x40 },
|
||||
{ 0x46, 0xE0, 0x0D, 0x4B }
|
||||
},
|
||||
|
||||
{
|
||||
105,
|
||||
{ 0x83, 0xFD, 0x23, 0xA2, 0x44, 0xA7, 0x4C, 0xF3, 0x58, 0xDA, 0x30, 0x19, 0xF1, 0x72, 0x26, 0x35 },
|
||||
{ 0x36, 0xAF, 0x61, 0x44, 0x4F, 0x30, 0x2A, 0xD2,
|
||||
0x35, 0xC6, 0x87, 0x16, 0x63, 0x3C, 0x66, 0xFB, 0x75, 0x0C, 0x26, 0x68, 0x65, 0xD5, 0x3C, 0x11, 0xEA, 0x05, 0xB1, 0xE9, 0xFA, 0x49, 0xC8, 0x39, 0x8D, 0x48, 0xE1, 0xEF, 0xA5, 0x90, 0x9D, 0x39,
|
||||
0x47, 0x90, 0x28, 0x37, 0xF5, 0xAE, 0x96, 0xD5, 0xA0, 0x5B, 0xC8, 0xD6, 0x1C, 0xA8, 0xDB, 0xEF, 0x1B, 0x13, 0xA4, 0xB4, 0xAB, 0xFE, 0x4F, 0xB1, 0x00, 0x60, 0x45, 0xB6, 0x74, 0xBB, 0x54, 0x72,
|
||||
0x93, 0x04, 0xC3, 0x82, 0xBE, 0x53, 0xA5, 0xAF, 0x05, 0x55, 0x61, 0x76, 0xF6, 0xEA, 0xA2, 0xEF, 0x1D, 0x05, 0xE4, 0xB0, 0x83, 0x18, 0x1E, 0xE6, 0x74, 0xCD, 0xA5, 0xA4, 0x85, 0xF7, 0x4D, 0x7A,
|
||||
0x40|0x80 },
|
||||
{ 0x95, 0xAE, 0x41, 0xBA },
|
||||
}
|
||||
};
|
||||
unsigned char T[16];
|
||||
unsigned long taglen;
|
||||
int err, x, idx;
|
||||
|
||||
/* find kasumi */
|
||||
if ((idx = find_cipher("kasumi")) == -1) {
|
||||
return CRYPT_NOP;
|
||||
}
|
||||
|
||||
for (x = 0; x < (int)(sizeof(tests)/sizeof(tests[0])); x++) {
|
||||
taglen = 4;
|
||||
if ((err = f9_memory(idx, tests[x].K, 16, tests[x].M, tests[x].msglen, T, &taglen)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
if (taglen != 4 || XMEMCMP(T, tests[x].T, 4)) {
|
||||
return CRYPT_FAIL_TESTVECTOR;
|
||||
}
|
||||
}
|
||||
|
||||
return CRYPT_OK;
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/mac/f9/f9_test.c,v $ */
|
||||
/* $Revision: 1.8 $ */
|
||||
/* $Date: 2006/11/21 23:02:42 $ */
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
HMAC support, terminate stream, Tom St Denis/Dobes Vandermeer
|
||||
*/
|
||||
|
||||
#ifdef HMAC
|
||||
#ifdef LTC_HMAC
|
||||
|
||||
#define HMAC_BLOCKSIZE hash_descriptor[hash].blocksize
|
||||
|
||||
@@ -105,5 +105,5 @@ LBL_ERR:
|
||||
#endif
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/mac/hmac/hmac_done.c,v $ */
|
||||
/* $Revision: 1.3 $ */
|
||||
/* $Date: 2005/05/05 14:35:58 $ */
|
||||
/* $Revision: 1.5 $ */
|
||||
/* $Date: 2006/11/03 00:39:49 $ */
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
HMAC support, process a file, Tom St Denis/Dobes Vandermeer
|
||||
*/
|
||||
|
||||
#ifdef HMAC
|
||||
#ifdef LTC_HMAC
|
||||
|
||||
/**
|
||||
HMAC a file
|
||||
@@ -89,5 +89,5 @@ int hmac_file(int hash, const char *fname,
|
||||
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/mac/hmac/hmac_file.c,v $ */
|
||||
/* $Revision: 1.3 $ */
|
||||
/* $Date: 2005/05/05 14:35:58 $ */
|
||||
/* $Revision: 1.5 $ */
|
||||
/* $Date: 2006/11/03 00:39:49 $ */
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
HMAC support, initialize state, Tom St Denis/Dobes Vandermeer
|
||||
*/
|
||||
|
||||
#ifdef HMAC
|
||||
#ifdef LTC_HMAC
|
||||
|
||||
#define HMAC_BLOCKSIZE hash_descriptor[hash].blocksize
|
||||
|
||||
@@ -108,5 +108,5 @@ done:
|
||||
#endif
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/mac/hmac/hmac_init.c,v $ */
|
||||
/* $Revision: 1.3 $ */
|
||||
/* $Date: 2005/05/05 14:35:58 $ */
|
||||
/* $Revision: 1.5 $ */
|
||||
/* $Date: 2006/11/03 00:39:49 $ */
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
HMAC support, process a block of memory, Tom St Denis/Dobes Vandermeer
|
||||
*/
|
||||
|
||||
#ifdef HMAC
|
||||
#ifdef LTC_HMAC
|
||||
|
||||
/**
|
||||
HMAC a block of memory to produce the authentication tag
|
||||
@@ -34,13 +34,24 @@ int hmac_memory(int hash,
|
||||
unsigned char *out, unsigned long *outlen)
|
||||
{
|
||||
hmac_state *hmac;
|
||||
int err;
|
||||
int err;
|
||||
|
||||
LTC_ARGCHK(key != NULL);
|
||||
LTC_ARGCHK(in != NULL);
|
||||
LTC_ARGCHK(in != NULL);
|
||||
LTC_ARGCHK(out != NULL);
|
||||
LTC_ARGCHK(outlen != NULL);
|
||||
|
||||
/* make sure hash descriptor is valid */
|
||||
if ((err = hash_is_valid(hash)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
/* is there a descriptor? */
|
||||
if (hash_descriptor[hash].hmac_block != NULL) {
|
||||
return hash_descriptor[hash].hmac_block(key, keylen, in, inlen, out, outlen);
|
||||
}
|
||||
|
||||
/* nope, so call the hmac functions */
|
||||
/* allocate ram for hmac state */
|
||||
hmac = XMALLOC(sizeof(hmac_state));
|
||||
if (hmac == NULL) {
|
||||
@@ -73,5 +84,5 @@ LBL_ERR:
|
||||
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/mac/hmac/hmac_memory.c,v $ */
|
||||
/* $Revision: 1.3 $ */
|
||||
/* $Date: 2005/05/05 14:35:58 $ */
|
||||
/* $Revision: 1.6 $ */
|
||||
/* $Date: 2006/11/03 00:39:49 $ */
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
#include <stdarg.h>
|
||||
@@ -16,7 +16,7 @@
|
||||
HMAC support, process multiple blocks of memory, Tom St Denis/Dobes Vandermeer
|
||||
*/
|
||||
|
||||
#ifdef HMAC
|
||||
#ifdef LTC_HMAC
|
||||
|
||||
/**
|
||||
HMAC multiple blocks of memory to produce the authentication tag
|
||||
@@ -88,5 +88,5 @@ LBL_ERR:
|
||||
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/mac/hmac/hmac_memory_multi.c,v $ */
|
||||
/* $Revision: 1.3 $ */
|
||||
/* $Date: 2005/05/05 14:35:58 $ */
|
||||
/* $Revision: 1.5 $ */
|
||||
/* $Date: 2006/11/03 00:39:49 $ */
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
HMAC support, process data, Tom St Denis/Dobes Vandermeer
|
||||
*/
|
||||
|
||||
#ifdef HMAC
|
||||
#ifdef LTC_HMAC
|
||||
|
||||
/**
|
||||
Process data through HMAC
|
||||
@@ -39,5 +39,5 @@ int hmac_process(hmac_state *hmac, const unsigned char *in, unsigned long inlen)
|
||||
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/mac/hmac/hmac_process.c,v $ */
|
||||
/* $Revision: 1.3 $ */
|
||||
/* $Date: 2005/05/05 14:35:58 $ */
|
||||
/* $Revision: 1.5 $ */
|
||||
/* $Date: 2006/11/03 00:39:49 $ */
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
HMAC support, self-test, Tom St Denis/Dobes Vandermeer
|
||||
*/
|
||||
|
||||
#ifdef HMAC
|
||||
#ifdef LTC_HMAC
|
||||
|
||||
#define HMAC_BLOCKSIZE hash_descriptor[hash].blocksize
|
||||
|
||||
@@ -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
|
||||
@@ -277,7 +277,7 @@ Key First"
|
||||
return err;
|
||||
}
|
||||
|
||||
if(memcmp(digest, cases[i].digest, (size_t)hash_descriptor[hash].hashsize) != 0) {
|
||||
if(XMEMCMP(digest, cases[i].digest, (size_t)hash_descriptor[hash].hashsize) != 0) {
|
||||
failed++;
|
||||
#if 0
|
||||
unsigned int j;
|
||||
@@ -312,5 +312,5 @@ Key First"
|
||||
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/src/mac/hmac/hmac_test.c,v $ */
|
||||
/* $Revision: 1.3 $ */
|
||||
/* $Date: 2005/05/05 14:35:58 $ */
|
||||
/* $Revision: 1.7 $ */
|
||||
/* $Date: 2006/11/03 00:39:49 $ */
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user