2 ** Copyright 1998 - 1999 Double Precision, Inc.
3 ** See COPYING for distribution information.
13 struct hmac_hashinfo
*hmac_list
[]= {HMAC_LIST
};
16 const struct hmac_hashinfo
*hh
;
19 unsigned char *kxopad
;
20 unsigned char *kxipad
;
25 static void dohashkey(unsigned char *, void *);
26 static void docalcc(void *, void *);
28 void hmac_hashkey(const struct hmac_hashinfo
*hh
, const char *k
,
29 size_t kl
, unsigned char *kxopad
, unsigned char *kxipad
)
39 (*hh
->hh_allocacontext
)( docalcc
, (void *)&i
);
42 static void dokeycalc(struct hhki
*);
44 static void docalcc(void *c
, void *v
)
46 struct hhki
*i
=(struct hhki
*)v
;
50 if (i
->kl
> i
->hh
->hh_B
)
51 (*i
->hh
->hh_allocaval
)(dohashkey
, (void *)i
);
56 static void dohashkey(unsigned char *keybuf
, void *v
)
58 struct hhki
*i
=(struct hhki
*)v
;
60 (*i
->hh
->hh_init
)(i
->context
);
61 (*i
->hh
->hh_hash
)(i
->context
, i
->k
, i
->kl
);
62 (*i
->hh
->hh_endhash
)(i
->context
, i
->kl
);
63 (*i
->hh
->hh_getdigest
)(i
->context
, keybuf
);
69 static void dokeycalc(struct hhki
*i
)
71 char buf
[64]; /* Random guess :-) */
75 (*i
->hh
->hh_init
)(i
->context
);
77 for (l
=0; l
<i
->hh
->hh_B
; l
++)
79 buf
[n
] = ( l
< i
->kl
? i
->k
[l
]:0) ^ 0x5C;
80 if ( ++n
>= sizeof(buf
))
82 (*i
->hh
->hh_hash
)(i
->context
, buf
, sizeof(buf
));
87 (*i
->hh
->hh_hash
)(i
->context
, buf
, n
);
88 (*i
->hh
->hh_getdigest
)(i
->context
, i
->kxopad
);
90 (*i
->hh
->hh_init
)(i
->context
);
92 for (l
=0; l
<i
->hh
->hh_B
; l
++)
94 buf
[n
] = ( l
< i
->kl
? i
->k
[l
]:0) ^ 0x36;
95 if ( ++n
>= sizeof(buf
))
97 (*i
->hh
->hh_hash
)(i
->context
, buf
, sizeof(buf
));
102 (*i
->hh
->hh_hash
)(i
->context
, buf
, n
);
103 (*i
->hh
->hh_getdigest
)(i
->context
, i
->kxipad
);
107 const struct hmac_hashinfo
*hh
;
110 const unsigned char *kxopad
;
111 const unsigned char *kxipad
;
115 static void docalch(void *, void *);
118 const struct hmac_hashinfo
*hh
,
121 const unsigned char *kxopad
,
122 const unsigned char *kxipad
,
134 (*hh
->hh_allocacontext
)( docalch
, (void *)&o
);
137 static void docalch(void *c
, void *v
)
139 struct hhko
*o
=(struct hhko
*)v
;
141 (o
->hh
->hh_setdigest
)(c
, o
->kxipad
);
142 (o
->hh
->hh_hash
)(c
, o
->t
, o
->tl
);
143 (o
->hh
->hh_endhash
)(c
, o
->tl
+o
->hh
->hh_B
);
144 (o
->hh
->hh_getdigest
)(c
, o
->hash
);
146 (o
->hh
->hh_setdigest
)(c
, o
->kxopad
);
147 (o
->hh
->hh_hash
)(c
, o
->hash
, o
->hh
->hh_L
);
148 (o
->hh
->hh_endhash
)(c
, o
->hh
->hh_L
+ o
->hh
->hh_B
);
149 (o
->hh
->hh_getdigest
)(c
, o
->hash
);