Blob


1 /*
2 * Copyright (c) 2018 Stefan Sperling <stsp@openbsd.org>
3 *
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
17 #define GOT_SHA1_STRING_ZERO "0000000000000000000000000000000000000000"
18 #define GOT_SHA256_STRING_ZERO "0000000000000000000000000000000000000000000000000000000000000000"
20 int got_parse_xdigit(uint8_t *, const char *);
22 int got_parse_sha1_digest(uint8_t *, const char *);
23 char *got_sha1_digest_to_str(const uint8_t *, char *, size_t);
25 int got_parse_sha256_digest(uint8_t *, const char *);
26 char *got_sha256_digest_to_str(const uint8_t *, char *, size_t);
28 int got_parse_hash_digest(uint8_t *, const char *, enum got_hash_algorithm);
29 char *got_hash_digest_to_str(const uint8_t *, char *, size_t,
30 enum got_hash_algorithm);
32 size_t got_hash_digest_length(enum got_hash_algorithm);
33 size_t got_hash_digest_string_length(enum got_hash_algorithm);
35 struct got_hash {
36 SHA1_CTX sha1_ctx;
37 SHA2_CTX sha256_ctx;
38 enum got_hash_algorithm algo;
39 };
41 /*
42 * These functions allow to compute and check hashes.
43 * The hash function used is specified during got_hash_init.
44 * Data can be added with got_hash_update and, once done, the checksum
45 * can be obtained with got_hash_final; its output buffer must be at
46 * least GOT_OBJECT_ID_MAXLEN bytes.
47 * got_hash_cmp is like memcmp() and compares two hash digests.
48 */
49 void got_hash_init(struct got_hash *, enum got_hash_algorithm);
50 void got_hash_update(struct got_hash *, const void *, size_t);
51 void got_hash_final(struct got_hash *, uint8_t *);
52 int got_hash_cmp(struct got_hash *, uint8_t *, uint8_t *);