netdev-dpdk: fix mbuf leaks
[cascardo/ovs.git] / lib / sha1.h
1 /*
2  * This file is from the Apache Portable Runtime Library.
3  * The full upstream copyright and license statement is included below.
4  * Modifications copyright (c) 2009 Nicira, Inc.
5  */
6
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
13  *
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.
21  */
22 /* NIST Secure Hash Algorithm
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
27  */
28
29 #ifndef SHA1_H
30 #define SHA1_H
31
32 #include <stdbool.h>
33 #include <stddef.h>
34 #include <stdint.h>
35
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. */
38
39 /* SHA1 context structure. */
40 struct 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 };
46
47 void sha1_init(struct sha1_ctx *);
48 void sha1_update(struct sha1_ctx *, const void *, size_t);
49 void sha1_final(struct sha1_ctx *, uint8_t digest[SHA1_DIGEST_SIZE]);
50 void sha1_bytes(const void *, size_t, uint8_t digest[SHA1_DIGEST_SIZE]);
51
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
62 void sha1_to_hex(const uint8_t digest[SHA1_DIGEST_SIZE],
63                  char hex[SHA1_HEX_DIGEST_LEN + 1]);
64 bool sha1_from_hex(uint8_t digest[SHA1_DIGEST_SIZE], const char *hex);
65
66 #endif  /* sha1.h */