Blame


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