Beispiel #1
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;
}
Beispiel #2
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);
}
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);
}
Beispiel #4
0
/**
 * Add data for digest calculation. After calling <code>getDigest()</code> SHA context
 * is uninitialized and this method should not be called.
 *
 * @param data data to add for digest calculation.
 * @param length length of the data.
 * @throws IOException throws exception if update failed.
 * @see getDigest()
 */
void digidoc::Digest::update(const unsigned char *data, unsigned long length) throw(IOException)
{
    if(data == NULL)
        THROW_IOEXCEPTION("Can not update digest value from NULL pointer.");

    if(!d->digest.empty())
        THROW_IOEXCEPTION("Digest is already finalized, can not update it.");

    int result = 1;
    switch(d->method)
    {
    case NID_sha1:
        result = SHA1_Update(&d->sha1, static_cast<const void*>(data), length);
        break;
    case NID_sha224:
        result = SHA224_Update(&d->sha256, static_cast<const void*>(data), length);
        break;
    case NID_sha256:
        result = SHA256_Update(&d->sha256, static_cast<const void*>(data), length);
        break;
    case NID_sha384:
        result = SHA384_Update(&d->sha512, static_cast<const void*>(data), length);
        break;
    case NID_sha512:
        result = SHA512_Update(&d->sha512, static_cast<const void*>(data), length);
        break;
    default:
        break;
    }
    if(result != 1)
        THROW_IOEXCEPTION("Failed to update %s digest value: %s", getName().c_str(), ERR_reason_error_string(ERR_get_error()));
}
Beispiel #5
0
static void
int_sha384_update(PX_MD *h, const uint8 *data, unsigned dlen)
{
	SHA384_CTX *ctx = (SHA384_CTX *) h->p.ptr;

	SHA384_Update(ctx, data, dlen);
}
Beispiel #6
0
static mrb_value
sha384_file(mrb_state *mrb, mrb_value self)
{

#ifdef ENABLE_FILE_DIGEST
  SHA384_CTX *ctx = (SHA384_CTX*)DATA_PTR(self);
  char *filename;
  char block[SHA384_BLOCK_LENGTH];
  size_t len;
  FILE *fp;

  mrb_get_args(mrb, "z", &filename);
  if((fp = fopen(filename, "rb")) == NULL) {
    mrb_raisef(mrb, E_RUNTIME_ERROR, "cannot open: %S", mrb_str_new_cstr(mrb, filename));
  }

  while((len = fread(block, 1, SHA384_BLOCK_LENGTH, fp)) > 0) {
    SHA384_Update(ctx, (const u_int8_t *)block, len);
  }
  
  fclose(fp);
#else
  mrb_raise(mrb, E_NOTIMP_ERROR, "Digest::SHA384#file not implemented");
#endif

  return self;
}
Beispiel #7
0
/*! \brief Compute SHA384 checksum */
void compute_sha384(char *dst, u_int8_t *src, int src_len)
{
	SHA384_CTX ctx384;
	SHA384_Init(&ctx384);
	SHA384_Update(&ctx384, src, src_len);
	SHA384_End(&ctx384, dst);
}
static int
__archive_libc_sha384update(archive_sha384_ctx *ctx, const void *indata,
    size_t insize)
{
  SHA384_Update(ctx, indata, insize);
  return (ARCHIVE_OK);
}
Beispiel #9
0
static void
hmac_sha384_update(hmac_sha384_ctx *ctx, const char *msg,
    unsigned int msg_len)
{
    SHA384_Update(&ctx->ctx_inside, (unsigned char *)msg, msg_len);
    return;
}
Beispiel #10
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;
}
Beispiel #11
0
static void 
sha384_add(__ops_hash_t *hash, const uint8_t *data, unsigned length)
{
	if (__ops_get_debug_level(__FILE__)) {
		hexdump(stderr, "sha384_add", data, length);
	}
	SHA384_Update(hash->data, data, length);
}
Beispiel #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);
}
Beispiel #13
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;
}
Beispiel #14
0
/*! \brief Compute SHA384 checksum */
void compute_sha384(char *dst, u_int8_t *src, int src_len)
{
	SHA384_CTX ctx384;
	char buf[96];
	SHA384_Init(&ctx384);
	SHA384_Update(&ctx384, src, src_len);
	SHA384_End(&ctx384, buf);
	strncpy(dst, buf, 96);
}
Beispiel #15
0
	void update(const char *buf, size_t bufSize)
	{
		switch (name_) {
		case N_SHA1:   SHA1_Update(&ctx_.sha1, buf, bufSize);     break;
		case N_SHA224: SHA224_Update(&ctx_.sha256, buf, bufSize); break;
		case N_SHA256: SHA256_Update(&ctx_.sha256, buf, bufSize); break;
		case N_SHA384: SHA384_Update(&ctx_.sha512, buf, bufSize); break;
		case N_SHA512: SHA512_Update(&ctx_.sha512, buf, bufSize); break;
		}
	}
Beispiel #16
0
static int chk_ssha384(
	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 <= (int)(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_Update(&SHAcontext,
		(const unsigned char *) &orig_pass[sizeof(SHAdigest)],
		rc - sizeof(SHAdigest));
	SHA384_Final(SHAdigest, &SHAcontext);

	/* compare */
	rc = memcmp((char *)orig_pass, (char *)SHAdigest, sizeof(SHAdigest));
	ber_memfree(orig_pass);
	return rc ? LUTIL_PASSWD_ERR : LUTIL_PASSWD_OK;
}
Beispiel #17
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;
}
Beispiel #18
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);
    }
Beispiel #19
0
static mrb_value
sha384_update(mrb_state *mrb, mrb_value self)
{
  char *str;
  int len;
  SHA384_CTX *ctx = (SHA384_CTX*)DATA_PTR(self);

  mrb_get_args(mrb, "s", &str, &len);
  SHA384_Update(ctx, (const u_int8_t *)str, len);
  
  return self;
}
Beispiel #20
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);
	}
Beispiel #21
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);
	}
}
Beispiel #22
0
static int hash_update( SRP_HashAlgorithm alg, HashCTX *c, const void *data, size_t len )
{
    switch (alg)
    {
      case SRP_SHA1  : return SHA1_Update( &c->sha, data, len );
      case SRP_SHA224: return SHA224_Update( &c->sha256, data, len );
      case SRP_SHA256: return SHA256_Update( &c->sha256, data, len );
      case SRP_SHA384: return SHA384_Update( &c->sha512, data, len );
      case SRP_SHA512: return SHA512_Update( &c->sha512, data, len );
      default:
        return -1;
    }
}
Beispiel #23
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]);
	};
}
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;
		}
Beispiel #25
0
void bdoc::SHA384Digest::update(const unsigned char* data, unsigned long length)
{
	if (data == NULL) {
		THROW_STACK_EXCEPTION("Can not update digest value from NULL pointer.");
	}

	if (!digest.empty()) {
		THROW_STACK_EXCEPTION("Digest is already finalized, can not update it.");
	}

	if (SHA384_Update(&ctx, static_cast<const void*>(data), length) != 1) {
		THROW_STACK_EXCEPTION("Failed to update SHA384 digest value: %s", ERR_reason_error_string(ERR_get_error()));
	}
}
ikptr
ikrt_openssl_sha384_update (ikptr s_ctx, ikptr s_input, ikptr s_input_len, ikpcb * pcb)
{
#ifdef HAVE_SHA384_UPDATE
  SHA384_CTX *	ctx	= IK_SHA384_CTX(s_ctx);
  const void *	in	= IK_GENERALISED_C_STRING(s_input);
  size_t	in_len	= ik_generalised_c_buffer_len(s_input, s_input_len);
  int		rv;
  rv = SHA384_Update(ctx, in, (unsigned long)in_len);
  return IK_BOOLEAN_FROM_INT(rv);
#else
  feature_failure(__func__);
#endif
}
Beispiel #27
0
/* Begin SHA384 HMAC functions
*/
static void
hmac_sha384_init(hmac_sha384_ctx *ctx, const char *key, const int key_len)
{
    unsigned char  final_key[MAX_DIGEST_BLOCK_LEN] = {0};
    int            final_len = key_len;

    if(key_len > MAX_DIGEST_BLOCK_LEN)
        final_len = MAX_DIGEST_BLOCK_LEN;

    /* When we eventually support arbitrary key sizes, take the digest
     * of the key with: sha384(final_key, init_key, final_len);
    */
    memcpy(final_key, key, final_len);

    pad_init(ctx->block_inner_pad, ctx->block_outer_pad, final_key, final_len);

    SHA384_Init(&ctx->ctx_inside);
    SHA384_Update(&ctx->ctx_inside, ctx->block_inner_pad, SHA384_BLOCK_LEN);

    SHA384_Init(&ctx->ctx_outside);
    SHA384_Update(&ctx->ctx_outside, ctx->block_outer_pad, SHA384_BLOCK_LEN);

    return;
}
Beispiel #28
0
static mrb_value
sha384_initialize(mrb_state *mrb, mrb_value self)
{
  char *str;
  int len;
  SHA384_CTX *ctx = (SHA384_CTX*)mrb_malloc(mrb, sizeof(SHA384_CTX));
  SHA384_Init(ctx);

  DATA_TYPE(self) = &sha384_type;
  DATA_PTR(self) = ctx;

  if (mrb_get_args(mrb, "|s", &str, &len) == 1) {
    SHA384_Update(ctx, (const u_int8_t *)str, len);
  }

  return self;
}
Beispiel #29
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);
}
Beispiel #30
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;
}