Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Revert "Revert "changed types to u_int32_t and u_int8_t to make code …

…x86_64 portable""

This reverts commit f19befe.
  • Loading branch information...
commit 5f239f7665e87428c3e97b13dfe7c891776dd4c0 1 parent f19befe
@jdg authored
View
18 Crytpo/hmac.c
@@ -33,14 +33,14 @@
#include <stdlib.h>
#include <string.h>
-void hmac_sha1(const unsigned char *inText, size_t inTextLength, unsigned char* inKey, size_t inKeyLength, unsigned char *outDigest)
+void hmac_sha1(const u_int8_t *inText, size_t inTextLength, u_int8_t* inKey, size_t inKeyLength, u_int8_t *outDigest)
{
-const size_t B = 64;
-const size_t L = 20;
+#define B 64
+#define L 20
SHA1_CTX theSHA1Context;
-unsigned char k_ipad[B + 1]; /* inner padding - key XORd with ipad */
-unsigned char k_opad[B + 1]; /* outer padding - key XORd with opad */
+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 */
/* if key is longer than 64 bytes reset it to key=SHA1 (key) */
if (inKeyLength > B)
@@ -70,8 +70,8 @@ for (i = 0; i < B; i++)
*/
SHA1Init(&theSHA1Context); /* init context for 1st pass */
SHA1Update(&theSHA1Context, k_ipad, B); /* start with inner pad */
-SHA1Update(&theSHA1Context, (unsigned char *)inText, inTextLength); /* then text of datagram */
-SHA1Final((unsigned char *)outDigest, &theSHA1Context); /* finish up 1st pass */
+SHA1Update(&theSHA1Context, (u_int8_t *)inText, inTextLength); /* then text of datagram */
+SHA1Final((u_int8_t *)outDigest, &theSHA1Context); /* finish up 1st pass */
/*
* perform outer SHA1
@@ -79,8 +79,8 @@ SHA1Final((unsigned char *)outDigest, &theSHA1Context); /* finish
SHA1Init(&theSHA1Context); /* init context for 2nd
* pass */
SHA1Update(&theSHA1Context, k_opad, B); /* start with outer pad */
-SHA1Update(&theSHA1Context, outDigest, L); /* then results of 1st
+SHA1Update(&theSHA1Context, (u_int8_t *)outDigest, L); /* then results of 1st
* hash */
-SHA1Final(outDigest, &theSHA1Context); /* finish up 2nd pass */
+SHA1Final((u_int8_t *)outDigest, &theSHA1Context); /* finish up 2nd pass */
}
View
2  Crytpo/hmac.h
@@ -26,6 +26,6 @@
#ifndef HMAC_H
#define HMAC_H 1
-extern void hmac_sha1(const unsigned char *inText, int inTextLength, unsigned char* inKey, const unsigned int inKeyLength, unsigned char *outDigest);
+extern void hmac_sha1(const u_int8_t *inText, size_t inTextLength, u_int8_t* inKey, const size_t inKeyLength, u_int8_t *outDigest);
#endif /* HMAC_H */
View
28 Crytpo/sha1.c
@@ -23,7 +23,7 @@ A million repetitions of "a"
#include "sha1.h"
-void SHA1Transform(unsigned long state[5], unsigned char buffer[64]);
+void SHA1Transform(u_int32_t state[5], u_int8_t buffer[64]);
#define rol(value, bits) (((value) << (bits)) | ((value) >> (32 - (bits))))
@@ -48,16 +48,16 @@ void SHA1Transform(unsigned long state[5], unsigned char buffer[64]);
/* Hash a single 512-bit block. This is the core of the algorithm. */
-void SHA1Transform(unsigned long state[5], unsigned char buffer[64])
+void SHA1Transform(u_int32_t state[5], u_int8_t buffer[64])
{
-unsigned long a, b, c, d, e;
+u_int32_t a, b, c, d, e;
typedef union {
- unsigned char c[64];
- unsigned long l[16];
+ u_int8_t c[64];
+ u_int32_t l[16];
} CHAR64LONG16;
CHAR64LONG16* block;
#ifdef SHA1HANDSOFF
-static unsigned char workspace[64];
+static u_int8_t workspace[64];
block = (CHAR64LONG16*)workspace;
memcpy(block, buffer, 64);
#else
@@ -117,7 +117,7 @@ void SHA1Init(SHA1_CTX* context)
/* Run your data through this. */
-void SHA1Update(SHA1_CTX* context, unsigned char* data, unsigned int len)
+void SHA1Update(SHA1_CTX* context, u_int8_t* data, unsigned int len)
{
unsigned int i, j;
@@ -139,22 +139,22 @@ unsigned int i, j;
/* Add padding and return the message digest. */
-void SHA1Final(unsigned char digest[20], SHA1_CTX* context)
+void SHA1Final(u_int8_t digest[20], SHA1_CTX* context)
{
-unsigned long i, j;
-unsigned char finalcount[8];
+u_int32_t i, j;
+u_int8_t finalcount[8];
for (i = 0; i < 8; i++) {
- finalcount[i] = (unsigned char)((context->count[(i >= 4 ? 0 : 1)]
+ finalcount[i] = (u_int8_t)((context->count[(i >= 4 ? 0 : 1)]
>> ((3-(i & 3)) * 8) ) & 255); /* Endian independent */
}
- SHA1Update(context, (unsigned char *)"\200", 1);
+ SHA1Update(context, (u_int8_t *)"\200", 1);
while ((context->count[0] & 504) != 448) {
- SHA1Update(context, (unsigned char *)"\0", 1);
+ SHA1Update(context, (u_int8_t *)"\0", 1);
}
SHA1Update(context, finalcount, 8); /* Should cause a SHA1Transform() */
for (i = 0; i < 20; i++) {
- digest[i] = (unsigned char)
+ digest[i] = (u_int8_t)
((context->state[i>>2] >> ((3-(i & 3)) * 8) ) & 255);
}
/* Wipe variables */
View
10 Crytpo/sha1.h
@@ -2,11 +2,11 @@
// From http://www.mirrors.wiretapped.net/security/cryptography/hashes/sha1/sha1.c
typedef struct {
- unsigned long state[5];
- unsigned long count[2];
- unsigned char buffer[64];
+ u_int32_t state[5];
+ u_int32_t count[2];
+ u_int8_t buffer[64];
} SHA1_CTX;
extern void SHA1Init(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);
+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);
View
6 OAHMAC_SHA1SignatureProvider.m
@@ -36,10 +36,12 @@ - (NSString *)name {
}
- (NSString *)signClearText:(NSString *)text withSecret:(NSString *)secret {
- NSData *secretData = [secret dataUsingEncoding:NSUTF8StringEncoding];
- NSData *clearTextData = [text dataUsingEncoding:NSUTF8StringEncoding];
+ NSData *secretData = [[secret dataUsingEncoding:NSUTF8StringEncoding] retain];
+ NSData *clearTextData = [[text dataUsingEncoding:NSUTF8StringEncoding] retain];
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
Please sign in to comment.
Something went wrong with that request. Please try again.