예제 #1
0
static void crypt_all(int count)
{
	SHA256_CTX ctx;

	SHA224_Init( &ctx );
	SHA224_Update( &ctx, ipad, BLOCK_SIZE );
	SHA224_Update( &ctx, cursalt, strlen( (char*) cursalt) );
	SHA224_Final( (unsigned char*) crypt_key, &ctx);

	SHA224_Init( &ctx );
	SHA224_Update( &ctx, opad, BLOCK_SIZE );
	SHA224_Update( &ctx, crypt_key, BINARY_SIZE);
	SHA224_Final( (unsigned char*) crypt_key, &ctx);
}
예제 #2
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;
}
예제 #3
0
파일: sha224.c 프로젝트: sanikoyes/cipher
void SHA224_Simple(const void *p, int len, unsigned char *output) {
    SHA256_State s;

    SHA224_Init(&s);
    SHA224_Bytes(&s, p, len);
    SHA224_Final(&s, output);
}
예제 #4
0
static void
int_sha224_finish(PX_MD *h, uint8 *dst)
{
	SHA224_CTX *ctx = (SHA224_CTX *) h->p.ptr;

	SHA224_Final(dst, ctx);
}
예제 #5
0
uint8_t *SHA224(const uint8_t *data, size_t len, uint8_t *out) {
  SHA256_CTX ctx;
  SHA224_Init(&ctx);
  SHA224_Update(&ctx, data, len);
  SHA224_Final(out, &ctx);
  OPENSSL_cleanse(&ctx, sizeof(ctx));
  return out;
}
예제 #6
0
static unsigned 
sha224_finish(__ops_hash_t *hash, uint8_t *out)
{
	SHA224_Final(out, hash->data);
	if (__ops_get_debug_level(__FILE__)) {
		hexdump(stderr, "sha224_finish", out, SHA224_DIGEST_LENGTH);
	}
	free(hash->data);
	hash->data = NULL;
	return SHA224_DIGEST_LENGTH;
}
예제 #7
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;
    }
}
예제 #8
0
static unsigned sha224_finish(ops_hash_t *hash,unsigned char *out)
    {
    SHA224_Final(out,hash->data);
    if (debug)
        {
        unsigned i=0;
        fprintf(stderr,"***\n***\nsha1_finish\n***\n");
        for (i=0; i<SHA224_DIGEST_LENGTH; i++)
            fprintf(stderr,"0x%02x ",out[i]);
        fprintf(stderr,"\n");
        }
    free(hash->data);
    hash->data=NULL;
    return SHA224_DIGEST_LENGTH;
    }
예제 #9
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();
	}
예제 #10
0
파일: util.c 프로젝트: sandsmark/pacman
/** Compute the SHA-224 or SHA-256 message digest of a file.
 * @param path file path of file to compute SHA2 digest of
 * @param output string to hold computed SHA2 digest
 * @param is224 use SHA-224 instead of SHA-256
 * @return 0 on success, 1 on file open error, 2 on file read error
 */
static int sha2_file(const char *path, unsigned char output[32], int is224)
{
	SHA256_CTX ctx;
	unsigned char *buf;
	ssize_t n;
	int fd;

	MALLOC(buf, (size_t)ALPM_BUFFER_SIZE, return 1);

	OPEN(fd, path, O_RDONLY);
	if(fd < 0) {
		free(buf);
		return 1;
	}

	if(is224) {
		SHA224_Init(&ctx);
	} else {
		SHA256_Init(&ctx);
	}

	while((n = read(fd, buf, ALPM_BUFFER_SIZE)) > 0 || errno == EINTR) {
		if(n < 0) {
			continue;
		}
		if(is224) {
			SHA224_Update(&ctx, buf, n);
		} else {
			SHA256_Update(&ctx, buf, n);
		}
	}

	CLOSE(fd);
	free(buf);

	if(n < 0) {
		return 2;
	}

	if(is224) {
		SHA224_Final(output, &ctx);
	} else {
		SHA256_Final(output, &ctx);
	}
	return 0;
}
예제 #11
0
std::vector<unsigned char> bdoc::SHA224Digest::getDigest()
{
	if (!digest.empty()) {
		return digest;
	}

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

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

	return digest;
}
예제 #12
0
파일: SHA+NNT.cpp 프로젝트: imace/nnt
core::data sha2::digest224(core::data const& da)
{
    core::data tmp = da.shadow();
    
    SHA256_CTX ctx;
    SHA224_Init(&ctx);
    
    while (tmp.length())
    {
        SHA224_Update(&ctx, tmp.bytes(), tmp.limit(SHA224_DIGEST_LENGTH));
        tmp.offset(tmp.limit(SHA224_DIGEST_LENGTH));
    }
    
    core::data ret(SHA224_DIGEST_LENGTH);
    SHA224_Final((byte*)ret.bytes(), &ctx);
    
    return ret;
}
ikptr
ikrt_openssl_sha224_final (ikptr s_ctx, ikpcb * pcb)
{
#ifdef HAVE_SHA224_FINAL
  ikptr		s_pointer	= IK_SHA224_CTX_POINTER(s_ctx);
  SHA224_CTX *	ctx		= IK_POINTER_DATA_VOIDP(s_pointer);
  unsigned char	sum[SHA224_DIGEST_LENGTH];
  int		rv = 0;
  if (ctx) {
    rv = SHA224_Final(sum, ctx);
    free(ctx);
    IK_POINTER_SET_NULL(s_pointer);
  }
  return (rv)? ika_bytevector_from_memory_block(pcb, sum, SHA224_DIGEST_LENGTH) : IK_FALSE;
#else
  feature_failure(__func__);
#endif
}
static void SHA224_File(FILE *file, unsigned char **output, int *outlength)
{
	*output = new unsigned char[SHA224_DIGEST_LENGTH];
	*outlength = SHA224_DIGEST_LENGTH;

	SHA256_CTX c;
	int i;
	unsigned char buf[SHA224_FILE_BUFFER_SIZE];
	
	SHA224_Init(&c);
	for (;;)
	{
		i = fread(buf,1,SHA224_FILE_BUFFER_SIZE,file);
		if(i <= 0)
			break;
		SHA224_Update(&c,buf,(unsigned long)i);
	}
	SHA224_Final(*output, &c);
}
예제 #15
0
int main(int argc, char** argv) {

  size_t dataSize = 10;
  unsigned char data[dataSize];
  memset(data, 0, dataSize);

  // Store key.
  size_t mdSize = SHA256_DIGEST_LENGTH;
  unsigned char md[mdSize];

  SHA256_CTX c;
  SHA224_Init(&c);
  SHA224_Update(&c, data, dataSize);
  SHA224_Final(md, &c);

  printBlock(md, mdSize);
  printf("\n");
  return 0;
}
예제 #16
0
static void _wi_sha2_ctx_final(unsigned char *buffer, _wi_sha2_ctx_t *ctx) {
#ifdef WI_SHA2_OPENSSL
    switch(ctx->bits) {
    case WI_SHA2_224:
        SHA224_Final(buffer, &ctx->openssl_256_ctx);
        break;

    case WI_SHA2_256:
        SHA256_Final(buffer, &ctx->openssl_256_ctx);
        break;

    case WI_SHA2_384:
        SHA384_Final(buffer, &ctx->openssl_512_ctx);
        break;

    case WI_SHA2_512:
        SHA512_Final(buffer, &ctx->openssl_512_ctx);
        break;
    }
#endif

#ifdef WI_SHA2_COMMONCRYPTO
    switch(ctx->bits) {
    case WI_SHA2_224:
        CC_SHA224_Final(buffer, &ctx->commondigest_256_ctx);
        break;

    case WI_SHA2_256:
        CC_SHA256_Final(buffer, &ctx->commondigest_256_ctx);
        break;

    case WI_SHA2_384:
        CC_SHA384_Final(buffer, &ctx->commondigest_512_ctx);
        break;

    case WI_SHA2_512:
        CC_SHA512_Final(buffer, &ctx->commondigest_512_ctx);
        break;
    }
#endif
}
예제 #17
0
int main(void)
{
    
    SHA256_CTX      context;
    unsigned char   hash[SHA224_DIGEST_LENGTH];
    BIO*            bio_out;

    char*       data_to_hash = "The worthwhile problems are the ones you can"
                               "really solve or help solve, the ones you can"
                               "really contribute something to. ... No "
                               "problem is too small or too trivial if we "
                               "can really do something about it."
                               "- Richard Feynman";

    int         length = (int)strlen(data_to_hash);
    int         i      = 0;


    SHA224_Init(&context);

    while (i < length)
    {
        if ((length - i) < DATA_LENGTH)
            SHA224_Update(&context, (void*)(data_to_hash + i), length - i);
        else
            SHA224_Update(&context, (void*)(data_to_hash + i), DATA_LENGTH);

        i += DATA_LENGTH;
    }

    SHA224_Final(hash, &context);

    bio_out = BIO_new_fp(stdout, BIO_NOCLOSE);
    
    for (i = 0; i < SHA224_DIGEST_LENGTH; i++)
        BIO_printf(bio_out, "%02x", (unsigned char*)hash[i]);


    return 0;

}
예제 #18
0
inline bool hashfile(const char* filename, char* buffer){
    FILE *inFile = fopen(filename, "rb");
    SHA256_CTX context;
    int bytes;
    unsigned char data[FILE_BUFFER];
    unsigned char digest[SHA224_DIGEST_LENGTH];

    if (inFile == NULL) {
        printf("%s can't be opened.\n", filename);
        return false;
    }

    SHA224_Init (&context);
    while ((bytes = fread (data, 1, FILE_BUFFER, inFile)) != 0)
        SHA224_Update (&context, data, bytes);
    SHA224_Final (digest,&context);
    
    fclose (inFile);    
    digest_to_char(buffer, digest);
    
    return true;
}
예제 #19
0
파일: digests.c 프로젝트: 360ground/Meda.et
static void sha224_final(EVP_MD_CTX *ctx, uint8_t *md) {
  CHECK(SHA224_Final(md, ctx->md_data));
}