It may be your code that converts to hex for printing. Notice how neither of your hashes is 40 characters long? Try using my to_hex() method below.
python ==> '7110eda4d09e062aa5e4a390b0a572ac0d2c0220'
string result: 7110eda4d09e62aa5e4a390b0a572acd2c220
integer result: c7f07b846cc46631c2079cdd7179afdd783d643
I also couldn't reproduce your C results. Here's an OSX version:
#include <stdio.h>
#include <CommonCrypto/CommonDigest.h>
char *to_hex(unsigned char *buffer, size_t len) {
static char out[100];
char *p = out;
while (len--)
p += sprintf(p, "%02x", *buffer++);
*p = 0;
return out;
}
int main() {
unsigned char buffer[21] = { 0 };
printf("SHA1(\"1234\") = %s\n", to_hex(CC_SHA1("1234", 4, buffer), 20));
unsigned n = 1234;
printf("1234 LE = %s\n", to_hex(&n, 4));
printf("SHA1(1234 LE) = %s\n", to_hex(CC_SHA1(&n, 4, buffer), 20));
n = htonl(n);
printf("1234 BE = %s\n", to_hex(&n, 4));
printf("SHA1(1234 BE) = %s\n", to_hex(CC_SHA1(&n, 4, buffer), 20));
return 0;
}
and here's the Android version
#include <stdio.h>
#include "mincrypt/sha.h"
char *to_hex(unsigned char *buffer, size_t len) {
static char out[100];
char *p = out;
while (len--)
p += sprintf(p, "%02x", *buffer++);
*p = 0;
return out;
}
int main() {
unsigned char buffer[21] = { 0 };
printf("SHA1(\"1234\") = %s\n", to_hex(SHA1_hash("1234", 4, buffer), 20));
unsigned n = 1234;
printf("1234 LE = %s\n", to_hex(&n, 4));
printf("SHA1(1234 LE) = %s\n", to_hex(SHA1_hash(&n, 4, buffer), 20));
n = htonl(n);
printf("1234 BE = %s\n", to_hex(&n, 4));
printf("SHA1(1234 BE) = %s\n", to_hex(SHA1_hash(&n, 4, buffer), 20));
return 0;
}
that file is in system/core/libmincrypt
and compiled with cc -I../include -o sha_test sha_test.c sha.c
both programs yield the same results
SHA1("1234") = 7110eda4d09e062aa5e4a390b0a572ac0d2c0220
1234 LE = d2040000
SHA1(1234 LE) = 7b08e025e311c3dfcf5179b67c0fdc08e73de261
1234 BE = 000004d2
SHA1(1234 BE) = ac9928e78cf6ea117451ecd6654fea2adae73e21