added libtomcrypt-1.17

This commit is contained in:
Tom St Denis
2007-07-20 17:48:02 +00:00
committed by Steffen Jaeckel
parent e24b01d392
commit bbc52b9e1b
341 changed files with 4806 additions and 1740 deletions
+12 -12
View File
@@ -6,24 +6,24 @@
* The library is free for all purposes without any express
* guarantee it works.
*
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
* Tom St Denis, tomstdenis@gmail.com, http://libtom.org
*/
#include "tomcrypt.h"
/**
@file hmac_done.c
HMAC support, terminate stream, Tom St Denis/Dobes Vandermeer
LTC_HMAC support, terminate stream, Tom St Denis/Dobes Vandermeer
*/
#ifdef LTC_HMAC
#define HMAC_BLOCKSIZE hash_descriptor[hash].blocksize
#define LTC_HMAC_BLOCKSIZE hash_descriptor[hash].blocksize
/**
Terminate an HMAC session
@param hmac The HMAC state
@param out [out] The destination of the HMAC authentication tag
@param outlen [in/out] The max size and resulting size of the HMAC authentication tag
Terminate an LTC_HMAC session
@param hmac The LTC_HMAC state
@param out [out] The destination of the LTC_HMAC authentication tag
@param outlen [in/out] The max size and resulting size of the LTC_HMAC authentication tag
@return CRYPT_OK if successful
*/
int hmac_done(hmac_state *hmac, unsigned char *out, unsigned long *outlen)
@@ -45,7 +45,7 @@ int hmac_done(hmac_state *hmac, unsigned char *out, unsigned long *outlen)
hashsize = hash_descriptor[hash].hashsize;
/* allocate buffers */
buf = XMALLOC(HMAC_BLOCKSIZE);
buf = XMALLOC(LTC_HMAC_BLOCKSIZE);
isha = XMALLOC(hashsize);
if (buf == NULL || isha == NULL) {
if (buf != NULL) {
@@ -57,13 +57,13 @@ int hmac_done(hmac_state *hmac, unsigned char *out, unsigned long *outlen)
return CRYPT_MEM;
}
/* Get the hash of the first HMAC vector plus the data */
/* Get the hash of the first LTC_HMAC vector plus the data */
if ((err = hash_descriptor[hash].done(&hmac->md, isha)) != CRYPT_OK) {
goto LBL_ERR;
}
/* Create the second HMAC vector vector for step (3) */
for(i=0; i < HMAC_BLOCKSIZE; i++) {
/* Create the second LTC_HMAC vector vector for step (3) */
for(i=0; i < LTC_HMAC_BLOCKSIZE; i++) {
buf[i] = hmac->key[i] ^ 0x5C;
}
@@ -71,7 +71,7 @@ int hmac_done(hmac_state *hmac, unsigned char *out, unsigned long *outlen)
if ((err = hash_descriptor[hash].init(&hmac->md)) != CRYPT_OK) {
goto LBL_ERR;
}
if ((err = hash_descriptor[hash].process(&hmac->md, buf, HMAC_BLOCKSIZE)) != CRYPT_OK) {
if ((err = hash_descriptor[hash].process(&hmac->md, buf, LTC_HMAC_BLOCKSIZE)) != CRYPT_OK) {
goto LBL_ERR;
}
if ((err = hash_descriptor[hash].process(&hmac->md, isha, hashsize)) != CRYPT_OK) {
+5 -5
View File
@@ -6,24 +6,24 @@
* The library is free for all purposes without any express
* guarantee it works.
*
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
* Tom St Denis, tomstdenis@gmail.com, http://libtom.org
*/
#include "tomcrypt.h"
/**
@file hmac_file.c
HMAC support, process a file, Tom St Denis/Dobes Vandermeer
LTC_HMAC support, process a file, Tom St Denis/Dobes Vandermeer
*/
#ifdef LTC_HMAC
/**
HMAC a file
LTC_HMAC a file
@param hash The index of the hash you wish to use
@param fname The name of the file you wish to HMAC
@param fname The name of the file you wish to LTC_HMAC
@param key The secret key
@param keylen The length of the secret key
@param out [out] The HMAC authentication tag
@param out [out] The LTC_HMAC authentication tag
@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
*/
+16 -16
View File
@@ -6,22 +6,22 @@
* The library is free for all purposes without any express
* guarantee it works.
*
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
* Tom St Denis, tomstdenis@gmail.com, http://libtom.org
*/
#include "tomcrypt.h"
/**
@file hmac_init.c
HMAC support, initialize state, Tom St Denis/Dobes Vandermeer
LTC_HMAC support, initialize state, Tom St Denis/Dobes Vandermeer
*/
#ifdef LTC_HMAC
#define HMAC_BLOCKSIZE hash_descriptor[hash].blocksize
#define LTC_HMAC_BLOCKSIZE hash_descriptor[hash].blocksize
/**
Initialize an HMAC context.
@param hmac The HMAC state
Initialize an LTC_HMAC context.
@param hmac The LTC_HMAC state
@param hash The index of the hash you want to use
@param key The secret key
@param keylen The length of the secret key (octets)
@@ -50,37 +50,37 @@ int hmac_init(hmac_state *hmac, int hash, const unsigned char *key, unsigned lon
}
/* allocate ram for buf */
buf = XMALLOC(HMAC_BLOCKSIZE);
buf = XMALLOC(LTC_HMAC_BLOCKSIZE);
if (buf == NULL) {
return CRYPT_MEM;
}
/* allocate memory for key */
hmac->key = XMALLOC(HMAC_BLOCKSIZE);
hmac->key = XMALLOC(LTC_HMAC_BLOCKSIZE);
if (hmac->key == NULL) {
XFREE(buf);
return CRYPT_MEM;
}
/* (1) make sure we have a large enough key */
if(keylen > HMAC_BLOCKSIZE) {
z = HMAC_BLOCKSIZE;
if(keylen > LTC_HMAC_BLOCKSIZE) {
z = LTC_HMAC_BLOCKSIZE;
if ((err = hash_memory(hash, key, keylen, hmac->key, &z)) != CRYPT_OK) {
goto LBL_ERR;
}
if(hashsize < HMAC_BLOCKSIZE) {
zeromem((hmac->key) + hashsize, (size_t)(HMAC_BLOCKSIZE - hashsize));
if(hashsize < LTC_HMAC_BLOCKSIZE) {
zeromem((hmac->key) + hashsize, (size_t)(LTC_HMAC_BLOCKSIZE - hashsize));
}
keylen = hashsize;
} else {
XMEMCPY(hmac->key, key, (size_t)keylen);
if(keylen < HMAC_BLOCKSIZE) {
zeromem((hmac->key) + keylen, (size_t)(HMAC_BLOCKSIZE - keylen));
if(keylen < LTC_HMAC_BLOCKSIZE) {
zeromem((hmac->key) + keylen, (size_t)(LTC_HMAC_BLOCKSIZE - keylen));
}
}
/* Create the initial vector for step (3) */
for(i=0; i < HMAC_BLOCKSIZE; i++) {
for(i=0; i < LTC_HMAC_BLOCKSIZE; i++) {
buf[i] = hmac->key[i] ^ 0x36;
}
@@ -89,7 +89,7 @@ int hmac_init(hmac_state *hmac, int hash, const unsigned char *key, unsigned lon
goto LBL_ERR;
}
if ((err = hash_descriptor[hash].process(&hmac->md, buf, HMAC_BLOCKSIZE)) != CRYPT_OK) {
if ((err = hash_descriptor[hash].process(&hmac->md, buf, LTC_HMAC_BLOCKSIZE)) != CRYPT_OK) {
goto LBL_ERR;
}
goto done;
@@ -98,7 +98,7 @@ LBL_ERR:
XFREE(hmac->key);
done:
#ifdef LTC_CLEAN_STACK
zeromem(buf, HMAC_BLOCKSIZE);
zeromem(buf, LTC_HMAC_BLOCKSIZE);
#endif
XFREE(buf);
+5 -5
View File
@@ -6,24 +6,24 @@
* The library is free for all purposes without any express
* guarantee it works.
*
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
* Tom St Denis, tomstdenis@gmail.com, http://libtom.org
*/
#include "tomcrypt.h"
/**
@file hmac_memory.c
HMAC support, process a block of memory, Tom St Denis/Dobes Vandermeer
LTC_HMAC support, process a block of memory, Tom St Denis/Dobes Vandermeer
*/
#ifdef LTC_HMAC
/**
HMAC a block of memory to produce the authentication tag
LTC_HMAC a block of memory to produce the authentication tag
@param hash The index of the hash to use
@param key The secret key
@param keylen The length of the secret key (octets)
@param in The data to HMAC
@param inlen The length of the data to HMAC (octets)
@param in The data to LTC_HMAC
@param inlen The length of the data to LTC_HMAC (octets)
@param out [out] Destination of the authentication tag
@param outlen [in/out] Max size and resulting size of authentication tag
@return CRYPT_OK if successful
+6 -6
View File
@@ -6,28 +6,28 @@
* The library is free for all purposes without any express
* guarantee it works.
*
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
* Tom St Denis, tomstdenis@gmail.com, http://libtom.org
*/
#include "tomcrypt.h"
#include <stdarg.h>
/**
@file hmac_memory_multi.c
HMAC support, process multiple blocks of memory, Tom St Denis/Dobes Vandermeer
LTC_HMAC support, process multiple blocks of memory, Tom St Denis/Dobes Vandermeer
*/
#ifdef LTC_HMAC
/**
HMAC multiple blocks of memory to produce the authentication tag
LTC_HMAC multiple blocks of memory to produce the authentication tag
@param hash The index of the hash to use
@param key The secret key
@param keylen The length of the secret key (octets)
@param out [out] Destination of the authentication tag
@param outlen [in/out] Max size and resulting size of authentication tag
@param in The data to HMAC
@param inlen The length of the data to HMAC (octets)
@param ... tuples of (data,len) pairs to HMAC, terminated with a (NULL,x) (x=don't care)
@param in The data to LTC_HMAC
@param inlen The length of the data to LTC_HMAC (octets)
@param ... tuples of (data,len) pairs to LTC_HMAC, terminated with a (NULL,x) (x=don't care)
@return CRYPT_OK if successful
*/
int hmac_memory_multi(int hash,
+5 -5
View File
@@ -6,22 +6,22 @@
* The library is free for all purposes without any express
* guarantee it works.
*
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
* Tom St Denis, tomstdenis@gmail.com, http://libtom.org
*/
#include "tomcrypt.h"
/**
@file hmac_process.c
HMAC support, process data, Tom St Denis/Dobes Vandermeer
LTC_HMAC support, process data, Tom St Denis/Dobes Vandermeer
*/
#ifdef LTC_HMAC
/**
Process data through HMAC
Process data through LTC_HMAC
@param hmac The hmac state
@param in The data to send through HMAC
@param inlen The length of the data to HMAC (octets)
@param in The data to send through LTC_HMAC
@param inlen The length of the data to LTC_HMAC (octets)
@return CRYPT_OK if successful
*/
int hmac_process(hmac_state *hmac, const unsigned char *in, unsigned long inlen)
+10 -10
View File
@@ -6,18 +6,18 @@
* The library is free for all purposes without any express
* guarantee it works.
*
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
* Tom St Denis, tomstdenis@gmail.com, http://libtom.org
*/
#include "tomcrypt.h"
/**
@file hmac_test.c
HMAC support, self-test, Tom St Denis/Dobes Vandermeer
LTC_HMAC support, self-test, Tom St Denis/Dobes Vandermeer
*/
#ifdef LTC_HMAC
#define HMAC_BLOCKSIZE hash_descriptor[hash].blocksize
#define LTC_HMAC_BLOCKSIZE hash_descriptor[hash].blocksize
/*
TEST CASES SOURCE:
@@ -27,11 +27,11 @@ Request for Comments: 2202 IBM
Category: Informational R. Glenn
NIST
September 1997
Test Cases for HMAC-MD5 and HMAC-SHA-1
Test Cases for LTC_HMAC-LTC_MD5 and LTC_HMAC-LTC_SHA-1
*/
/**
HMAC self-test
LTC_HMAC self-test
@return CRYPT_OK if successful, CRYPT_NOP if tests have been disabled.
*/
int hmac_test(void)
@@ -52,7 +52,7 @@ int hmac_test(void)
unsigned char digest[MAXBLOCKSIZE];
} cases[] = {
/*
3. Test Cases for HMAC-SHA-1
3. Test Cases for LTC_HMAC-LTC_SHA-1
test_case = 1
key = 0x0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c
@@ -118,7 +118,7 @@ int hmac_test(void)
0x6b, 0xba, 0xa7, 0x96, 0x5c, 0x78, 0x08, 0xbb, 0xff, 0x1a, 0x91} },
/*
2. Test Cases for HMAC-MD5
2. Test Cases for LTC_HMAC-LTC_MD5
test_case = 1
key = 0x0b 0b 0b 0b
@@ -272,7 +272,7 @@ Key First"
outlen = sizeof(digest);
if((err = hmac_memory(hash, cases[i].key, cases[i].keylen, cases[i].data, cases[i].datalen, digest, &outlen)) != CRYPT_OK) {
#if 0
printf("HMAC-%s test #%d, %s\n", cases[i].algo, cases[i].num, error_to_string(err));
printf("LTC_HMAC-%s test #%d, %s\n", cases[i].algo, cases[i].num, error_to_string(err));
#endif
return err;
}
@@ -281,7 +281,7 @@ Key First"
failed++;
#if 0
unsigned int j;
printf("\nHMAC-%s test #%d:\n", cases[i].algo, cases[i].num);
printf("\nLTC_HMAC-%s test #%d:\n", cases[i].algo, cases[i].num);
printf( "Result: 0x");
for(j=0; j < hash_descriptor[hash].hashsize; j++) {
printf("%2x ", digest[j]);
@@ -294,7 +294,7 @@ Key First"
return CRYPT_ERROR;
#endif
} else {
/* printf("HMAC-%s test #%d: Passed\n", cases[i].algo, cases[i].num); */
/* printf("LTC_HMAC-%s test #%d: Passed\n", cases[i].algo, cases[i].num); */
}
}