plugins/jabber/digest.c File Reference

#include "ekg2-config.h"
#include <ekg/win32.h>
#include <ekg/debug.h>
#include <ekg/recode.h>
#include <stdint.h>
#include <ekg/stuff.h>
#include <ekg/xmalloc.h>
#include "jabber.h"
#include <stdio.h>
#include <string.h>

Data Structures

struct  EKG2_SHA1_CTX

Defines

#define LITTLE_ENDIAN
#define SHA1HANDSOFF
#define SHA1Init(ctx)   Init(ctx, 1)
#define SHA1Transform(state, buffer)   Transform(state, buffer, 1)
#define SHA1Update(ctx, data, len)   Update(ctx, (unsigned char *) data, len, 1)
#define SHA1Final(digest, ctx)   Final(digest, ctx, 1)
#define MD5Init(ctx)   Init(ctx, 0)
#define MD5Transform(state, buffer)   Transform(state, buffer, 0)
#define MD5Update(ctx, data, len)   Update(ctx, (unsigned char *) data, len, 0)
#define MD5Final(digest, ctx)   Final(digest, ctx, 0)
#define rol(value, bits)   (((value) << (bits)) | ((value) >> (32 - (bits))))
#define blk0(i)
#define blk(i)
#define R0(v, w, x, y, z, i)   z+=((w&(x^y))^y)+blk0(i)+0x5A827999+rol(v,5);w=rol(w,30);
#define R1(v, w, x, y, z, i)   z+=((w&(x^y))^y)+blk(i)+0x5A827999+rol(v,5);w=rol(w,30);
#define R2(v, w, x, y, z, i)   z+=(w^x^y)+blk(i)+0x6ED9EBA1+rol(v,5);w=rol(w,30);
#define R3(v, w, x, y, z, i)   z+=(((w|x)&y)|(w&x))+blk(i)+0x8F1BBCDC+rol(v,5);w=rol(w,30);
#define R4(v, w, x, y, z, i)   z+=(w^x^y)+blk(i)+0xCA62C1D6+rol(v,5);w=rol(w,30);
#define F(x, y, z)   (((x) & (y)) | ((~x) & (z)))
#define G(x, y, z)   (((x) & (z)) | ((y) & (~z)))
#define H(x, y, z)   ((x) ^ (y) ^ (z))
#define I(x, y, z)   ((y) ^ ((x) | (~z)))
#define FF(a, b, c, d, x, s, ac)   { (a) += F ((b), (c), (d)) + (x) + (uint32_t)(ac); (a) = rol((a), (s)); (a) += (b); }
#define GG(a, b, c, d, x, s, ac)   { (a) += G ((b), (c), (d)) + (x) + (uint32_t)(ac); (a) = rol((a), (s)); (a) += (b); }
#define HH(a, b, c, d, x, s, ac)   { (a) += H ((b), (c), (d)) + (x) + (uint32_t)(ac); (a) = rol((a), (s)); (a) += (b); }
#define II(a, b, c, d, x, s, ac)   { (a) += I ((b), (c), (d)) + (x) + (uint32_t)(ac); (a) = rol((a), (s)); (a) += (b); }
#define S11   7
#define S12   12
#define S13   17
#define S14   22
#define S21   5
#define S22   9
#define S23   14
#define S24   20
#define S31   4
#define S32   11
#define S33   16
#define S34   23
#define S41   6
#define S42   10
#define S43   15
#define S44   21

Typedefs

typedef struct EKG2_SHA1_CTX EKG2_MD5_CTX

Functions

static void Init (EKG2_SHA1_CTX *context, int usesha)
static void Transform (uint32_t state[5], unsigned char buffer[64], int usesha)
static void Update (EKG2_SHA1_CTX *context, unsigned char *data, unsigned int len, int usesha)
static void Final (unsigned char digest[20], EKG2_SHA1_CTX *context, int usesha)
static void Encode (unsigned char *output, uint32_t *input, unsigned int len, int usesha)
static char * base16_encode (const unsigned char *data)
char * jabber_challange_digest (const char *sid, const char *password, const char *nonce, const char *cnonce, const char *xmpp_temp, const char *realm)
char * jabber_dcc_digest (char *sid, char *initiator, char *target)
char * jabber_digest (const char *sid, const char *password, int istlen)
char * jabber_sha1_generic (char *buf, int len)

Variables

char * config_console_charset

Define Documentation

#define blk ( i   ) 

Value:

(block->l[i&15] = rol(block->l[(i+13)&15]^block->l[(i+8)&15] \
    ^block->l[(i+2)&15]^block->l[i&15],1))

#define blk0 ( i   ) 

Value:

(block->l[i] = (rol(block->l[i],24)&0xFF00FF00) \
    |(rol(block->l[i],8)&0x00FF00FF))

#define F ( x,
y,
 )     (((x) & (y)) | ((~x) & (z)))

#define FF ( a,
b,
c,
d,
x,
s,
ac   )     { (a) += F ((b), (c), (d)) + (x) + (uint32_t)(ac); (a) = rol((a), (s)); (a) += (b); }

#define G ( x,
y,
 )     (((x) & (z)) | ((y) & (~z)))

#define GG ( a,
b,
c,
d,
x,
s,
ac   )     { (a) += G ((b), (c), (d)) + (x) + (uint32_t)(ac); (a) = rol((a), (s)); (a) += (b); }

#define H ( x,
y,
 )     ((x) ^ (y) ^ (z))

#define HH ( a,
b,
c,
d,
x,
s,
ac   )     { (a) += H ((b), (c), (d)) + (x) + (uint32_t)(ac); (a) = rol((a), (s)); (a) += (b); }

#define I ( x,
y,
 )     ((y) ^ ((x) | (~z)))

#define II ( a,
b,
c,
d,
x,
s,
ac   )     { (a) += I ((b), (c), (d)) + (x) + (uint32_t)(ac); (a) = rol((a), (s)); (a) += (b); }

#define LITTLE_ENDIAN

#define MD5Final ( digest,
ctx   )     Final(digest, ctx, 0)

#define MD5Init ( ctx   )     Init(ctx, 0)

#define MD5Transform ( state,
buffer   )     Transform(state, buffer, 0)

#define MD5Update ( ctx,
data,
len   )     Update(ctx, (unsigned char *) data, len, 0)

#define R0 ( v,
w,
x,
y,
z,
i   )     z+=((w&(x^y))^y)+blk0(i)+0x5A827999+rol(v,5);w=rol(w,30);

#define R1 ( v,
w,
x,
y,
z,
i   )     z+=((w&(x^y))^y)+blk(i)+0x5A827999+rol(v,5);w=rol(w,30);

#define R2 ( v,
w,
x,
y,
z,
i   )     z+=(w^x^y)+blk(i)+0x6ED9EBA1+rol(v,5);w=rol(w,30);

#define R3 ( v,
w,
x,
y,
z,
i   )     z+=(((w|x)&y)|(w&x))+blk(i)+0x8F1BBCDC+rol(v,5);w=rol(w,30);

#define R4 ( v,
w,
x,
y,
z,
i   )     z+=(w^x^y)+blk(i)+0xCA62C1D6+rol(v,5);w=rol(w,30);

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

#define S11   7

#define S12   12

#define S13   17

#define S14   22

#define S21   5

#define S22   9

#define S23   14

#define S24   20

#define S31   4

#define S32   11

#define S33   16

#define S34   23

#define S41   6

#define S42   10

#define S43   15

#define S44   21

#define SHA1Final ( digest,
ctx   )     Final(digest, ctx, 1)

#define SHA1HANDSOFF

#define SHA1Init ( ctx   )     Init(ctx, 1)

#define SHA1Transform ( state,
buffer   )     Transform(state, buffer, 1)

#define SHA1Update ( ctx,
data,
len   )     Update(ctx, (unsigned char *) data, len, 1)


Typedef Documentation

typedef struct EKG2_SHA1_CTX EKG2_MD5_CTX


Function Documentation

static char* base16_encode ( const unsigned char *  data  )  [static]

base16_encode()

Return base16 hash of data

Returns:
static with 32 digit BASE16 HASH + NUL char.

static void Encode ( unsigned char *  output,
uint32_t *  input,
unsigned int  len,
int  usesha 
) [static]

static void Final ( unsigned char  digest[20],
EKG2_SHA1_CTX context,
int  usesha 
) [static]

static void Init ( EKG2_SHA1_CTX context,
int  usesha 
) [static]

char* jabber_challange_digest ( const char *  sid,
const char *  password,
const char *  nonce,
const char *  cnonce,
const char *  xmpp_temp,
const char *  realm 
)

jabber_challange_digest()

Return base16 encoded hash for SASL MD5 CHALLANGE

Todo:
MD5Update() on NULL params will fail. XXX, no idea what to do.
Returns:
static buffer with 32 digit BASE16 HASH + NUL char

char* jabber_dcc_digest ( char *  sid,
char *  initiator,
char *  target 
)

jabber_dcc_digest()

Return SHA1 hash for SOCKS5 Bytestreams connections [DCC]
Make SHA1Update()'s on (uid, initiator and target)

Todo:
SHA1Update() on NULL params will fail. XXX, no idea what to do.
Todo:
We don't reencode params here to utf-8.
Returns:
static buffer, with 40 digit SHA1 hash + NUL char

char* jabber_digest ( const char *  sid,
const char *  password,
int  istlen 
)

jabber_digest()

Return SHA1 hash for jabber:iq:auth
Make SHA1Update()'s on recoded to utf-8 (sid and password)

Todo:
SHA1Update() on NULL params will fail. XXX, no idea what to do.
Returns:
static buffer, with 40 digit SHA1 hash + NUL char

char* jabber_sha1_generic ( char *  buf,
int  len 
)

static void Transform ( uint32_t  state[5],
unsigned char  buffer[64],
int  usesha 
) [static]

static void Update ( EKG2_SHA1_CTX context,
unsigned char *  data,
unsigned int  len,
int  usesha 
) [static]


Variable Documentation

char* config_console_charset


Generated on Tue Jan 6 22:30:49 2009 for ekg2 by  doxygen 1.5.1