Skip to content

Commit

Permalink
Revert "changed types to u_int32_t and u_int8_t to make code x86_64 p…
Browse files Browse the repository at this point in the history
…ortable"

This reverts commit 4e26cb9.
  • Loading branch information
jdg committed Jan 11, 2011
1 parent ca2c6e1 commit f19befe
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 33 deletions.
18 changes: 9 additions & 9 deletions Crytpo/hmac.c
Expand Up @@ -33,14 +33,14 @@
#include <stdlib.h>
#include <string.h>

void hmac_sha1(const u_int8_t *inText, size_t inTextLength, u_int8_t* inKey, size_t inKeyLength, u_int8_t *outDigest)
void hmac_sha1(const unsigned char *inText, size_t inTextLength, unsigned char* inKey, size_t inKeyLength, unsigned char *outDigest)
{
#define B 64
#define L 20
const size_t B = 64;
const size_t L = 20;

SHA1_CTX theSHA1Context;
u_int8_t k_ipad[B + 1]; /* inner padding - key XORd with ipad */
u_int8_t k_opad[B + 1]; /* outer padding - key XORd with opad */
unsigned char k_ipad[B + 1]; /* inner padding - key XORd with ipad */
unsigned char k_opad[B + 1]; /* outer padding - key XORd with opad */

/* if key is longer than 64 bytes reset it to key=SHA1 (key) */
if (inKeyLength > B)
Expand Down Expand Up @@ -70,17 +70,17 @@ for (i = 0; i < B; i++)
*/
SHA1Init(&theSHA1Context); /* init context for 1st pass */
SHA1Update(&theSHA1Context, k_ipad, B); /* start with inner pad */
SHA1Update(&theSHA1Context, (u_int8_t *)inText, inTextLength); /* then text of datagram */
SHA1Final((u_int8_t *)outDigest, &theSHA1Context); /* finish up 1st pass */
SHA1Update(&theSHA1Context, (unsigned char *)inText, inTextLength); /* then text of datagram */
SHA1Final((unsigned char *)outDigest, &theSHA1Context); /* finish up 1st pass */

/*
* perform outer SHA1
*/
SHA1Init(&theSHA1Context); /* init context for 2nd
* pass */
SHA1Update(&theSHA1Context, k_opad, B); /* start with outer pad */
SHA1Update(&theSHA1Context, (u_int8_t *)outDigest, L); /* then results of 1st
SHA1Update(&theSHA1Context, outDigest, L); /* then results of 1st
* hash */
SHA1Final((u_int8_t *)outDigest, &theSHA1Context); /* finish up 2nd pass */
SHA1Final(outDigest, &theSHA1Context); /* finish up 2nd pass */

}
2 changes: 1 addition & 1 deletion Crytpo/hmac.h
Expand Up @@ -26,6 +26,6 @@
#ifndef HMAC_H
#define HMAC_H 1

extern void hmac_sha1(const u_int8_t *inText, size_t inTextLength, u_int8_t* inKey, const size_t inKeyLength, u_int8_t *outDigest);
extern void hmac_sha1(const unsigned char *inText, int inTextLength, unsigned char* inKey, const unsigned int inKeyLength, unsigned char *outDigest);

#endif /* HMAC_H */
28 changes: 14 additions & 14 deletions Crytpo/sha1.c
Expand Up @@ -23,7 +23,7 @@ A million repetitions of "a"

#include "sha1.h"

void SHA1Transform(u_int32_t state[5], u_int8_t buffer[64]);
void SHA1Transform(unsigned long state[5], unsigned char buffer[64]);

#define rol(value, bits) (((value) << (bits)) | ((value) >> (32 - (bits))))

Expand All @@ -48,16 +48,16 @@ void SHA1Transform(u_int32_t state[5], u_int8_t buffer[64]);

/* Hash a single 512-bit block. This is the core of the algorithm. */

void SHA1Transform(u_int32_t state[5], u_int8_t buffer[64])
void SHA1Transform(unsigned long state[5], unsigned char buffer[64])
{
u_int32_t a, b, c, d, e;
unsigned long a, b, c, d, e;
typedef union {
u_int8_t c[64];
u_int32_t l[16];
unsigned char c[64];
unsigned long l[16];
} CHAR64LONG16;
CHAR64LONG16* block;
#ifdef SHA1HANDSOFF
static u_int8_t workspace[64];
static unsigned char workspace[64];
block = (CHAR64LONG16*)workspace;
memcpy(block, buffer, 64);
#else
Expand Down Expand Up @@ -117,7 +117,7 @@ void SHA1Init(SHA1_CTX* context)

/* Run your data through this. */

void SHA1Update(SHA1_CTX* context, u_int8_t* data, unsigned int len)
void SHA1Update(SHA1_CTX* context, unsigned char* data, unsigned int len)
{
unsigned int i, j;

Expand All @@ -139,22 +139,22 @@ unsigned int i, j;

/* Add padding and return the message digest. */

void SHA1Final(u_int8_t digest[20], SHA1_CTX* context)
void SHA1Final(unsigned char digest[20], SHA1_CTX* context)
{
u_int32_t i, j;
u_int8_t finalcount[8];
unsigned long i, j;
unsigned char finalcount[8];

for (i = 0; i < 8; i++) {
finalcount[i] = (u_int8_t)((context->count[(i >= 4 ? 0 : 1)]
finalcount[i] = (unsigned char)((context->count[(i >= 4 ? 0 : 1)]
>> ((3-(i & 3)) * 8) ) & 255); /* Endian independent */
}
SHA1Update(context, (u_int8_t *)"\200", 1);
SHA1Update(context, (unsigned char *)"\200", 1);
while ((context->count[0] & 504) != 448) {
SHA1Update(context, (u_int8_t *)"\0", 1);
SHA1Update(context, (unsigned char *)"\0", 1);
}
SHA1Update(context, finalcount, 8); /* Should cause a SHA1Transform() */
for (i = 0; i < 20; i++) {
digest[i] = (u_int8_t)
digest[i] = (unsigned char)
((context->state[i>>2] >> ((3-(i & 3)) * 8) ) & 255);
}
/* Wipe variables */
Expand Down
10 changes: 5 additions & 5 deletions Crytpo/sha1.h
Expand Up @@ -2,11 +2,11 @@
// From http://www.mirrors.wiretapped.net/security/cryptography/hashes/sha1/sha1.c

typedef struct {
u_int32_t state[5];
u_int32_t count[2];
u_int8_t buffer[64];
unsigned long state[5];
unsigned long count[2];
unsigned char buffer[64];
} SHA1_CTX;

extern void SHA1Init(SHA1_CTX* context);
extern void SHA1Update(SHA1_CTX* context, u_int8_t* data, u_int32_t len);
extern void SHA1Final(u_int8_t digest[20], SHA1_CTX* context);
extern void SHA1Update(SHA1_CTX* context, unsigned char* data, unsigned int len);
extern void SHA1Final(unsigned char digest[20], SHA1_CTX* context);
6 changes: 2 additions & 4 deletions OAHMAC_SHA1SignatureProvider.m
Expand Up @@ -36,12 +36,10 @@ - (NSString *)name {
}

- (NSString *)signClearText:(NSString *)text withSecret:(NSString *)secret {
NSData *secretData = [[secret dataUsingEncoding:NSUTF8StringEncoding] retain];
NSData *clearTextData = [[text dataUsingEncoding:NSUTF8StringEncoding] retain];
NSData *secretData = [secret dataUsingEncoding:NSUTF8StringEncoding];
NSData *clearTextData = [text dataUsingEncoding:NSUTF8StringEncoding];
unsigned char result[20];
hmac_sha1((unsigned char *)[clearTextData bytes], [clearTextData length], (unsigned char *)[secretData bytes], [secretData length], result);
[secretData release];
[clearTextData release];

//Base64 Encoding

Expand Down

0 comments on commit f19befe

Please sign in to comment.