| /* |
| * Cryptographic API. |
| * |
| * SHA-256, as specified in |
| * http://csrc.nist.gov/groups/STM/cavp/documents/shs/sha256-384-512.pdf |
| * |
| * SHA-256 code by Jean-Luc Cooke <jlcooke@certainkey.com>. |
| * |
| * Copyright (c) Jean-Luc Cooke <jlcooke@certainkey.com> |
| * Copyright (c) Andrew McDonald <andrew@mcdonald.org.uk> |
| * Copyright (c) 2002 James Morris <jmorris@intercode.com.au> |
| * SHA224 Support Copyright 2007 Intel Corporation <jonathan.lynch@intel.com> |
| * |
| * This program is free software; you can redistribute it and/or modify it |
| * under the terms of the GNU General Public License as published by the Free |
| * Software Foundation; either version 2 of the License, or (at your option) |
| * any later version. |
| * |
| */ |
| |
| #ifndef SHA256_FMP_H |
| #define SHA256_FMP_H |
| |
| #include <linux/types.h> |
| |
| #define SHA256_DIGEST_SIZE 32 |
| #define SHA256_BLOCK_SIZE 64 |
| #define SHA256_DIGEST_LENGTH SHA256_DIGEST_SIZE |
| |
| struct sha256_state { |
| u32 state[SHA256_DIGEST_SIZE / 4]; |
| u64 count; |
| u8 buf[SHA256_BLOCK_SIZE]; |
| }; |
| |
| struct fmp_shash_desc { |
| struct sha256_state __ctx; |
| }; |
| |
| typedef struct fmp_shash_desc SHA256_CTX; |
| |
| typedef void (sha256_block_fn)(struct sha256_state *sst, u8 const *src, |
| int blocks); |
| |
| /* Initialises desc |
| * Returns 0 at success, nonzero otherwise |
| */ |
| int fmp_sha256_init(struct fmp_shash_desc *desc); |
| |
| /* Adds len bytes from data to desc. |
| * Returns 0 at success, nonzero otherwise |
| */ |
| int fmp_sha256_update(struct fmp_shash_desc *desc, const u8 *data, |
| unsigned int len); |
| |
| /* Adds the final padding to desc and writes the resulting digest |
| * to out, which must have at least SHA256_DIGEST_SIZE bytes of space. |
| * Returns 0 at success, nonzero otherwise |
| */ |
| int fmp_sha256_final(struct fmp_shash_desc *desc, u8 *out); |
| |
| /* Writes the digest of len bytes from data to out. Returns out. |
| * Out should be preallocated at least SHA256_DIGEST_SIZE length. |
| * Returns 0 at success, nonzero otherwise |
| */ |
| int fmp_sha256(const u8 *data, unsigned int len, u8 *out); |
| |
| /* desc dup |
| * Returns 0 at success, nonzero otherwise |
| */ |
| int fmp_sha256_desc_copy(struct fmp_shash_desc *dst, const struct fmp_shash_desc *src); |
| |
| #endif /* SHA256_FMP_H */ |