Example #1
0
/*
*  USHAInput
*
*  Description:
*      This function accepts an array of octets as the next portion
*      of the message.
*
*  Parameters:
*      context: [in/out]
*          The SHA context to update
*      message_array: [in]
*          An array of characters representing the next portion of
*          the message.
*      length: [in]
*          The length of the message in message_array
*
*  Returns:
*      sha Error Code.
*
*/
int USHAInput(USHAContext *ctx,
    const uint8_t *bytes, unsigned int bytecount)
{
    if (ctx) {
        switch (ctx->whichSha) {
        case SHA1:
            return SHA1Input((SHA1Context*)&ctx->ctx, bytes, bytecount);
        case SHA224:
            return SHA224Input((SHA224Context*)&ctx->ctx, bytes,
                bytecount);
        case SHA256:
            return SHA256Input((SHA256Context*)&ctx->ctx, bytes,
                bytecount);
        case SHA384:
            return SHA384Input((SHA384Context*)&ctx->ctx, bytes,
                bytecount);
        case SHA512:
            return SHA512Input((SHA512Context*)&ctx->ctx, bytes,
                bytecount);
        default: return shaBadParam;
        }
    }
    else {
        return shaNull;
    }
}
void md_map_sh256(uint8_t *hash, const uint8_t *msg, int len) {
	SHA256Context ctx;

	if (SHA256Reset(&ctx) != shaSuccess) {
		THROW(ERR_NO_VALID);
	}
	if (SHA256Input(&ctx, msg, len) != shaSuccess) {
		THROW(ERR_NO_VALID);
	}
	if (SHA256Result(&ctx, hash) != shaSuccess) {
		THROW(ERR_NO_VALID);
	}
}
Example #3
0
/*!
    Adds the first \a length chars of \a data to the cryptographic
    hash.
*/
void QCryptographicHash::addData(const char *data, int length)
{
    switch (d->method) {
    case Sha1:
        sha1Update(&d->sha1Context, (const unsigned char *)data, length);
        break;
#ifdef QT_CRYPTOGRAPHICHASH_ONLY_SHA1
    default:
        Q_ASSERT_X(false, "QCryptographicHash", "Method not compiled in");
        Q_UNREACHABLE();
        break;
#else
    case Md4:
        md4_update(&d->md4Context, (const unsigned char *)data, length);
        break;
    case Md5:
        MD5Update(&d->md5Context, (const unsigned char *)data, length);
        break;
    case Sha224:
        SHA224Input(&d->sha224Context, reinterpret_cast<const unsigned char *>(data), length);
        break;
    case Sha256:
        SHA256Input(&d->sha256Context, reinterpret_cast<const unsigned char *>(data), length);
        break;
    case Sha384:
        SHA384Input(&d->sha384Context, reinterpret_cast<const unsigned char *>(data), length);
        break;
    case Sha512:
        SHA512Input(&d->sha512Context, reinterpret_cast<const unsigned char *>(data), length);
        break;
    case RealSha3_224:
    case Keccak_224:
        sha3Update(&d->sha3Context, reinterpret_cast<const BitSequence *>(data), length*8);
        break;
    case RealSha3_256:
    case Keccak_256:
        sha3Update(&d->sha3Context, reinterpret_cast<const BitSequence *>(data), length*8);
        break;
    case RealSha3_384:
    case Keccak_384:
        sha3Update(&d->sha3Context, reinterpret_cast<const BitSequence *>(data), length*8);
        break;
    case RealSha3_512:
    case Keccak_512:
        sha3Update(&d->sha3Context, reinterpret_cast<const BitSequence *>(data), length*8);
        break;
#endif
    }
    d->result.clear();
}
Example #4
0
void SHA256::Update( const void* data, size_type size )
{
   if ( data != nullptr )
      if ( size > 0 )
      {
         if ( m_context == nullptr )
         {
            m_context = new SHA256Context;
            SHA256Reset( CTX );
         }
         const uint8* bytes = reinterpret_cast<const uint8*>( data );
         do
         {
            size_type blockSize = Min( size_type( 0xfffffff0 ), size );
            SHA256Input( CTX, bytes, unsigned( blockSize ) );
            size -= blockSize;
            bytes += blockSize;
         }
         while ( size > 0 );
      }
}
static int load_registration_id(PROV_AUTH_INFO* handle)
{
    int result;
    if (handle->sec_type == PROV_AUTH_TYPE_TPM)
    {
        SHA256Context sha_ctx;
        uint8_t msg_digest[SHA256HashSize];
        unsigned char* endorsement_key;
        size_t ek_len;

        if (handle->hsm_client_get_endorsement_key(handle->hsm_client_handle, &endorsement_key, &ek_len) != 0)
        {
            LogError("Failed getting device reg id");
            result = MU_FAILURE;
        }
        else
        {
            if (SHA256Reset(&sha_ctx) != 0)
            {
                LogError("Failed sha256 reset");
                result = MU_FAILURE;
            }
            else if (SHA256Input(&sha_ctx, endorsement_key, (unsigned int)ek_len) != 0)
            {
                LogError("Failed SHA256Input");
                result = MU_FAILURE;
            }
            else if (SHA256Result(&sha_ctx, msg_digest) != 0)
            {
                LogError("Failed SHA256Result");
                result = MU_FAILURE;
            }
            else
            {
                handle->registration_id = encode_value(msg_digest, SHA256HashSize);
                if (handle->registration_id == NULL)
                {
                    LogError("Failed allocating registration Id");
                    result = MU_FAILURE;
                }
                else
                {
                    result = 0;
                }
            }
            free(endorsement_key);
        }
    }
    else
    {
        handle->registration_id = handle->hsm_client_get_common_name(handle->hsm_client_handle);
        if (handle->registration_id == NULL)
        {
            LogError("Failed getting common name from certificate");
            result = MU_FAILURE;
        }
        else
        {
            result = 0;
        }
    }
    return result;
}
Example #6
0
File: low.c Project: ucodev/libpsec
int sha256_low_update(SHA256Context *context, const unsigned char *in, size_t in_len) {
	return SHA256Input(context, (uint8_t *) in, in_len);
}