panthema / 2009 / digup / digup-0.6.40 / src / digest.h (Download File)
 * Class-like structures to easily switch between message digests.           *
 *                                                                           *
 * Copyright (C) 2009 Timo Bingmann                                          *
 *                                                                           *
 * This program is free software; you can redistribute it and/or modify it   *
 * under the terms of the GNU General Public License as published by the     *
 * Free Software Foundation; either version 3, or (at your option) any       *
 * later version.                                                            *
 *                                                                           *
 * This program is distributed in the hope that it will be useful,           *
 * but WITHOUT ANY WARRANTY; without even the implied warranty of            *
 * GNU General Public License for more details.                              *
 *                                                                           *
 * You should have received a copy of the GNU General Public License         *
 * along with this program; if not, write to the Free Software Foundation,   *
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.        *

/* $Id: digest.h 14 2009-10-22 13:52:55Z tb $ */

#ifndef _DIGEST_H
#define _DIGEST_H 1

#include "md5.h"
#include "sha1.h"
#include "sha256.h"
#include "sha512.h"
#include "crc32.h"

 * variable sized structure to hold binary digest results of different
 * algorithms.
typedef struct digest_result
    unsigned char	size;
    /* variable length of bytes follows:
    unsigned char	data[];
} digest_result;

 * class-like structure with function pointers and integrated digest
 * algorithm context.
typedef struct digest_ctx
	struct md5_ctx		md5;
	struct sha1_ctx		sha1;
	struct sha256_ctx	sha256;
	struct sha512_ctx	sha512;
	uint32_t		crc32;
    } ctx;

    size_t (*digest_size)(void);

    void (*init)(struct digest_ctx *ctx);

    void (*process)(struct digest_ctx *ctx,
		    const void *buffer, size_t len);

    struct digest_result* (*finish)(struct digest_ctx *ctx);

    struct digest_result* (*read)(struct digest_ctx *ctx);

    struct digest_result* (*process_buffer)(const char *buffer, size_t len);
} digest_ctx;

/* initialize the structure with function pointers for specific digest
 * type */
extern void digest_init_md5(struct digest_ctx* ctx);

extern void digest_init_sha1(struct digest_ctx* ctx);

extern void digest_init_sha256(struct digest_ctx* ctx);

extern void digest_init_sha512(struct digest_ctx* ctx);

extern void digest_init_crc32(struct digest_ctx* ctx);

/* miscellaneous utilities */

extern struct digest_result* digest_dup(const struct digest_result* res);

extern char* digest_bin2hex(const struct digest_result*, char* out);

extern char* digest_bin2hex_dup(const struct digest_result* res);

extern struct digest_result* digest_hex2bin(const char* str, int len);

extern int digest_equal(const struct digest_result* a, const struct digest_result* b);

extern int digest_cmp(const struct digest_result* a, const struct digest_result* b);

#endif /* _DIGEST_H */

RSS 2.0 Weblog Feed Atom 1.0 Weblog Feed Valid XHTML 1.1 Valid CSS (2.1)
Copyright 2005-2017 Timo Bingmann - Impressum