summaryrefstree
path: root/kernel/drivers/crypto/fmp/sha256.h
blob: f4e21848cc25ba2b2c1fb66f911ba1f9d6f7ff4a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*
 * 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 shash_desc {
	struct sha256_state __ctx;
};

typedef struct 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 sha256_init(struct shash_desc *desc);

/* Adds len bytes from data to desc.
 * Returns 0 at success, nonzero otherwise
 * */
int sha256_update(struct 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 sha256_final(struct 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 sha256(const u8 *data, unsigned int len, u8 *out);

/* desc dup
 * Returns 0 at success, nonzero otherwise
 *  */
int sha256_desc_copy(struct shash_desc *dst, const struct shash_desc *src);

#endif  /* SHA256_FMP_H */