Пример #1
0
static void
hmac_sha384_final(hmac_sha384_ctx *ctx, unsigned char *hmac)
{
    unsigned char digest_inside[SHA384_DIGEST_LEN];

    SHA384_Final(digest_inside, &ctx->ctx_inside);
    SHA384_Update(&ctx->ctx_outside, digest_inside, SHA384_DIGEST_LEN);
    SHA384_Final(hmac, &ctx->ctx_outside);

    return;
}
Пример #2
0
static void crypt_all(int count)
{
	SHA512_CTX ctx;

	SHA384_Init( &ctx );
	SHA384_Update( &ctx, ipad, PAD_SIZE );
	SHA384_Update( &ctx, cursalt, strlen( (char*) cursalt) );
	SHA384_Final( (unsigned char*) crypt_key, &ctx);

	SHA384_Init( &ctx );
	SHA384_Update( &ctx, opad, PAD_SIZE );
	SHA384_Update( &ctx, crypt_key, BINARY_SIZE);
	SHA384_Final( (unsigned char*) crypt_key, &ctx);
}
Пример #3
0
int
ds_sha384_hash_is_equal(u_char * name_n,
                        u_char * rrdata,
                        size_t rrdatalen, 
                        u_char * ds_hash,
                        size_t ds_hash_len)
{
    u_char        ds_digest[SHA384_DIGEST_LENGTH];
    size_t        namelen;
    SHA512_CTX    c;
    size_t          l_index;
    u_char        qc_name_n[NS_MAXCDNAME];

    if (rrdata == NULL || ds_hash_len != SHA384_DIGEST_LENGTH)
        return 0;

    namelen = wire_name_length(name_n);
    memcpy(qc_name_n, name_n, namelen);
    l_index = 0;
    lower_name(qc_name_n, &l_index);

    memset(ds_digest, 0, SHA384_DIGEST_LENGTH);

    SHA384_Init(&c);
    SHA384_Update(&c, qc_name_n, namelen);
    SHA384_Update(&c, rrdata, rrdatalen);
    SHA384_Final(ds_digest, &c);

    if (!memcmp(ds_digest, ds_hash, SHA384_DIGEST_LENGTH))
        return 1;

    return 0;
}
Пример #4
0
static void
int_sha384_finish(PX_MD *h, uint8 *dst)
{
	SHA384_CTX *ctx = (SHA384_CTX *) h->p.ptr;

	SHA384_Final(dst, ctx);
}
Пример #5
0
static int hash_ssha384(
	const struct berval *scheme,
	const struct berval *passwd,
	struct berval *hash,
	const char **text )
{
	SHA384_CTX ct;
	unsigned char hash384[SHA384_DIGEST_LENGTH];
	char          saltdata[SHA2_SALT_SIZE];
	struct berval digest;
	struct berval salt;

	digest.bv_val = (char *) hash384;
	digest.bv_len = sizeof(hash384);
	salt.bv_val = saltdata;
	salt.bv_len = sizeof(saltdata);

	if (lutil_entropy((unsigned char *)salt.bv_val, salt.bv_len) < 0) {
		return LUTIL_PASSWD_ERR;
	}

	SHA384_Init(&ct);
	SHA384_Update(&ct, (const uint8_t*)passwd->bv_val, passwd->bv_len);
	SHA384_Update(&ct, (const uint8_t*)salt.bv_val, salt.bv_len);
	SHA384_Final(hash384, &ct);

	return lutil_passwd_string64(scheme, &digest, hash, &salt);
}
Пример #6
0
void psSha384Final(psSha384_t *sha384, unsigned char hash[SHA384_HASHLEN])
{
    if (SHA384_Final(hash, sha384) != 1) {
        memset(hash, 0x0, SHA384_HASHLEN);
        memset(sha384, 0x0, sizeof(psSha384_t));
    }
}
Пример #7
0
/**
 * Calculate message digest. SHA context will be invalid after this call.
 * For calculating an other digest you must create new SHA1Digest class.
 *
 * @return returns the calculated digest.
 * @throws IOException throws exception if update failed.
 */
std::vector<unsigned char> digidoc::Digest::getDigest() throw(IOException)
{
    // If digest is already calculated return it.
    if(!d->digest.empty())
        return d->digest;

    int result = 1;
    unsigned char *buf = new unsigned char[getSize()];
    switch(d->method)
    {
    case NID_sha1: result = SHA1_Final(buf, &d->sha1); break;
    case NID_sha224: result = SHA224_Final(buf, &d->sha256); break;
    case NID_sha256: result = SHA256_Final(buf, &d->sha256); break;
    case NID_sha384: result = SHA384_Final(buf, &d->sha512); break;
    case NID_sha512: result = SHA512_Final(buf, &d->sha512); break;
    default:
        break;
    }
    if(result != 1)
    {
        delete[] buf;
        THROW_IOEXCEPTION("Failed to create %s digest: %s", getName().c_str(), ERR_reason_error_string(ERR_get_error()));
    }

    for(unsigned int i = 0; i < getSize(); i++)
        d->digest.push_back(buf[i]);
    delete[] buf;
    return d->digest;
}
Пример #8
0
uint8_t *SHA384(const uint8_t *data, size_t len, uint8_t *out) {
  SHA512_CTX ctx;
  SHA384_Init(&ctx);
  SHA384_Update(&ctx, data, len);
  SHA384_Final(out, &ctx);
  OPENSSL_cleanse(&ctx, sizeof(ctx));
  return out;
}
Пример #9
0
R_API void r_hash_do_end(RHash *ctx, int flags) {
	CHKFLAG (flags, R_HASH_MD5) MD5Final (ctx->digest, &ctx->md5);
	CHKFLAG (flags, R_HASH_SHA1) SHA1_Final (ctx->digest, &ctx->sha1);
	CHKFLAG (flags, R_HASH_SHA256) SHA256_Final (ctx->digest, &ctx->sha256);
	CHKFLAG (flags, R_HASH_SHA384) SHA384_Final (ctx->digest, &ctx->sha384);
	CHKFLAG (flags, R_HASH_SHA512) SHA512_Final (ctx->digest, &ctx->sha512);
	ctx->rst = 1;
}
Пример #10
0
static mrb_value
sha384_digest(mrb_state *mrb, mrb_value self)
{
  char *digest = (char*)mrb_malloc(mrb, SHA384_DIGEST_LENGTH);
  SHA384_CTX ctx = *(SHA384_CTX*)DATA_PTR(self);
  SHA384_Final((u_int8_t *)digest, &ctx);
  return mrb_str_new(mrb, digest, SHA384_DIGEST_LENGTH);
}
Пример #11
0
R_API ut8 *r_hash_do_sha384(RHash *ctx, const ut8 *input, int len) {
	if (len<0) return NULL;
	if (ctx->rst)
		SHA384_Init (&ctx->sha384);
	SHA384_Update (&ctx->sha384, input, len);
	if (ctx->rst || len == 0)
		SHA384_Final (ctx->digest, &ctx->sha384);
	return ctx->digest;
}
Пример #12
0
/* Compute SHA384 hash on in and store the hex string result in out.
*/
void
sha384(unsigned char *out, unsigned char *in, size_t size)
{
    SHA384_CTX    sha384_ctx;

    SHA384_Init(&sha384_ctx);
    SHA384_Update(&sha384_ctx, (const uint8_t*)in, size);
    SHA384_Final(out, &sha384_ctx);
}
Пример #13
0
    Digest Buffer::getSHA384() const
    {
        unsigned char digest[48]={0};
        SHA384_CTX context;

        SHA384_Init(&context);
        SHA384_Update(&context, (unsigned char *)m_data, m_length);
        SHA384_Final(digest, &context);

        return Digest(digest,48);
    }
Пример #14
0
static unsigned 
sha384_finish(__ops_hash_t *hash, uint8_t *out)
{
	SHA384_Final(out, hash->data);
	if (__ops_get_debug_level(__FILE__)) {
		hexdump(stderr, "sha384_finish", out, SHA384_DIGEST_LENGTH);
	}
	free(hash->data);
	hash->data = NULL;
	return SHA384_DIGEST_LENGTH;
}
Пример #15
0
unsigned char *SHA384(const unsigned char *d, size_t n, unsigned char *md)
	{
	SHA512_CTX c;
	static unsigned char m[SHA384_DIGEST_LENGTH];

	if (md == NULL) md=m;
	SHA384_Init(&c);
	SHA384_Update(&c,d,n);
	SHA384_Final(md,&c);
	OPENSSL_cleanse(&c,sizeof(c));
	return(md);
	}
Пример #16
0
static void crypt_all(int count)
{
	int index = 0;
#ifdef _OPENMP
#pragma omp parallel for
	for (index = 0; index < count; index++)
#endif
	{
		SHA512_CTX ctx;

		SHA384_Init( &ctx );
		SHA384_Update( &ctx, ipad[index], PAD_SIZE );
		SHA384_Update( &ctx, cursalt, strlen( (char*) cursalt) );
		SHA384_Final( (unsigned char*) crypt_key[index], &ctx);

		SHA384_Init( &ctx );
		SHA384_Update( &ctx, opad[index], PAD_SIZE );
		SHA384_Update( &ctx, crypt_key[index], BINARY_SIZE);
		SHA384_Final( (unsigned char*) crypt_key[index], &ctx);
	}
}
Пример #17
0
void hash(char *string, char *result) {
	unsigned char hash[SHA384_DIGEST_LENGTH];
	int i = 0;
	SHA384_CTX handler;

	SHA384_Init(&handler);
	SHA384_Update(&handler, string, strlen(string));
	SHA384_Final(hash, &handler);
	memset(result, '\0', strlen(result));
	for (i = 0; i < SHA384_DIGEST_LENGTH; i++) {
		sprintf(result, "%s%02x", result, hash[i]);
	};
}
Пример #18
0
static int hash_final( SRP_HashAlgorithm alg, HashCTX *c, unsigned char *md )
{
    switch (alg)
    {
      case SRP_SHA1  : return SHA1_Final( md, &c->sha );
      case SRP_SHA224: return SHA224_Final( md, &c->sha256 );
      case SRP_SHA256: return SHA256_Final( md, &c->sha256 );
      case SRP_SHA384: return SHA384_Final( md, &c->sha512 );
      case SRP_SHA512: return SHA512_Final( md, &c->sha512 );
      default:
        return -1;
    }
}
Пример #19
0
static void set_key(char *key, int index)
{
	int len;

#ifdef SIMD_COEF_64
	ARCH_WORD_64 *ipadp = (ARCH_WORD_64*)&ipad[GETPOS(7, index)];
	ARCH_WORD_64 *opadp = (ARCH_WORD_64*)&opad[GETPOS(7, index)];
	const ARCH_WORD_64 *keyp = (ARCH_WORD_64*)key;
	ARCH_WORD_64 temp;

	len = strlen(key);
	memcpy(saved_plain[index], key, len);
	saved_plain[index][len] = 0;

#if PAD_SIZE < PLAINTEXT_LENGTH
	if (len > PAD_SIZE) {
		unsigned char k0[BINARY_SIZE];
		SHA512_CTX ctx;
		int i;

		SHA384_Init(&ctx);
		SHA384_Update(&ctx, key, len);
		SHA384_Final(k0, &ctx);

		keyp = (ARCH_WORD_64*)k0;
		for(i = 0; i < BINARY_SIZE / 8; i++, ipadp += SIMD_COEF_64, opadp += SIMD_COEF_64)
		{
			temp = JOHNSWAP64(*keyp++);
			*ipadp ^= temp;
			*opadp ^= temp;
		}
	}
	else
#endif
	while(((temp = JOHNSWAP64(*keyp++)) & 0xff00000000000000)) {
		if (!(temp & 0x00ff000000000000) || !(temp & 0x0000ff0000000000))
		{
			((unsigned short*)ipadp)[3] ^=
				(unsigned short)(temp >> 48);
			((unsigned short*)opadp)[3] ^=
				(unsigned short)(temp >> 48);
			break;
		}
		if (!(temp & 0x00ff00000000) || !(temp & 0x0000ff000000))
		{
			((ARCH_WORD_32*)ipadp)[1] ^=
				(ARCH_WORD_32)(temp >> 32);
			((ARCH_WORD_32*)opadp)[1] ^=
				(ARCH_WORD_32)(temp >> 32);
			break;
		}
Пример #20
0
static unsigned sha384_finish(ops_hash_t *hash,unsigned char *out)
    {
    SHA384_Final(out,hash->data);
    if (debug)
        {
        unsigned i=0;
        fprintf(stderr,"***\n***\nsha1_finish\n***\n");
        for (i=0; i<SHA384_DIGEST_LENGTH; i++)
            fprintf(stderr,"0x%02x ",out[i]);
        fprintf(stderr,"\n");
        }
    free(hash->data);
    hash->data=NULL;
    return SHA384_DIGEST_LENGTH;
    }
Пример #21
0
	/*
		md must have hashSize byte
		@note clear inner buffer after calling digest
	*/
	void digest(char *out, const char *buf, size_t bufSize)
	{
		update(buf, bufSize);
		unsigned char *md = reinterpret_cast<unsigned char*>(out);
		switch (name_) {
		case N_SHA1:   SHA1_Final(md, &ctx_.sha1);     break;
		case N_SHA224: SHA224_Final(md, &ctx_.sha256); break;
		case N_SHA256: SHA256_Final(md, &ctx_.sha256); break;
		case N_SHA384: SHA384_Final(md, &ctx_.sha512); break;
		case N_SHA512: SHA512_Final(md, &ctx_.sha512); break;
		default:
			throw cybozu::Exception("crypto:Hash:digest") << name_;
		}
		reset();
	}
Пример #22
0
std::vector<unsigned char> bdoc::SHA384Digest::getDigest()
{
	if (!digest.empty()) {
		return digest;
	}

	unsigned char buf[SHA384_DIGEST_LENGTH];
	if (SHA384_Final(buf, &ctx) != 1) {
		THROW_STACK_EXCEPTION("Failed to create SHA384 digest: %s", ERR_reason_error_string(ERR_get_error()));
	}

	for (unsigned int i = 0; i < SHA384_DIGEST_LENGTH; i++) {
		digest.push_back(buf[i]);
	}

	return digest;
}
Пример #23
0
static int hash_sha384(
	const struct berval *scheme,
	const struct berval *passwd,
	struct berval *hash,
	const char **text )
{
	SHA384_CTX ct;
	unsigned char hash384[SHA384_DIGEST_LENGTH];
	struct berval digest;
	digest.bv_val = (char *) hash384;
	digest.bv_len = sizeof(hash384);

	SHA384_Init(&ct);
	SHA384_Update(&ct, (const uint8_t*)passwd->bv_val, passwd->bv_len);
	SHA384_Final(hash384, &ct);

	return lutil_passwd_string64(scheme, &digest, hash, NULL);
}
ikptr
ikrt_openssl_sha384_final (ikptr s_ctx, ikpcb * pcb)
{
#ifdef HAVE_SHA384_FINAL
  ikptr		s_pointer	= IK_SHA384_CTX_POINTER(s_ctx);
  SHA384_CTX *	ctx		= IK_POINTER_DATA_VOIDP(s_pointer);
  unsigned char	sum[SHA384_DIGEST_LENGTH];
  int		rv = 0;
  if (ctx) {
    rv = SHA384_Final(sum, ctx);
    free(ctx);
    IK_POINTER_SET_NULL(s_pointer);
  }
  return (rv)? ika_bytevector_from_memory_block(pcb, sum, SHA384_DIGEST_LENGTH) : IK_FALSE;
#else
  feature_failure(__func__);
#endif
}
Пример #25
0
core::data sha2::digest384(core::data const& da)
{
    core::data tmp = da.shadow();
    
    SHA512_CTX ctx;
    SHA384_Init(&ctx);
    
    while (tmp.length())
    {
        SHA384_Update(&ctx, tmp.bytes(), tmp.limit(SHA384_DIGEST_LENGTH));
        tmp.offset(tmp.limit(SHA384_DIGEST_LENGTH));
    }
    
    core::data ret(SHA384_DIGEST_LENGTH);
    SHA384_Final((byte*)ret.bytes(), &ctx);
    
    return ret;
}
static void SHA384_File(FILE *file, unsigned char **output, int *outlength)
{
	*output = new unsigned char[SHA384_DIGEST_LENGTH];
	*outlength = SHA384_DIGEST_LENGTH;

	SHA512_CTX c;
	int i;
	unsigned char buf[SHA384_FILE_BUFFER_SIZE];
	
	SHA384_Init(&c);
	for (;;)
	{
		i = fread(buf,1,SHA384_FILE_BUFFER_SIZE,file);
		if(i <= 0)
			break;
		SHA384_Update(&c,buf,(unsigned long)i);
	}
	SHA384_Final(*output, &c);
}
Пример #27
0
static int chk_sha384(
	const struct berval *scheme, /* Scheme of hashed reference password */
	const struct berval *passwd, /* Hashed reference password to check against */
	const struct berval *cred, /* user-supplied password to check */
	const char **text )
{
	SHA384_CTX SHAcontext;
	unsigned char SHAdigest[SHA384_DIGEST_LENGTH];
	int rc;
	unsigned char *orig_pass = NULL;
	size_t decode_len = LUTIL_BASE64_DECODE_LEN(passwd->bv_len);

	/* safety check */
	if (decode_len < sizeof(SHAdigest)) {
		return LUTIL_PASSWD_ERR;
	}

	/* base64 un-encode password */
	orig_pass = (unsigned char *) ber_memalloc(decode_len + 1);

	if( orig_pass == NULL ) return LUTIL_PASSWD_ERR;

	rc = lutil_b64_pton(passwd->bv_val, orig_pass, decode_len);

	if( rc != sizeof(SHAdigest) ) {
		ber_memfree(orig_pass);
		return LUTIL_PASSWD_ERR;
	}

	/* hash credentials with salt */
	SHA384_Init(&SHAcontext);
	SHA384_Update(&SHAcontext,
		(const unsigned char *) cred->bv_val, cred->bv_len);
	SHA384_Final(SHAdigest, &SHAcontext);

	/* compare */
	rc = memcmp((char *)orig_pass, (char *)SHAdigest, sizeof(SHAdigest));
#ifdef SLAPD_SHA2_DEBUG
	chk_sha_debug(scheme, passwd, cred, (char *)SHAdigest, sizeof(SHAdigest), rc);
#endif
	ber_memfree(orig_pass);
	return rc ? LUTIL_PASSWD_ERR : LUTIL_PASSWD_OK;
}
Пример #28
0
int sha_file(int md_alg, const char *filename, unsigned char *md)
{
	FILE *inFile;
	SHA256_CTX shaContext;
	SHA512_CTX sha512Context;
	int bytes;
	unsigned char data[BUFFER_SIZE];

	if ((filename == NULL) || (md == NULL)) {
		ERROR("%s(): NULL argument\n", __FUNCTION__);
		return 0;
	}

	inFile = fopen(filename, "rb");
	if (inFile == NULL) {
		ERROR("Cannot read %s\n", filename);
		return 0;
	}

	if (md_alg == HASH_ALG_SHA384) {
		SHA384_Init(&sha512Context);
		while ((bytes = fread(data, 1, BUFFER_SIZE, inFile)) != 0) {
			SHA384_Update(&sha512Context, data, bytes);
		}
		SHA384_Final(md, &sha512Context);
	} else if (md_alg == HASH_ALG_SHA512) {
		SHA512_Init(&sha512Context);
		while ((bytes = fread(data, 1, BUFFER_SIZE, inFile)) != 0) {
			SHA512_Update(&sha512Context, data, bytes);
		}
		SHA512_Final(md, &sha512Context);
	} else {
		SHA256_Init(&shaContext);
		while ((bytes = fread(data, 1, BUFFER_SIZE, inFile)) != 0) {
			SHA256_Update(&shaContext, data, bytes);
		}
		SHA256_Final(md, &shaContext);
	}

	fclose(inFile);
	return 1;
}
Пример #29
0
ATF_TC_BODY(t_sha384, tc)
{
	size_t i, j, len;
	SHA384_CTX ctx;
	unsigned char buf[384];
	unsigned char digest[8 + SHA384_DIGEST_LENGTH];
	char output[SHA384_DIGEST_STRING_LENGTH];

	for (i = 0; i < sizeof(test384) / sizeof(test384[0]); ++i) {
		len = strlen(test384[i].vector);
		for (j = 0; j < 8; ++j) {
			SHA384_Init(&ctx);
			memcpy(buf + j, test384[i].vector, len);
			SHA384_Update(&ctx, buf + j, len);
			SHA384_Final(digest + j, &ctx);
			digest2string(digest + j, output, SHA384_DIGEST_LENGTH);
			ATF_CHECK_STREQ(test384[i].hash, output);
		}
	}
}
Пример #30
0
char * sha384_hex_hash(const char * passwd) {

	SHA384_CTX ct;
	unsigned char hash[SHA384_DIGEST_LENGTH];
	static char real_hash[LUTIL_BASE64_ENCODE_LEN(SHA384_DIGEST_LENGTH)+1]; // extra char for \0

	SHA384_Init(&ct);
	SHA384_Update(&ct, (const uint8_t*)passwd, strlen(passwd));
	SHA384_Final(hash, &ct);

        /* base64 encode it */
	lutil_b64_ntop(
			hash,
			SHA384_DIGEST_LENGTH,
			real_hash,
			LUTIL_BASE64_ENCODE_LEN(SHA384_DIGEST_LENGTH)+1
			);

	return real_hash;
}