#include "puzzles.h"
-typedef unsigned long uint32;
-
-typedef struct {
- uint32 h[5];
- unsigned char block[64];
- int blkused;
- uint32 lenhi, lenlo;
-} SHA_State;
-
/* ----------------------------------------------------------------------
* Core SHA algorithm: processes 16-word blocks into a message digest.
*/
* the end, and pass those blocks to the core SHA algorithm.
*/
-static void SHA_Init(SHA_State * s)
+void SHA_Init(SHA_State * s)
{
SHA_Core_Init(s->h);
s->blkused = 0;
s->lenhi = s->lenlo = 0;
}
-static void SHA_Bytes(SHA_State * s, void *p, int len)
+void SHA_Bytes(SHA_State * s, void *p, int len)
{
unsigned char *q = (unsigned char *) p;
uint32 wordblock[16];
}
}
-static void SHA_Final(SHA_State * s, unsigned char *output)
+void SHA_Final(SHA_State * s, unsigned char *output)
{
int i;
int pad;
}
}
-static void SHA_Simple(void *p, int len, unsigned char *output)
+void SHA_Simple(void *p, int len, unsigned char *output)
{
SHA_State s;
unsigned long random_bits(random_state *state, int bits)
{
- int ret = 0;
+ unsigned long ret = 0;
int n;
for (n = 0; n < bits; n += 8) {
ret = (ret << 8) | state->databuf[state->pos++];
}
- ret &= (1 << bits) - 1;
+ /*
+ * `(1 << bits) - 1' is not good enough, since if bits==32 on a
+ * 32-bit machine, behaviour is undefined and Intel has a nasty
+ * habit of shifting left by zero instead. We'll shift by
+ * bits-1 and then separately shift by one.
+ */
+ ret &= (1 << (bits-1)) * 2 - 1;
return ret;
}