Debian Codegraph @

crt/aws-checksums/include/aws/checksums/xxhash.h

raw symbols SCIP
1 #ifndef AWS_CHECKSUMS_XXHASH_H
2 #define AWS_CHECKSUMS_XXHASH_H
3 /**
4 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
5 * SPDX-License-Identifier: Apache-2.0.
6 */
7
8 #include <aws/checksums/exports.h>
9 #include <aws/common/byte_buf.h>
10
11 AWS_PUSH_SANE_WARNING_LEVEL
12
13 struct aws_xxhash_impl;
14
15 enum aws_xxhash_type { XXHASH64 = 0, XXHASH3_64 = 1, XXHASH3_128 = 2 };
16
17 struct aws_xxhash {
18 struct aws_allocator *allocator;
19 enum aws_xxhash_type type;
20 struct aws_xxhash_impl *impl;
21 };
22
23 AWS_EXTERN_C_BEGIN
24
25 /**
26 * Streaming.
27 * General flow is create a new hash, update it as data arrives and then finalize when you need the checksum.
28 * Note: finalizing does not make hash unusable, it just returns checksum of the data so far,
29 * and more data can be pushed through the hash after.
30 **/
31
32 /**
33 * Allocates and initializes a XXHASH64 hash instance.
34 */
35 AWS_CHECKSUMS_API struct aws_xxhash *aws_xxhash64_new(struct aws_allocator *allocator, uint64_t seed);
36
37 /**
38 * Allocates and initializes a XXHASH3 64bit hash instance.
39 */
40 AWS_CHECKSUMS_API struct aws_xxhash *aws_xxhash3_64_new(struct aws_allocator *allocator, uint64_t seed);
41
42 /**
43 * Allocates and initializes a XXHASH3 128bit hash instance.
44 */
45 AWS_CHECKSUMS_API struct aws_xxhash *aws_xxhash3_128_new(struct aws_allocator *allocator, uint64_t seed);
46
47 /**
48 * Update hash state from the data.
49 * Can return error. Hash is unusable after error;
50 */
51 AWS_CHECKSUMS_API int aws_xxhash_update(struct aws_xxhash *hash, struct aws_byte_cursor data);
52
53 /**
54 * Write out bytes of the hash to out.
55 * Out buffer should be allocated by caller and should have enough capacity.
56 * Hash is written out in big-endian, i.e. network order.
57 */
58 AWS_CHECKSUMS_API int aws_xxhash_finalize(struct aws_xxhash *hash, struct aws_byte_buf *out);
59
60 /**
61 * Destroy allocated hash.
62 */
63 AWS_CHECKSUMS_API void aws_xxhash_destroy(struct aws_xxhash *hash);
64
65 /**
66 * One-shot.
67 */
68
69 /**
70 * Compute XXH64 hash.
71 */
72 AWS_CHECKSUMS_API int aws_xxhash64_compute(uint64_t seed, struct aws_byte_cursor data, struct aws_byte_buf *out);
73
74 /**
75 * Compute XXH3_64 hash.
76 */
77 AWS_CHECKSUMS_API int aws_xxhash3_64_compute(uint64_t seed, struct aws_byte_cursor data, struct aws_byte_buf *out);
78
79 /**
80 * Compute XXH3_128 hash.
81 */
82 AWS_CHECKSUMS_API int aws_xxhash3_128_compute(uint64_t seed, struct aws_byte_cursor data, struct aws_byte_buf *out);
83
84 AWS_EXTERN_C_END
85 AWS_POP_SANE_WARNING_LEVEL
86
87 #endif /* AWS_CHECKSUMS_XXHASH_H */