3

I'm having a small issue getting the sha1 function to work in G-WAN.

Basically i have the string i want to hash, I'm new to C in general so any pointers would be great.

This is the string im trying to sha1 hash, I'v tried several approaches but I'm not sure what I'm doing wrong.

u8 *input = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";

I almost have websockets working with G-wan and the last thing is getting this sha1 function to cooperate with me.

Documentation on G-wans sha1 function is below

// u8 dst[20]; // the resulting 160-bit hash
// sha1_t ctx;
// sha1_init(&ctx);
// int i = 10;
// while(i--)
//    sha1_add(&ctx, data[i].ptr, data[i].len);
// sha1_end(&ctx, dst);

typedef struct { u8 x[220]; } sha1_t;
void sha1_init(sha1_t *ctx);
void sha1_add (sha1_t *ctx, u8 *src, int srclen);
void sha1_end (sha1_t *ctx, u8 *dst);
// a wrapper on all the above SHA-160 calls
void sha1(u8 *input, int ilen, u8 *dst);

Link to there api http://gwan.com/api

If anyone could throw me a bone here It would make my last hours with C a tad bit forgiving.

Gil
  • 3,279
  • 1
  • 15
  • 25
tomek
  • 35
  • 3
  • 1
    Can you provide the lines of source involving the call to the sha1 hash function? And also the error messages or logs that you are seeing as well as a description of the software behavior? – Richard Chambers Nov 06 '12 at 15:28
  • I wouldn't be abel to provide source let alone find it TBH. The only error in logs that I have is "bug in web.c" & too few arguments to function sha1. Then results in page crash with a 404 served. Thanks for the reply appreciate it. :) Just got it to give me another error which is last arg is incompatible pointer. – tomek Nov 06 '12 at 15:48
  • I am a bit confused as to how you expect to make changes to source that you are not able to provide. The logs are indicating that there is something wrong with the arguments provided. I can not tell whether this is a compilation error or a run time error. Without additional information about your environment and the software behavior, I can not help you. Having the actual error messages and logs would also be handy. – Richard Chambers Nov 06 '12 at 16:22
  • G-WAN v3.6 fixed an SHA calculation bug, here is the to-be-published timeline: *"fixed an sha2() glitch breaking the feature, thanks Richard for the report"*. That does not seem to be related to this question but it might be relevant to know before you meet that issue. – Gil Nov 07 '12 at 07:49

1 Answers1

2

Here's a sample on how to use sha1 function.

u8 input[] = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
u8 result[20];

sha1(input, sizeof(input) - 1, result);
xbuf_xcat(get_reply(argv), "SHA1 Result: %20B", result);

The result is binary so you need to convert it to B64 or HEX to make it readable. '%B' is a B64 conversion in G-WAN. '%20B' tells it to convert the first 20 bytes.

Result:

SHA1 Result: Kfh9QIsMVZcl6xEPYxPHzW8SZ8w=

Richard Heath
  • 349
  • 3
  • 12