xref: /isa-l_crypto/include/multi_buffer.h (revision f1e544df07577282ca9849bef22d6c84264feb7d)
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 {
49         STS_UNKNOWN = 0,         //!< STS_UNKNOWN
50         STS_BEING_PROCESSED = 1, //!< STS_BEING_PROCESSED
51         STS_COMPLETED = 2,       //!< STS_COMPLETED
52         STS_INTERNAL_ERROR,      //!< STS_INTERNAL_ERROR
53         STS_ERROR                //!< STS_ERROR
54 } JOB_STS;
55 
56 #define HASH_MB_NO_FLAGS 0
57 #define HASH_MB_FIRST    1
58 #define HASH_MB_LAST     2
59 
60 /* Common flags for the new API only
61  *  */
62 
63 /**
64  *  @enum HASH_CTX_FLAG
65  *  @brief CTX job type
66  */
67 typedef enum {
68         HASH_UPDATE = 0x00, //!< HASH_UPDATE
69         HASH_FIRST = 0x01,  //!< HASH_FIRST
70         HASH_LAST = 0x02,   //!< HASH_LAST
71         HASH_ENTIRE = 0x03, //!< HASH_ENTIRE
72 } HASH_CTX_FLAG;
73 
74 /**
75  *  @enum HASH_CTX_STS
76  *  @brief CTX status flags
77  */
78 typedef enum {
79         HASH_CTX_STS_IDLE = 0x00,       //!< HASH_CTX_STS_IDLE
80         HASH_CTX_STS_PROCESSING = 0x01, //!< HASH_CTX_STS_PROCESSING
81         HASH_CTX_STS_LAST = 0x02,       //!< HASH_CTX_STS_LAST
82         HASH_CTX_STS_COMPLETE = 0x04,   //!< HASH_CTX_STS_COMPLETE
83 } HASH_CTX_STS;
84 
85 /**
86  *  @enum HASH_CTX_ERROR
87  *  @brief CTX error flags
88  */
89 typedef enum {
90         HASH_CTX_ERROR_NONE = 0,                //!< HASH_CTX_ERROR_NONE
91         HASH_CTX_ERROR_INVALID_FLAGS = -1,      //!< HASH_CTX_ERROR_INVALID_FLAGS
92         HASH_CTX_ERROR_ALREADY_PROCESSING = -2, //!< HASH_CTX_ERROR_ALREADY_PROCESSING
93         HASH_CTX_ERROR_ALREADY_COMPLETED = -3,  //!< HASH_CTX_ERROR_ALREADY_COMPLETED
94 } HASH_CTX_ERROR;
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