]> git.proxmox.com Git - mirror_ovs.git/blame - lib/sha1.h
cirrus: Use FreeBSD 12.2.
[mirror_ovs.git] / lib / sha1.h
CommitLineData
064af421 1/*
5eccf359
BP
2 * This file is from the Apache Portable Runtime Library.
3 * The full upstream copyright and license statement is included below.
e0edde6f 4 * Modifications copyright (c) 2009 Nicira, Inc.
064af421 5 */
064af421 6
5eccf359
BP
7/* Licensed to the Apache Software Foundation (ASF) under one or more
8 * contributor license agreements. See the NOTICE file distributed with
9 * this work for additional information regarding copyright ownership.
10 * The ASF licenses this file to You under the Apache License, Version 2.0
11 * (the "License"); you may not use this file except in compliance with
12 * the License. You may obtain a copy of the License at
064af421 13 *
5eccf359
BP
14 * http://www.apache.org/licenses/LICENSE-2.0
15 *
16 * Unless required by applicable law or agreed to in writing, software
17 * distributed under the License is distributed on an "AS IS" BASIS,
18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 * See the License for the specific language governing permissions and
20 * limitations under the License.
064af421 21 */
5eccf359 22/* NIST Secure Hash Algorithm
05fe1764
BP
23 * heavily modified by Uwe Hollerbach uh@alumni.caltech edu
24 * from Peter C. Gutmann's implementation as found in
25 * Applied Cryptography by Bruce Schneier
26 * This code is hereby placed in the public domain
064af421 27 */
064af421 28
5eccf359
BP
29#ifndef SHA1_H
30#define SHA1_H
064af421 31
e7f1bf58 32#include <stdbool.h>
5eccf359
BP
33#include <stddef.h>
34#include <stdint.h>
064af421 35
e7f1bf58
BP
36#define SHA1_DIGEST_SIZE 20 /* Size of the SHA1 digest. */
37#define SHA1_HEX_DIGEST_LEN 40 /* Length of SHA1 digest as hex in ASCII. */
064af421 38
5eccf359
BP
39/* SHA1 context structure. */
40struct sha1_ctx {
41 uint32_t digest[5]; /* Message digest. */
42 uint32_t count_lo, count_hi; /* 64-bit bit counts. */
43 uint32_t data[16]; /* SHA data buffer */
44 int local; /* Unprocessed amount in data. */
45};
064af421 46
5eccf359 47void sha1_init(struct sha1_ctx *);
a1d2c5f5 48void sha1_update(struct sha1_ctx *, const void *, uint32_t size);
5eccf359 49void sha1_final(struct sha1_ctx *, uint8_t digest[SHA1_DIGEST_SIZE]);
a1d2c5f5 50void sha1_bytes(const void *, uint32_t size, uint8_t digest[SHA1_DIGEST_SIZE]);
064af421 51
e7f1bf58
BP
52#define SHA1_FMT \
53 "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x" \
54 "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x"
55#define SHA1_ARGS(DIGEST) \
56 ((DIGEST)[0]), ((DIGEST)[1]), ((DIGEST)[2]), ((DIGEST)[3]), \
57 ((DIGEST)[4]), ((DIGEST)[5]), ((DIGEST)[6]), ((DIGEST)[7]), \
58 ((DIGEST)[8]), ((DIGEST)[9]), ((DIGEST)[10]), ((DIGEST)[11]), \
59 ((DIGEST)[12]), ((DIGEST)[13]), ((DIGEST)[14]), ((DIGEST)[15]), \
60 ((DIGEST)[16]), ((DIGEST)[17]), ((DIGEST)[18]), ((DIGEST)[19])
61
62void sha1_to_hex(const uint8_t digest[SHA1_DIGEST_SIZE],
63 char hex[SHA1_HEX_DIGEST_LEN + 1]);
64bool sha1_from_hex(uint8_t digest[SHA1_DIGEST_SIZE], const char *hex);
65
5eccf359 66#endif /* sha1.h */