示例#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
static void
int_sha224_reset(PX_MD *h)
{
	SHA224_CTX *ctx = (SHA224_CTX *) h->p.ptr;

	SHA224_Init(ctx);
}
示例#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
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;
}
示例#5
0
static int partial_hash_sha224(uint8_t *data_in, uint8_t *data_out)
{
	SHA256_CTX ctx;

	if (!SHA224_Init(&ctx))
		return -EFAULT;
	SHA256_Transform(&ctx, data_in);
	rte_memcpy(data_out, &ctx, SHA256_DIGEST_LENGTH);
	return 0;
}
示例#6
0
static void sha224_init(ops_hash_t *hash)
    {
    if (debug)
        {
        fprintf(stderr,"***\n***\nsha1_init\n***\n");
        }
    assert(!hash->data);
    hash->data=malloc(sizeof(SHA256_CTX));
    SHA224_Init(hash->data);
    }
示例#7
0
unsigned char *SHA224(const unsigned char *d, size_t n, unsigned char *md)
	{
	SHA256_CTX c;
	static unsigned char m[SHA224_DIGEST_LENGTH];

	if (md == NULL) md=m;
	SHA224_Init(&c);
	SHA256_Update(&c,d,n);
	SHA256_Final(md,&c);
	return(md);
	}
示例#8
0
	void reset()
	{
		switch (name_) {
		case N_SHA1:   SHA1_Init(&ctx_.sha1);     break;
		case N_SHA224: SHA224_Init(&ctx_.sha256); break;
		case N_SHA256: SHA256_Init(&ctx_.sha256); break;
		case N_SHA384: SHA384_Init(&ctx_.sha512); break;
		case N_SHA512: SHA512_Init(&ctx_.sha512); break;
		default:
			throw cybozu::Exception("crypto:Hash:rset") << name_;
		}
	}
示例#9
0
static int hash_init( SRP_HashAlgorithm alg, HashCTX *c )
{
    switch (alg)
    {
      case SRP_SHA1  : return SHA1_Init( &c->sha );
      case SRP_SHA224: return SHA224_Init( &c->sha256 );
      case SRP_SHA256: return SHA256_Init( &c->sha256 );
      case SRP_SHA384: return SHA384_Init( &c->sha512 );
      case SRP_SHA512: return SHA512_Init( &c->sha512 );
      default:
        return -1;
    }
}
示例#10
0
static int 
sha224_init(__ops_hash_t *hash)
{
	if (hash->data) {
		(void) fprintf(stderr, "sha224_init: hash data non-null\n");
	}
	if ((hash->data = calloc(1, sizeof(SHA256_CTX))) == NULL) {
		(void) fprintf(stderr, "sha256_init: bad alloc\n");
		return 0;
	}
	SHA224_Init(hash->data);
	return 1;
}
示例#11
0
文件: sha256.c 项目: RobinWuDev/Qt
uint8_t *SHA224(const uint8_t *data, size_t len, uint8_t *out) {
  SHA256_CTX ctx;
  static uint8_t buf[SHA224_DIGEST_LENGTH];

  /* TODO(fork): remove this static buffer. */
  if (out == NULL) {
    out = buf;
  }
  SHA224_Init(&ctx);
  SHA256_Update(&ctx, data, len);
  SHA256_Final(out, &ctx);
  OPENSSL_cleanse(&ctx, sizeof(ctx));
  return out;
}
示例#12
0
void digidoc::Digest::reset()
{
    int result = 1;
    switch(d->method)
    {
    case NID_sha1: result = SHA1_Init(&d->sha1); break;
    case NID_sha224: result = SHA224_Init(&d->sha256); break;
    case NID_sha256: result = SHA256_Init(&d->sha256); break;
    case NID_sha384: result = SHA384_Init(&d->sha512); break;
    case NID_sha512: result = SHA512_Init(&d->sha512); break;
    default: break;
    }
    d->digest.clear();
    if(result != 1)
        THROW_IOEXCEPTION("Failed to initialize %s digest calculator: %s", getName().c_str(), ERR_reason_error_string(ERR_get_error()));
}
示例#13
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;
}
示例#14
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;
}
示例#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;
}
ikptr
ikrt_openssl_sha224_init (ikpcb * pcb)
{
#ifdef HAVE_SHA224_INIT
  SHA224_CTX *	ctx;
  int		rv;
  ctx = malloc(sizeof(SHA224_CTX));
  if (ctx) {
    rv  = SHA224_Init(ctx);
    if (rv)
      return ika_pointer_alloc(pcb, (long)ctx);
    else
      free(ctx);
  }
  return IK_FALSE;
#else
  feature_failure(__func__);
#endif
}
示例#17
0
static void _wi_sha2_ctx_init(wi_sha2_bits_t bits, _wi_sha2_ctx_t *ctx) {
    ctx->bits = bits;

#ifdef WI_SHA2_OPENSSL
    switch(ctx->bits) {
    case WI_SHA2_224:
        SHA224_Init(&ctx->openssl_256_ctx);
        break;

    case WI_SHA2_256:
        SHA256_Init(&ctx->openssl_256_ctx);
        break;

    case WI_SHA2_384:
        SHA384_Init(&ctx->openssl_512_ctx);
        break;

    case WI_SHA2_512:
        SHA512_Init(&ctx->openssl_512_ctx);
        break;
    }
#endif

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

    case WI_SHA2_256:
        CC_SHA256_Init(&ctx->commondigest_256_ctx);
        break;

    case WI_SHA2_384:
        CC_SHA384_Init(&ctx->commondigest_512_ctx);
        break;

    case WI_SHA2_512:
        CC_SHA512_Init(&ctx->commondigest_512_ctx);
        break;
    }
#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);
}
示例#19
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;

}
示例#20
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;
}
示例#21
0
void NzHashSHA224::Begin()
{
	SHA224_Init(m_state);
}
示例#22
0
bdoc::SHA224Digest::SHA224Digest()
{
	if (SHA224_Init(&ctx) != 1) {
		THROW_STACK_EXCEPTION("Failed to initialize SHA224 digest calculator: %s", ERR_reason_error_string(ERR_get_error()));
	}
}
示例#23
0
static void sha224_init(EVP_MD_CTX *ctx) {
  CHECK(SHA224_Init(ctx->md_data));
}