xref: /isa-l_crypto/include/multi_buffer.h (revision a7753fe3f5e15d45f9d62d8d197b068929dd5f7a)
1 /**********************************************************************
2   Copyright(c) 2011-2016 Intel Corporation All rights reserved.
3 
4   Redistribution and use in source and binary forms, with or without
5   modification, are permitted provided that the following conditions
6   are met:
7     * Redistributions of source code must retain the above copyright
8       notice, this list of conditions and the following disclaimer.
9     * Redistributions in binary form must reproduce the above copyright
10       notice, this list of conditions and the following disclaimer in
11       the documentation and/or other materials provided with the
12       distribution.
13     * Neither the name of Intel Corporation nor the names of its
14       contributors may be used to endorse or promote products derived
15       from this software without specific prior written permission.
16 
17   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 **********************************************************************/
29 
30 #ifndef _MULTI_BUFFER_H_
31 #define _MULTI_BUFFER_H_
32 
33 /**
34  *  @file  multi_buffer.h
35  *  @brief Multi-buffer common fields
36  *
37  */
38 
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
42 
43 /**
44  *  @enum JOB_STS
45  *  @brief Job return codes
46  */
47 
48 typedef enum {STS_UNKNOWN = 0,	//!< STS_UNKNOWN
49 	STS_BEING_PROCESSED = 1,//!< STS_BEING_PROCESSED
50 	STS_COMPLETED = 2,	//!< STS_COMPLETED
51 	STS_INTERNAL_ERROR,	//!< STS_INTERNAL_ERROR
52 	STS_ERROR		//!< STS_ERROR
53 } JOB_STS;
54 
55 #define HASH_MB_NO_FLAGS 0
56 #define HASH_MB_FIRST	1
57 #define HASH_MB_LAST	2
58 
59 /* Common flags for the new API only
60  *  */
61 
62 /**
63  *  @enum HASH_CTX_FLAG
64  *  @brief CTX job type
65  */
66 typedef enum {
67 	HASH_UPDATE	= 0x00, //!< HASH_UPDATE
68 	HASH_FIRST	= 0x01, //!< HASH_FIRST
69 	HASH_LAST	= 0x02, //!< HASH_LAST
70 	HASH_ENTIRE	= 0x03, //!< HASH_ENTIRE
71 } HASH_CTX_FLAG;
72 
73 /**
74  *  @enum HASH_CTX_STS
75  *  @brief CTX status flags
76  */
77 typedef enum {
78 	HASH_CTX_STS_IDLE	= 0x00, //!< HASH_CTX_STS_IDLE
79 	HASH_CTX_STS_PROCESSING	= 0x01, //!< HASH_CTX_STS_PROCESSING
80 	HASH_CTX_STS_LAST	= 0x02, //!< HASH_CTX_STS_LAST
81 	HASH_CTX_STS_COMPLETE	= 0x04, //!< HASH_CTX_STS_COMPLETE
82 } HASH_CTX_STS;
83 
84 /**
85  *  @enum HASH_CTX_ERROR
86  *  @brief CTX error flags
87  */
88 typedef enum {
89 	HASH_CTX_ERROR_NONE			=  0, //!< HASH_CTX_ERROR_NONE
90 	HASH_CTX_ERROR_INVALID_FLAGS		= -1, //!< HASH_CTX_ERROR_INVALID_FLAGS
91 	HASH_CTX_ERROR_ALREADY_PROCESSING	= -2, //!< HASH_CTX_ERROR_ALREADY_PROCESSING
92 	HASH_CTX_ERROR_ALREADY_COMPLETED	= -3, //!< HASH_CTX_ERROR_ALREADY_COMPLETED
93 } HASH_CTX_ERROR;
94 
95 
96 #define hash_ctx_user_data(ctx)  ((ctx)->user_data)
97 #define hash_ctx_digest(ctx)     ((ctx)->job.result_digest)
98 #define hash_ctx_processing(ctx) ((ctx)->status & HASH_CTX_STS_PROCESSING)
99 #define hash_ctx_complete(ctx)   ((ctx)->status == HASH_CTX_STS_COMPLETE)
100 #define hash_ctx_status(ctx)     ((ctx)->status)
101 #define hash_ctx_error(ctx)      ((ctx)->error)
102 #define hash_ctx_init(ctx) \
103 	do { \
104 		(ctx)->error = HASH_CTX_ERROR_NONE; \
105 		(ctx)->status = HASH_CTX_STS_COMPLETE; \
106 	} while(0)
107 
108 #ifdef __cplusplus
109 }
110 #endif
111 
112 #endif // _MULTI_BUFFER_H_
113