xref: /isa-l_crypto/include/multi_buffer.h (revision e3f7d4fb1bd3dcbfb75b87e0c61870e751d613aa)
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 #include "endian_helper.h"
44 
45 /**
46  *  @enum JOB_STS
47  *  @brief Job return codes
48  */
49 
50 typedef enum {STS_UNKNOWN = 0,	//!< STS_UNKNOWN
51 	STS_BEING_PROCESSED = 1,//!< STS_BEING_PROCESSED
52 	STS_COMPLETED = 2,	//!< STS_COMPLETED
53 	STS_INTERNAL_ERROR,	//!< STS_INTERNAL_ERROR
54 	STS_ERROR		//!< STS_ERROR
55 } JOB_STS;
56 
57 #define HASH_MB_NO_FLAGS 0
58 #define HASH_MB_FIRST	1
59 #define HASH_MB_LAST	2
60 
61 /* Common flags for the new API only
62  *  */
63 
64 /**
65  *  @enum HASH_CTX_FLAG
66  *  @brief CTX job type
67  */
68 typedef enum {
69 	HASH_UPDATE	= 0x00, //!< HASH_UPDATE
70 	HASH_FIRST	= 0x01, //!< HASH_FIRST
71 	HASH_LAST	= 0x02, //!< HASH_LAST
72 	HASH_ENTIRE	= 0x03, //!< HASH_ENTIRE
73 } HASH_CTX_FLAG;
74 
75 /**
76  *  @enum HASH_CTX_STS
77  *  @brief CTX status flags
78  */
79 typedef enum {
80 	HASH_CTX_STS_IDLE	= 0x00, //!< HASH_CTX_STS_IDLE
81 	HASH_CTX_STS_PROCESSING	= 0x01, //!< HASH_CTX_STS_PROCESSING
82 	HASH_CTX_STS_LAST	= 0x02, //!< HASH_CTX_STS_LAST
83 	HASH_CTX_STS_COMPLETE	= 0x04, //!< HASH_CTX_STS_COMPLETE
84 } HASH_CTX_STS;
85 
86 /**
87  *  @enum HASH_CTX_ERROR
88  *  @brief CTX error flags
89  */
90 typedef enum {
91 	HASH_CTX_ERROR_NONE			=  0, //!< HASH_CTX_ERROR_NONE
92 	HASH_CTX_ERROR_INVALID_FLAGS		= -1, //!< HASH_CTX_ERROR_INVALID_FLAGS
93 	HASH_CTX_ERROR_ALREADY_PROCESSING	= -2, //!< HASH_CTX_ERROR_ALREADY_PROCESSING
94 	HASH_CTX_ERROR_ALREADY_COMPLETED	= -3, //!< HASH_CTX_ERROR_ALREADY_COMPLETED
95 } HASH_CTX_ERROR;
96 
97 
98 #define hash_ctx_user_data(ctx)  ((ctx)->user_data)
99 #define hash_ctx_digest(ctx)     ((ctx)->job.result_digest)
100 #define hash_ctx_processing(ctx) ((ctx)->status & HASH_CTX_STS_PROCESSING)
101 #define hash_ctx_complete(ctx)   ((ctx)->status == HASH_CTX_STS_COMPLETE)
102 #define hash_ctx_status(ctx)     ((ctx)->status)
103 #define hash_ctx_error(ctx)      ((ctx)->error)
104 #define hash_ctx_init(ctx) \
105 	do { \
106 		(ctx)->error = HASH_CTX_ERROR_NONE; \
107 		(ctx)->status = HASH_CTX_STS_COMPLETE; \
108 	} while(0)
109 
110 #ifdef __cplusplus
111 }
112 #endif
113 
114 #endif // _MULTI_BUFFER_H_
115