Esempio n. 1
0
static foreign_t
pl_sha_new_ctx(term_t ctx, term_t options)
{ struct context c;
  optval *op = &(c.opts);

  if ( !sha_options(options, op) )
    return FALSE;

  c.magic = CONTEXT_MAGIC;

  if ( op->algorithm == ALGORITHM_SHA1 )
  { sha1_begin(&(c.context.sha1));
  } else
  { sha2_begin((unsigned long) op->digest_size, &(c.context.sha2));
  }

  /* NB: the context size depends on the digest size */
  /* (e. g., sha512_ctx is twice as long as sha256_ctx) */
  /* so there're extra data.  It will do no harm, though. */
  /* . */
  return PL_unify_string_nchars(ctx, sizeof(c), (char*)&c);
}
Esempio n. 2
0
std::string vmsHash::Hash_SHA2(LPCSTR pszFile)
{
	sha2_ctx sha2;
	vmsFile file;
	__int64 trb = 0;
	BYTE abBuf [16000];

	sha2_begin (m_nSHA2Strength, &sha2);

	try {
		
	file.Open (pszFile, TRUE);
	__int64 uSize = file.get_Size ();
	DWORD dwRead;
	while (dwRead = file.Read (abBuf, sizeof (abBuf))) 
	{
		sha2_hash (abBuf, dwRead, &sha2);
		trb += dwRead;
		if (m_pEvents) 
		{
			double f = (double)trb / uSize * 100;
			if (false == m_pEvents->OnProgressChanged (f)) {
				trb = 0;
				break;
			}
		}
	}

	BYTE abRes [256];
	sha2_end (abRes, &sha2);

	if (trb == 0 && uSize != 0)
		return "";
	
	return Hash_ResultToStr (abRes, m_nSHA2Strength / 8);

	}catch (...) {return "";}
}