MCPcopy Create free account
hub / github.com/F-Stack/f-stack / ktls_ocf_tls_cbc_encrypt

Function ktls_ocf_tls_cbc_encrypt

freebsd/opencrypto/ktls_ocf.c:157–315  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

155}
156
157static int
158ktls_ocf_tls_cbc_encrypt(struct ktls_session *tls,
159 const struct tls_record_layer *hdr, uint8_t *trailer, struct iovec *iniov,
160 struct iovec *outiov, int iovcnt, uint64_t seqno,
161 uint8_t record_type __unused)
162{
163 struct uio uio, out_uio;
164 struct tls_mac_data ad;
165 struct cryptop crp;
166 struct ocf_session *os;
167 struct iovec iov[iovcnt + 2];
168 struct iovec out_iov[iovcnt + 1];
169 int i, error;
170 uint16_t tls_comp_len;
171 uint8_t pad;
172 bool inplace;
173
174 os = tls->cipher;
175
176#ifdef INVARIANTS
177 if (os->implicit_iv) {
178 mtx_lock(&os->lock);
179 KASSERT(!os->in_progress,
180 ("concurrent implicit IV encryptions"));
181 if (os->next_seqno != seqno) {
182 printf("KTLS CBC: TLS records out of order. "
183 "Expected %ju, got %ju\n",
184 (uintmax_t)os->next_seqno, (uintmax_t)seqno);
185 mtx_unlock(&os->lock);
186 return (EINVAL);
187 }
188 os->in_progress = true;
189 mtx_unlock(&os->lock);
190 }
191#endif
192
193 /*
194 * Compute the payload length.
195 *
196 * XXX: This could be easily computed O(1) from the mbuf
197 * fields, but we don't have those accessible here. Can
198 * at least compute inplace as well while we are here.
199 */
200 tls_comp_len = 0;
201 inplace = true;
202 for (i = 0; i < iovcnt; i++) {
203 tls_comp_len += iniov[i].iov_len;
204 if (iniov[i].iov_base != outiov[i].iov_base)
205 inplace = false;
206 }
207
208 /* Initialize the AAD. */
209 ad.seq = htobe64(seqno);
210 ad.type = hdr->tls_type;
211 ad.tls_vmajor = hdr->tls_vmajor;
212 ad.tls_vminor = hdr->tls_vminor;
213 ad.tls_length = htons(tls_comp_len);
214

Callers

nothing calls this directly

Calls 10

crypto_initreqFunction · 0.85
crypto_use_uioFunction · 0.85
ktls_ocf_dispatchFunction · 0.85
crypto_destroyreqFunction · 0.85
crypto_use_output_uioFunction · 0.85
mtx_lockFunction · 0.50
printfFunction · 0.50
mtx_unlockFunction · 0.50
memcpyFunction · 0.50
counter_u64_addFunction · 0.50

Tested by

no test coverage detected