Exemple #1
0
char *
Digest_File(CCDigestAlg algorithm, const char *filename, char *buf)
{
	int fd;
	__block CCDigestCtx ctx;
	dispatch_queue_t queue;
	dispatch_semaphore_t sema;
	dispatch_io_t io;
	__block int s_error = 0;

	/* dispatch_io_create_with_path requires an absolute path */
	fd = open(filename, O_RDONLY);
	if (fd < 0) {
		return NULL;
	}

	(void)fcntl(fd, F_NOCACHE, 1);

	(void)osx_assumes_zero(CCDigestInit(algorithm, &ctx));

	queue = dispatch_queue_create("com.apple.mtree.io", NULL);
	osx_assert(queue);
	sema = dispatch_semaphore_create(0);
	osx_assert(sema);

	io = dispatch_io_create(DISPATCH_IO_STREAM, fd, queue, ^(int error) {
		if (error != 0) {
			s_error = error; 
		}
		(void)close(fd);
		(void)dispatch_semaphore_signal(sema);
	});
Exemple #2
0
char *
Digest_Data(CCDigestAlg algorithm, const void *data, size_t len, char *buf)
{
	CCDigestCtx ctx;

	(void)osx_assumes_zero(CCDigestInit(algorithm, &ctx));
	(void)osx_assumes_zero(CCDigestUpdate(&ctx, data, len));
	return Digest_End(&ctx, buf);
}
Exemple #3
0
int
CCDigest(CCDigestAlg algorithm, const uint8_t *data, size_t length, uint8_t *output)
{
	CCDigestCtx_t c;
	CCDigestCtxPtr ptr = &c;
	CCDigestInit(algorithm, ptr);
    uint8_t* checkedData = data;
    if (checkedData == NULL) {
        checkedData = "";
    }
	hash_descriptor[ptr->hashIndex].process(&ptr->md, checkedData, length);
	return hash_descriptor[ptr->hashIndex].done(&ptr->md, output);
}
Exemple #4
0
CCDigestRef
CCDigestCreate(CCDigestAlg algorithm)
{
    CCDigestRef ctx;
    
    if(!(ctx = (CCDigestCtx *) malloc(CC_DIGEST_SIZE))) {
        return NULL;
    }
    if(CCDigestInit(algorithm, ctx) != 0) { 
        free(ctx); 
        return NULL; 
    }
    return ctx;
}