7a7d97c082834dccdd89dbb95598977deec4d5a7Timo Sirainen/*
7a7d97c082834dccdd89dbb95598977deec4d5a7Timo Sirainen * FIPS 180-2 SHA-224/256/384/512 implementation
7a7d97c082834dccdd89dbb95598977deec4d5a7Timo Sirainen * Last update: 02/02/2007
7a7d97c082834dccdd89dbb95598977deec4d5a7Timo Sirainen * Issue date: 04/30/2005
7a7d97c082834dccdd89dbb95598977deec4d5a7Timo Sirainen *
7a7d97c082834dccdd89dbb95598977deec4d5a7Timo Sirainen * Copyright (C) 2005, 2007 Olivier Gay <olivier.gay@a3.epfl.ch>
7a7d97c082834dccdd89dbb95598977deec4d5a7Timo Sirainen * All rights reserved.
7a7d97c082834dccdd89dbb95598977deec4d5a7Timo Sirainen *
7a7d97c082834dccdd89dbb95598977deec4d5a7Timo Sirainen * Redistribution and use in source and binary forms, with or without
7a7d97c082834dccdd89dbb95598977deec4d5a7Timo Sirainen * modification, are permitted provided that the following conditions
7a7d97c082834dccdd89dbb95598977deec4d5a7Timo Sirainen * are met:
7a7d97c082834dccdd89dbb95598977deec4d5a7Timo Sirainen * 1. Redistributions of source code must retain the above copyright
7a7d97c082834dccdd89dbb95598977deec4d5a7Timo Sirainen * notice, this list of conditions and the following disclaimer.
7a7d97c082834dccdd89dbb95598977deec4d5a7Timo Sirainen * 2. Redistributions in binary form must reproduce the above copyright
7a7d97c082834dccdd89dbb95598977deec4d5a7Timo Sirainen * notice, this list of conditions and the following disclaimer in the
7a7d97c082834dccdd89dbb95598977deec4d5a7Timo Sirainen * documentation and/or other materials provided with the distribution.
7a7d97c082834dccdd89dbb95598977deec4d5a7Timo Sirainen * 3. Neither the name of the project nor the names of its contributors
7a7d97c082834dccdd89dbb95598977deec4d5a7Timo Sirainen * may be used to endorse or promote products derived from this software
7a7d97c082834dccdd89dbb95598977deec4d5a7Timo Sirainen * without specific prior written permission.
7a7d97c082834dccdd89dbb95598977deec4d5a7Timo Sirainen *
7a7d97c082834dccdd89dbb95598977deec4d5a7Timo Sirainen * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
7a7d97c082834dccdd89dbb95598977deec4d5a7Timo Sirainen * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
7a7d97c082834dccdd89dbb95598977deec4d5a7Timo Sirainen * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
7a7d97c082834dccdd89dbb95598977deec4d5a7Timo Sirainen * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
7a7d97c082834dccdd89dbb95598977deec4d5a7Timo Sirainen * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
7a7d97c082834dccdd89dbb95598977deec4d5a7Timo Sirainen * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
7a7d97c082834dccdd89dbb95598977deec4d5a7Timo Sirainen * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
7a7d97c082834dccdd89dbb95598977deec4d5a7Timo Sirainen * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
7a7d97c082834dccdd89dbb95598977deec4d5a7Timo Sirainen * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
7a7d97c082834dccdd89dbb95598977deec4d5a7Timo Sirainen * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
7a7d97c082834dccdd89dbb95598977deec4d5a7Timo Sirainen * SUCH DAMAGE.
7a7d97c082834dccdd89dbb95598977deec4d5a7Timo Sirainen */
7a7d97c082834dccdd89dbb95598977deec4d5a7Timo Sirainen
7a7d97c082834dccdd89dbb95598977deec4d5a7Timo Sirainen#ifndef SHA2_H
7a7d97c082834dccdd89dbb95598977deec4d5a7Timo Sirainen#define SHA2_H
7a7d97c082834dccdd89dbb95598977deec4d5a7Timo Sirainen
74ae32512357bdd4872bf160dc697ff7b54b54c5Timo Sirainen#include "hash-method.h"
6868400686d0726ac2c08d67ed896f2c76e7b219Aki Tuomi#include "sha-common.h"
58d16e83e0953ac98f4bdc905f2f5d24b8f0002dTimo Sirainen
7a7d97c082834dccdd89dbb95598977deec4d5a7Timo Sirainenstruct sha256_ctx {
7a7d97c082834dccdd89dbb95598977deec4d5a7Timo Sirainen size_t tot_len;
7a7d97c082834dccdd89dbb95598977deec4d5a7Timo Sirainen size_t len;
7a7d97c082834dccdd89dbb95598977deec4d5a7Timo Sirainen unsigned char block[2 * SHA256_BLOCK_SIZE];
7a7d97c082834dccdd89dbb95598977deec4d5a7Timo Sirainen uint32_t h[8];
7a7d97c082834dccdd89dbb95598977deec4d5a7Timo Sirainen};
7a7d97c082834dccdd89dbb95598977deec4d5a7Timo Sirainen
58d16e83e0953ac98f4bdc905f2f5d24b8f0002dTimo Sirainenstruct sha512_ctx {
58d16e83e0953ac98f4bdc905f2f5d24b8f0002dTimo Sirainen size_t tot_len;
58d16e83e0953ac98f4bdc905f2f5d24b8f0002dTimo Sirainen size_t len;
58d16e83e0953ac98f4bdc905f2f5d24b8f0002dTimo Sirainen unsigned char block[2 * SHA512_BLOCK_SIZE];
58d16e83e0953ac98f4bdc905f2f5d24b8f0002dTimo Sirainen uint64_t h[8];
58d16e83e0953ac98f4bdc905f2f5d24b8f0002dTimo Sirainen};
58d16e83e0953ac98f4bdc905f2f5d24b8f0002dTimo Sirainen
7a7d97c082834dccdd89dbb95598977deec4d5a7Timo Sirainenvoid sha256_init(struct sha256_ctx *ctx);
4e1b3183abf33f3125247c8e28e30c788d2fa0abTimo Sirainenvoid sha256_loop(struct sha256_ctx *ctx, const void *data, size_t len);
7a7d97c082834dccdd89dbb95598977deec4d5a7Timo Sirainenvoid sha256_result(struct sha256_ctx *ctx,
9625595c47c665f5aee57ebfcb1fcbe9ad1bf3a0Martti Rannanjärvi unsigned char digest[STATIC_ARRAY SHA256_RESULTLEN]);
7a7d97c082834dccdd89dbb95598977deec4d5a7Timo Sirainen
7a7d97c082834dccdd89dbb95598977deec4d5a7Timo Sirainenvoid sha256_get_digest(const void *data, size_t size,
9625595c47c665f5aee57ebfcb1fcbe9ad1bf3a0Martti Rannanjärvi unsigned char digest[STATIC_ARRAY SHA256_RESULTLEN]);
7a7d97c082834dccdd89dbb95598977deec4d5a7Timo Sirainen
58d16e83e0953ac98f4bdc905f2f5d24b8f0002dTimo Sirainenvoid sha512_init(struct sha512_ctx *ctx);
58d16e83e0953ac98f4bdc905f2f5d24b8f0002dTimo Sirainenvoid sha512_loop(struct sha512_ctx *ctx, const void *data, size_t len);
58d16e83e0953ac98f4bdc905f2f5d24b8f0002dTimo Sirainenvoid sha512_result(struct sha512_ctx *ctx,
9625595c47c665f5aee57ebfcb1fcbe9ad1bf3a0Martti Rannanjärvi unsigned char digest[STATIC_ARRAY SHA512_RESULTLEN]);
58d16e83e0953ac98f4bdc905f2f5d24b8f0002dTimo Sirainen
58d16e83e0953ac98f4bdc905f2f5d24b8f0002dTimo Sirainenvoid sha512_get_digest(const void *data, size_t size,
9625595c47c665f5aee57ebfcb1fcbe9ad1bf3a0Martti Rannanjärvi unsigned char digest[STATIC_ARRAY SHA512_RESULTLEN]);
58d16e83e0953ac98f4bdc905f2f5d24b8f0002dTimo Sirainen
74ae32512357bdd4872bf160dc697ff7b54b54c5Timo Sirainenextern const struct hash_method hash_method_sha256;
74ae32512357bdd4872bf160dc697ff7b54b54c5Timo Sirainenextern const struct hash_method hash_method_sha512;
74ae32512357bdd4872bf160dc697ff7b54b54c5Timo Sirainen
7a7d97c082834dccdd89dbb95598977deec4d5a7Timo Sirainen#endif /* !SHA2_H */