Merge tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost
[cris-mirror.git] / arch / x86 / crypto / sha256-mb / sha256_mb_ctx.h
blobaabb30320af0dd4c11263bdfd8ce490d8ee726fa
1 /*
2 * Header file for multi buffer SHA256 context
4 * This file is provided under a dual BSD/GPLv2 license. When using or
5 * redistributing this file, you may do so under either license.
7 * GPL LICENSE SUMMARY
9 * Copyright(c) 2016 Intel Corporation.
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of version 2 of the GNU General Public License as
13 * published by the Free Software Foundation.
15 * This program is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
20 * Contact Information:
21 * Megha Dey <megha.dey@linux.intel.com>
23 * BSD LICENSE
25 * Copyright(c) 2016 Intel Corporation.
27 * Redistribution and use in source and binary forms, with or without
28 * modification, are permitted provided that the following conditions
29 * are met:
31 * * Redistributions of source code must retain the above copyright
32 * notice, this list of conditions and the following disclaimer.
33 * * Redistributions in binary form must reproduce the above copyright
34 * notice, this list of conditions and the following disclaimer in
35 * the documentation and/or other materials provided with the
36 * distribution.
37 * * Neither the name of Intel Corporation nor the names of its
38 * contributors may be used to endorse or promote products derived
39 * from this software without specific prior written permission.
41 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
42 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
43 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
44 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
45 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
46 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
47 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
48 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
49 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
50 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
51 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
54 #ifndef _SHA_MB_CTX_INTERNAL_H
55 #define _SHA_MB_CTX_INTERNAL_H
57 #include "sha256_mb_mgr.h"
59 #define HASH_UPDATE 0x00
60 #define HASH_FIRST 0x01
61 #define HASH_LAST 0x02
62 #define HASH_ENTIRE 0x03
63 #define HASH_DONE 0x04
64 #define HASH_FINAL 0x08
66 #define HASH_CTX_STS_IDLE 0x00
67 #define HASH_CTX_STS_PROCESSING 0x01
68 #define HASH_CTX_STS_LAST 0x02
69 #define HASH_CTX_STS_COMPLETE 0x04
71 enum hash_ctx_error {
72 HASH_CTX_ERROR_NONE = 0,
73 HASH_CTX_ERROR_INVALID_FLAGS = -1,
74 HASH_CTX_ERROR_ALREADY_PROCESSING = -2,
75 HASH_CTX_ERROR_ALREADY_COMPLETED = -3,
77 #ifdef HASH_CTX_DEBUG
78 HASH_CTX_ERROR_DEBUG_DIGEST_MISMATCH = -4,
79 #endif
83 #define hash_ctx_user_data(ctx) ((ctx)->user_data)
84 #define hash_ctx_digest(ctx) ((ctx)->job.result_digest)
85 #define hash_ctx_processing(ctx) ((ctx)->status & HASH_CTX_STS_PROCESSING)
86 #define hash_ctx_complete(ctx) ((ctx)->status == HASH_CTX_STS_COMPLETE)
87 #define hash_ctx_status(ctx) ((ctx)->status)
88 #define hash_ctx_error(ctx) ((ctx)->error)
89 #define hash_ctx_init(ctx) \
90 do { \
91 (ctx)->error = HASH_CTX_ERROR_NONE; \
92 (ctx)->status = HASH_CTX_STS_COMPLETE; \
93 } while (0)
96 /* Hash Constants and Typedefs */
97 #define SHA256_DIGEST_LENGTH 8
98 #define SHA256_LOG2_BLOCK_SIZE 6
100 #define SHA256_PADLENGTHFIELD_SIZE 8
102 #ifdef SHA_MB_DEBUG
103 #define assert(expr) \
104 do { \
105 if (unlikely(!(expr))) { \
106 printk(KERN_ERR "Assertion failed! %s,%s,%s,line=%d\n", \
107 #expr, __FILE__, __func__, __LINE__); \
109 } while (0)
110 #else
111 #define assert(expr) do {} while (0)
112 #endif
114 struct sha256_ctx_mgr {
115 struct sha256_mb_mgr mgr;
118 /* typedef struct sha256_ctx_mgr sha256_ctx_mgr; */
120 struct sha256_hash_ctx {
121 /* Must be at struct offset 0 */
122 struct job_sha256 job;
123 /* status flag */
124 int status;
125 /* error flag */
126 int error;
128 uint64_t total_length;
129 const void *incoming_buffer;
130 uint32_t incoming_buffer_length;
131 uint8_t partial_block_buffer[SHA256_BLOCK_SIZE * 2];
132 uint32_t partial_block_buffer_length;
133 void *user_data;
136 #endif