2 * Copyright (C) 2015 Felix Fietkau <nbd@openwrt.org>
4 * Permission to use, copy, modify, and/or 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.
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.
18 * Daniel Beer <dlbeer@gmail.com>, 22 Apr 2014
20 * This file is in the public domain.
26 #include <sys/types.h>
31 /* Feed a full block in */
32 #define SHA512_BLOCK_SIZE 128
34 /* SHA512 state. State is updated as data is fed in, and then the final
35 * hash can be read out in slices.
37 * Data is fed in as a sequence of full blocks terminated by a single
42 uint8_t partial
[SHA512_BLOCK_SIZE
];
46 /* Set up a new context */
47 void sha512_init(struct sha512_state
*s
);
49 void sha512_add(struct sha512_state
*s
, const void *data
, size_t len
);
51 /* Fetch a slice of the hash result. */
52 #define SHA512_HASH_SIZE 64
54 void sha512_final(struct sha512_state
*s
, uint8_t *hash
);
57 sha512_final_get(struct sha512_state
*s
)
59 sha512_final(s
, s
->partial
);