/*
 * Reusable init function.
 */
void sha1Reinit(sha1Obj sha1)
{
	sha1Inst *sinst = (sha1Inst *) sha1;

	shsInit(&sinst->context);
	sinst->isDone = 0;
	sinst->bufBytes = 0;
}
/*
 * Alloc and init an empty sha1 object.
 */
sha1Obj sha1Alloc(void)
{
	sha1Inst *sinst;

	sinst = (sha1Inst *)fmalloc(sizeof(sha1Inst));
	if(sinst == NULL) {
		return NULL;
	}
	shsInit(&sinst->context);
	sha1Reinit((sha1Obj)sinst);
	return (sha1Obj)sinst;
}
Beispiel #3
0
char * shs_crypt(const unsigned char * pw,
                 const Int pl,
                 const unsigned char * sp,
                 const Int sl,
                 char * passwd)
{
    uChar *p;
    uChar    final[SHS_DIGEST_SIZE];
    Int i,j;
    SHS_CTX    ctx,ctx1;
    uInt l;

    shsInit(&ctx);

    /* The password first, since that is what is most unknown */
    shsUpdate(&ctx,pw,pl);

    /* Then our magic string */
    shsUpdate(&ctx,(uChar *)"$2$",3);

    /* Then the raw salt */
    shsUpdate(&ctx,sp,sl);

    /* Then just as many characters of the shs(pw,salt,pw) */
    shsInit(&ctx1);
    shsUpdate(&ctx1,pw,pl);
    shsUpdate(&ctx1,sp,sl);
    shsUpdate(&ctx1,pw,pl);
    shsFinal(&ctx1,final);
    for(i = pl; i > 0; i -= SHS_DIGEST_SIZE)
        shsUpdate(&ctx,final,i>SHS_DIGEST_SIZE ? SHS_DIGEST_SIZE : i);

    /* Don't leave anything around in vm they could use. */
    memset(final,0,sizeof final);

    /* Then something really weird... */
    for (j=0,i = pl; i ; i >>= 1)
        if(i&1)
            shsUpdate(&ctx, final+j, 1);
        else
BSTR CMUSHclientDoc::Hash(LPCTSTR Text) 
{
	CString strResult;

  SHS_INFO shsInfo;
  shsInit   (&shsInfo);
  shsUpdate (&shsInfo, (unsigned char *) (const char *) Text, 
              strlen (Text));
  shsFinal  (&shsInfo);

  for (int i = 0; i < NUMITEMS (shsInfo.digest); i++)
    strResult += CFormat ("%08x", shsInfo.digest [i]);

	return strResult.AllocSysString();
}   // end of CMUSHclientDoc::Hash
Beispiel #5
0
static krb5_error_code
k5_sha1_hash(unsigned int icount, const krb5_data *input,
	     krb5_data *output)
{
    SHS_INFO ctx;
    unsigned int i;

    if (output->length != SHS_DIGESTSIZE)
	return(KRB5_CRYPTO_INTERNAL);

    shsInit(&ctx);
    for (i=0; i<icount; i++)
	shsUpdate(&ctx, (unsigned char *) input[i].data, input[i].length);
    shsFinal(&ctx);

    for (i=0; i<(sizeof(ctx.digest)/sizeof(ctx.digest[0])); i++) {
	store_32_be(ctx.digest[i], &output->data[i*4]);
    }

    return(0);
}
Beispiel #6
0
static int myhash (lua_State *L)
  {
  // get text to hash
  size_t textLength;
  const char * text = luaL_checklstring (L, 1, &textLength);
  char buf [50];

  SHS_INFO shsInfo;
  shsInit   (&shsInfo);
  shsUpdate (&shsInfo, (UC *) text, textLength);
  shsFinal  (&shsInfo);

  sprintf (buf, "%08x%08x%08x%08x%08x", 
                shsInfo.digest [0],
                shsInfo.digest [1],
                shsInfo.digest [2],
                shsInfo.digest [3],
                shsInfo.digest [4]
                );

  lua_pushstring (L, buf);

  return 1;  // number of result fields
  } // end of myhash