Commit 8c14eebb authored by cutealien's avatar cutealien

Move defines out of header or add prefixes to avoid accidental name collisions.


git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@4181 dfc29bdd-3216-0410-991c-e03cc46cb475
parent e33c2c5a
......@@ -37,6 +37,9 @@
#include "hmac.h"
#define HMAC_IPAD (0x36 * (((unsigned long)-1) / 0xff))
#define HMAC_OPAD (0x5c * (((unsigned long)-1) / 0xff))
/* initialise the HMAC context to zero */
void hmac_sha_begin(hmac_ctx cx[1])
{
......@@ -49,9 +52,9 @@ int hmac_sha_key(const unsigned char key[], unsigned long key_len, hmac_ctx cx[1
if(cx->klen == HMAC_IN_DATA) /* error if further key input */
return HMAC_BAD_MODE; /* is attempted in data mode */
if(cx->klen + key_len > HASH_INPUT_SIZE) /* if the key has to be hashed */
if(cx->klen + key_len > HMAC_HASH_INPUT_SIZE) /* if the key has to be hashed */
{
if(cx->klen <= HASH_INPUT_SIZE) /* if the hash has not yet been */
if(cx->klen <= HMAC_HASH_INPUT_SIZE) /* if the hash has not yet been */
{ /* started, initialise it and */
sha_begin(cx->ctx); /* hash stored key characters */
sha_hash(cx->key, cx->klen, cx->ctx);
......@@ -73,22 +76,22 @@ void hmac_sha_data(const unsigned char data[], unsigned long data_len, hmac_ctx
if(cx->klen != HMAC_IN_DATA) /* if not yet in data phase */
{
if(cx->klen > HASH_INPUT_SIZE) /* if key is being hashed */
if(cx->klen > HMAC_HASH_INPUT_SIZE) /* if key is being hashed */
{ /* complete the hash and */
sha_end(cx->key, cx->ctx); /* store the result as the */
cx->klen = HASH_OUTPUT_SIZE; /* key and set new length */
cx->klen = HMAC_HASH_OUTPUT_SIZE; /* key and set new length */
}
/* pad the key if necessary */
memset(cx->key + cx->klen, 0, HASH_INPUT_SIZE - cx->klen);
memset(cx->key + cx->klen, 0, HMAC_HASH_INPUT_SIZE - cx->klen);
/* xor ipad into key value */
for(i = 0; i < HASH_INPUT_SIZE / sizeof(unsigned long); ++i)
((unsigned long*)cx->key)[i] ^= IPAD;
for(i = 0; i < HMAC_HASH_INPUT_SIZE / sizeof(unsigned long); ++i)
((unsigned long*)cx->key)[i] ^= HMAC_IPAD;
/* and start hash operation */
sha_begin(cx->ctx);
sha_hash(cx->key, HASH_INPUT_SIZE, cx->ctx);
sha_hash(cx->key, HMAC_HASH_INPUT_SIZE, cx->ctx);
/* mark as now in data mode */
cx->klen = HMAC_IN_DATA;
......@@ -101,7 +104,7 @@ void hmac_sha_data(const unsigned char data[], unsigned long data_len, hmac_ctx
/* compute and output the MAC value */
void hmac_sha_end(unsigned char mac[], unsigned long mac_len, hmac_ctx cx[1])
{ unsigned char dig[HASH_OUTPUT_SIZE];
{ unsigned char dig[HMAC_HASH_OUTPUT_SIZE];
unsigned int i;
/* if no data has been entered perform a null data phase */
......@@ -111,13 +114,13 @@ void hmac_sha_end(unsigned char mac[], unsigned long mac_len, hmac_ctx cx[1])
sha_end(dig, cx->ctx); /* complete the inner hash */
/* set outer key value using opad and removing ipad */
for(i = 0; i < HASH_INPUT_SIZE / sizeof(unsigned long); ++i)
((unsigned long*)cx->key)[i] ^= OPAD ^ IPAD;
for(i = 0; i < HMAC_HASH_INPUT_SIZE / sizeof(unsigned long); ++i)
((unsigned long*)cx->key)[i] ^= HMAC_OPAD ^ HMAC_IPAD;
/* perform the outer hash operation */
sha_begin(cx->ctx);
sha_hash(cx->key, HASH_INPUT_SIZE, cx->ctx);
sha_hash(dig, HASH_OUTPUT_SIZE, cx->ctx);
sha_hash(cx->key, HMAC_HASH_INPUT_SIZE, cx->ctx);
sha_hash(dig, HMAC_HASH_OUTPUT_SIZE, cx->ctx);
sha_end(dig, cx->ctx);
/* output the hash value */
......
......@@ -48,12 +48,12 @@
#include "sha1.h"
#define HASH_INPUT_SIZE SHA1_BLOCK_SIZE
#define HASH_OUTPUT_SIZE SHA1_DIGEST_SIZE
#define sha_ctx sha1_ctx
#define sha_begin sha1_begin
#define sha_hash sha1_hash
#define sha_end sha1_end
#define HMAC_HASH_INPUT_SIZE SHA1_BLOCK_SIZE
#define HMAC_HASH_OUTPUT_SIZE SHA1_DIGEST_SIZE
#define sha_ctx sha1_ctx
#define sha_begin sha1_begin
#define sha_hash sha1_hash
#define sha_end sha1_end
#endif
......@@ -61,8 +61,8 @@
#include "sha2.h"
#define HASH_INPUT_SIZE SHA256_BLOCK_SIZE
#define HASH_OUTPUT_SIZE SHA256_DIGEST_SIZE
#define HMAC_HASH_INPUT_SIZE SHA256_BLOCK_SIZE
#define HMAC_HASH_OUTPUT_SIZE SHA256_DIGEST_SIZE
#define sha_ctx sha256_ctx
#define sha_begin sha256_begin
#define sha_hash sha256_hash
......@@ -74,11 +74,8 @@
#define HMAC_BAD_MODE -1
#define HMAC_IN_DATA 0xffffffff
#define IPAD (0x36 * (((unsigned long)-1) / 0xff))
#define OPAD (0x5c * (((unsigned long)-1) / 0xff))
typedef struct
{ unsigned char key[HASH_INPUT_SIZE];
{ unsigned char key[HMAC_HASH_INPUT_SIZE];
sha_ctx ctx[1];
unsigned long klen;
} hmac_ctx;
......
......@@ -46,7 +46,7 @@ void derive_key(const unsigned char pwd[], /* the PASSWORD */
unsigned int key_len)/* and its required length */
{
unsigned int i, j, k, n_blk;
unsigned char uu[HASH_OUTPUT_SIZE], ux[HASH_OUTPUT_SIZE];
unsigned char uu[HMAC_HASH_OUTPUT_SIZE], ux[HMAC_HASH_OUTPUT_SIZE];
hmac_ctx c1[1], c2[1], c3[1];
/* set HMAC context (c1) for password */
......@@ -58,12 +58,12 @@ void derive_key(const unsigned char pwd[], /* the PASSWORD */
hmac_sha_data(salt, salt_len, c2);
/* find the number of SHA blocks in the key */
n_blk = 1 + (key_len - 1) / HASH_OUTPUT_SIZE;
n_blk = 1 + (key_len - 1) / HMAC_HASH_OUTPUT_SIZE;
for(i = 0; i < n_blk; ++i) /* for each block in key */
{
/* ux[] holds the running xor value */
memset(ux, 0, HASH_OUTPUT_SIZE);
memset(ux, 0, HMAC_HASH_OUTPUT_SIZE);
/* set HMAC context (c3) for password and salt */
memcpy(c3, c2, sizeof(hmac_ctx));
......@@ -81,10 +81,10 @@ void derive_key(const unsigned char pwd[], /* the PASSWORD */
hmac_sha_data(uu, k, c3);
/* obtain HMAC for uu[] */
hmac_sha_end(uu, HASH_OUTPUT_SIZE, c3);
hmac_sha_end(uu, HMAC_HASH_OUTPUT_SIZE, c3);
/* xor into the running xor block */
for(k = 0; k < HASH_OUTPUT_SIZE; ++k)
for(k = 0; k < HMAC_HASH_OUTPUT_SIZE; ++k)
ux[k] ^= uu[k];
/* set HMAC context (c3) for password */
......@@ -92,8 +92,8 @@ void derive_key(const unsigned char pwd[], /* the PASSWORD */
}
/* compile key blocks into the key output */
j = 0; k = i * HASH_OUTPUT_SIZE;
while(j < HASH_OUTPUT_SIZE && k < key_len)
j = 0; k = i * HMAC_HASH_OUTPUT_SIZE;
while(j < HMAC_HASH_OUTPUT_SIZE && k < key_len)
key[k++] = ux[j++];
}
}
......@@ -112,21 +112,21 @@ struct
} tests[] =
{
{ 8, 4, 5, (unsigned char*)"password",
{
0x12, 0x34, 0x56, 0x78
{
0x12, 0x34, 0x56, 0x78
},
{
{
0x5c, 0x75, 0xce, 0xf0, 0x1a, 0x96, 0x0d, 0xf7,
0x4c, 0xb6, 0xb4, 0x9b, 0x9e, 0x38, 0xe6, 0xb5
0x4c, 0xb6, 0xb4, 0x9b, 0x9e, 0x38, 0xe6, 0xb5
}
},
{ 8, 8, 5, (unsigned char*)"password",
{
0x12, 0x34, 0x56, 0x78, 0x78, 0x56, 0x34, 0x12
{
0x12, 0x34, 0x56, 0x78, 0x78, 0x56, 0x34, 0x12
},
{
{
0xd1, 0xda, 0xa7, 0x86, 0x15, 0xf2, 0x87, 0xe6,
0xa1, 0xc8, 0xb1, 0x20, 0xd7, 0x06, 0x2a, 0x49
0xa1, 0xc8, 0xb1, 0x20, 0xd7, 0x06, 0x2a, 0x49
}
},
{ 8, 21, 1, (unsigned char*)"password",
......@@ -143,7 +143,7 @@ struct
"ATHENA.MIT.EDUraeburn"
},
{
0x01, 0xdb, 0xee, 0x7f, 0x4a, 0x9e, 0x24, 0x3e,
0x01, 0xdb, 0xee, 0x7f, 0x4a, 0x9e, 0x24, 0x3e,
0x98, 0x8b, 0x62, 0xc7, 0x3c, 0xda, 0x93, 0x5d
}
},
......@@ -152,7 +152,7 @@ struct
"ATHENA.MIT.EDUraeburn"
},
{
0x5c, 0x08, 0xeb, 0x61, 0xfd, 0xf7, 0x1e, 0x4e,
0x5c, 0x08, 0xeb, 0x61, 0xfd, 0xf7, 0x1e, 0x4e,
0x4e, 0xc3, 0xcf, 0x6b, 0xa1, 0xf5, 0x51, 0x2b
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment