1;;
2;; Copyright (c) 2012-2020, Intel Corporation
3;;
4;; Redistribution and use in source and binary forms, with or without
5;; modification, are permitted provided that the following conditions are met:
6;;
7;;     * Redistributions of source code must retain the above copyright notice,
8;;       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 the
11;;       documentation and/or other materials provided with the distribution.
12;;     * Neither the name of Intel Corporation nor the names of its contributors
13;;       may be used to endorse or promote products derived from this software
14;;       without specific prior written permission.
15;;
16;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17;; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18;; IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19;; DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
20;; FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21;; DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22;; SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23;; CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24;; OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25;; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26;;
27
28%include "include/datastruct.asm"
29
30;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
31;;;; Define constants
32;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
33
34%define STS_BEING_PROCESSED	0
35%define STS_COMPLETED_AES	1
36%define STS_COMPLETED_HMAC	2
37%define STS_COMPLETED		3
38%define STS_INVALID_ARGS	4
39
40;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
41;;;; Define IMB_JOB structure
42;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
43
44START_FIELDS	; HMAC Specific Fields
45;;;	name				size	align
46FIELD	__auth_key_xor_ipad,		8,	8	; pointer to ipad
47FIELD	__auth_key_xor_opad,		8,	8	; pointer to opad
48END_FIELDS
49
50%assign _HMAC_spec_fields_size	_FIELD_OFFSET
51%assign _HMAC_spec_fields_align	_STRUCT_ALIGN
52
53START_FIELDS	; AES XCBC Specific Fields
54;;;	name				size	align
55FIELD	__k1_expanded,			8,	8	; ptr to exp k1 keys
56FIELD	__k2,				8,	8	; ptr to k2
57FIELD	__k3,				8,	8	; ptr to k3
58END_FIELDS
59
60%assign _AES_XCBC_spec_fields_size	_FIELD_OFFSET
61%assign _AES_XCBC_spec_fields_align	_STRUCT_ALIGN
62
63START_FIELDS	; CBCMAC Specific Fields
64;;;	name				size	align
65FIELD	__aad,				8,	8	; pointer to AAD
66FIELD	__aad_len,			8,	8	; 64-bit AAD length
67END_FIELDS
68
69%assign _CBCMAC_spec_fields_size	_FIELD_OFFSET
70%assign _CBCMAC_spec_fields_align	_STRUCT_ALIGN
71
72START_FIELDS	; AES CMAC Specific Fields
73;;;	name				size	align
74FIELD	__key_expanded,			8,	8	; ptr to exp keys
75FIELD	__skey1,			8,	8	; ptr to subkey 1
76FIELD	__skey2,			8,	8	; ptr to subkey 2
77END_FIELDS
78
79%assign _AES_CMAC_spec_fields_size	_FIELD_OFFSET
80%assign _AES_CMAC_spec_fields_align	_STRUCT_ALIGN
81
82START_FIELDS	; GCM Specific Fields
83;;;	name	ggn			size	align
84FIELD	__gcm_aad,			8,	8	; pointer to AAD
85FIELD	__gcm_aad_len,			8,	8	; 64-bit AAD length
86END_FIELDS
87
88%assign _GCM_spec_fields_size	_FIELD_OFFSET
89%assign _GCM_spec_fields_align	_STRUCT_ALIGN
90
91START_FIELDS	; ZUC-EIA3 Specific Fields
92;;;	name				size	align
93FIELD	__zuc_eia3_key,			8,	8	; pointer to key
94FIELD	__zuc_eia3_iv,			8,	8	; pointer to IV
95END_FIELDS
96
97%assign _ZUC_EIA3_spec_fields_size	_FIELD_OFFSET
98%assign _ZUC_EIA3_spec_fields_align	_STRUCT_ALIGN
99
100START_FIELDS	; POLY1305 Specific Fields
101;;;	name				size	align
102FIELD	__poly1305_key,		 	8,	8	; ptr to 32 byte key
103END_FIELDS
104
105%assign _POLY1305_spec_fields_size	_FIELD_OFFSET
106%assign _POLY1305_spec_fields_align	_STRUCT_ALIGN
107
108START_FIELDS	; IMB_JOB
109;;;	name				size	align
110FIELD	_enc_keys,			8,	8	; pointer to enc keys
111FIELD	_dec_keys,			8,	8	; pointer to dec keys
112FIELD	_key_len_in_bytes,		8,	8
113FIELD	_src,				8,	8	; pointer to src buffer
114FIELD	_dst,				8,	8	; pointer to dst buffer
115FIELD	_cipher_start_src_offset_in_bytes, \
116					8,	8
117FIELD	_msg_len_to_cipher,	        8,	8
118FIELD	_hash_start_src_offset_in_bytes,8,	8
119FIELD	_msg_len_to_hash,	        8,	8
120FIELD	_iv,				8,	8	; pointer to IV
121FIELD	_iv_len_in_bytes,		8,	8
122FIELD	_auth_tag_output,		8,	8	; pointer to hash output
123FIELD	_auth_tag_output_len_in_bytes,	8,	8
124
125UNION	_u,	_HMAC_spec_fields_size,     _HMAC_spec_fields_align, \
126		_AES_XCBC_spec_fields_size, _AES_XCBC_spec_fields_align, \
127		_CBCMAC_spec_fields_size, _CBCMAC_spec_fields_align, \
128                _AES_CMAC_spec_fields_size, _AES_CMAC_spec_fields_align, \
129                _GCM_spec_fields_size, _GCM_spec_fields_align, \
130                _ZUC_EIA3_spec_fields_size, _ZUC_EIA3_spec_fields_align, \
131                _POLY1305_spec_fields_size, _POLY1305_spec_fields_align
132
133FIELD	_status,			4,	4	; JOB_STS
134FIELD	_cipher_mode,			4,	4	; JOB_CIPHER_MODE
135FIELD	_cipher_direction,		4,	4	; JOB_CIPHER_DIRECTION
136FIELD	_hash_alg,			4,	4	; JOB_HASH_ALG
137FIELD	_chain_order,			4,	4	; JOB_CHAIN_ORDER
138FIELD	_user_data,			8,	8
139FIELD	_user_data2,			8,	8
140END_FIELDS
141
142%assign _msg_len_to_cipher_in_bytes _msg_len_to_cipher
143%assign _msg_len_to_cipher_in_bits  _msg_len_to_cipher
144%assign _msg_len_to_hash_in_bytes   _msg_len_to_hash
145%assign _msg_len_to_hash_in_bits    _msg_len_to_hash
146
147%assign _IMB_JOB_size	_FIELD_OFFSET
148%assign _IMB_JOB_align	_STRUCT_ALIGN
149
150%assign _auth_key_xor_ipad              _u + __auth_key_xor_ipad
151%assign _auth_key_xor_opad	        _u + __auth_key_xor_opad
152%assign _k1_expanded		        _u + __k1_expanded
153%assign _k2			        _u + __k2
154%assign _k3			        _u + __k3
155%assign _cbcmac_aad	                _u + __aad
156%assign _cbcmac_aad_len	                _u + __aad_len
157%assign _key_expanded		        _u + __key_expanded
158%assign _skey1			        _u + __skey1
159%assign _skey2			        _u + __skey2
160%assign _gcm_aad	                _u + __gcm_aad
161%assign _gcm_aad_len	                _u + __gcm_aad_len
162%assign _zuc_eia3_key                   _u + __zuc_eia3_key
163%assign _zuc_eia3_iv                    _u + __zuc_eia3_iv
164%assign _poly1305_key	                _u + __poly1305_key
165