Deleted Added
full compact
padlock_cipher.c (162316) padlock_cipher.c (208834)
1/*-
2 * Copyright (c) 2005-2006 Pawel Jakub Dawidek <pjd@FreeBSD.org>
3 * Copyright (c) 2004 Mark R V Murray
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:

--- 31 unchanged lines hidden (view full) ---

40 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
41 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
42 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
43 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
44 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
45 */
46
47#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 2005-2006 Pawel Jakub Dawidek <pjd@FreeBSD.org>
3 * Copyright (c) 2004 Mark R V Murray
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:

--- 31 unchanged lines hidden (view full) ---

40 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
41 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
42 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
43 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
44 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
45 */
46
47#include <sys/cdefs.h>
48__FBSDID("$FreeBSD: head/sys/crypto/via/padlock_cipher.c 162316 2006-09-15 10:44:55Z pjd $");
48__FBSDID("$FreeBSD: head/sys/crypto/via/padlock_cipher.c 208834 2010-06-05 16:00:53Z kib $");
49
50#include <sys/param.h>
51#include <sys/systm.h>
52#include <sys/kernel.h>
53#include <sys/module.h>
54#include <sys/malloc.h>
55#include <sys/libkern.h>
49
50#include <sys/param.h>
51#include <sys/systm.h>
52#include <sys/kernel.h>
53#include <sys/module.h>
54#include <sys/malloc.h>
55#include <sys/libkern.h>
56#include <sys/pcpu.h>
56#include <sys/uio.h>
57
58#include <opencrypto/cryptodev.h>
59#include <crypto/rijndael/rijndael.h>
60
61#include <crypto/via/padlock.h>
62
63#define PADLOCK_ROUND_COUNT_AES128 10

--- 132 unchanged lines hidden (view full) ---

196 return (addr);
197}
198
199int
200padlock_cipher_process(struct padlock_session *ses, struct cryptodesc *enccrd,
201 struct cryptop *crp)
202{
203 union padlock_cw *cw;
57#include <sys/uio.h>
58
59#include <opencrypto/cryptodev.h>
60#include <crypto/rijndael/rijndael.h>
61
62#include <crypto/via/padlock.h>
63
64#define PADLOCK_ROUND_COUNT_AES128 10

--- 132 unchanged lines hidden (view full) ---

197 return (addr);
198}
199
200int
201padlock_cipher_process(struct padlock_session *ses, struct cryptodesc *enccrd,
202 struct cryptop *crp)
203{
204 union padlock_cw *cw;
205 struct thread *td;
204 u_char *buf, *abuf;
205 uint32_t *key;
206 u_char *buf, *abuf;
207 uint32_t *key;
206 int allocated;
208 int allocated, error;
207
208 buf = padlock_cipher_alloc(enccrd, crp, &allocated);
209 if (buf == NULL)
210 return (ENOMEM);
211 /* Buffer has to be 16 bytes aligned. */
212 abuf = PADLOCK_ALIGN(buf);
213
214 if ((enccrd->crd_flags & CRD_F_KEY_EXPLICIT) != 0) {

--- 27 unchanged lines hidden (view full) ---

242 }
243 }
244
245 if (allocated) {
246 crypto_copydata(crp->crp_flags, crp->crp_buf, enccrd->crd_skip,
247 enccrd->crd_len, abuf);
248 }
249
209
210 buf = padlock_cipher_alloc(enccrd, crp, &allocated);
211 if (buf == NULL)
212 return (ENOMEM);
213 /* Buffer has to be 16 bytes aligned. */
214 abuf = PADLOCK_ALIGN(buf);
215
216 if ((enccrd->crd_flags & CRD_F_KEY_EXPLICIT) != 0) {

--- 27 unchanged lines hidden (view full) ---

244 }
245 }
246
247 if (allocated) {
248 crypto_copydata(crp->crp_flags, crp->crp_buf, enccrd->crd_skip,
249 enccrd->crd_len, abuf);
250 }
251
252 td = curthread;
253 error = fpu_kern_enter(td, &ses->ses_fpu_ctx, FPU_KERN_NORMAL);
254 if (error != 0)
255 goto out;
256
250 padlock_cbc(abuf, abuf, enccrd->crd_len / AES_BLOCK_LEN, key, cw,
251 ses->ses_iv);
252
257 padlock_cbc(abuf, abuf, enccrd->crd_len / AES_BLOCK_LEN, key, cw,
258 ses->ses_iv);
259
260 fpu_kern_leave(td, &ses->ses_fpu_ctx);
261
253 if (allocated) {
254 crypto_copyback(crp->crp_flags, crp->crp_buf, enccrd->crd_skip,
255 enccrd->crd_len, abuf);
256 }
257
258 /* copy out last block for use as next session IV */
259 if ((enccrd->crd_flags & CRD_F_ENCRYPT) != 0) {
260 crypto_copydata(crp->crp_flags, crp->crp_buf,
261 enccrd->crd_skip + enccrd->crd_len - AES_BLOCK_LEN,
262 AES_BLOCK_LEN, ses->ses_iv);
263 }
264
262 if (allocated) {
263 crypto_copyback(crp->crp_flags, crp->crp_buf, enccrd->crd_skip,
264 enccrd->crd_len, abuf);
265 }
266
267 /* copy out last block for use as next session IV */
268 if ((enccrd->crd_flags & CRD_F_ENCRYPT) != 0) {
269 crypto_copydata(crp->crp_flags, crp->crp_buf,
270 enccrd->crd_skip + enccrd->crd_len - AES_BLOCK_LEN,
271 AES_BLOCK_LEN, ses->ses_iv);
272 }
273
274 out:
265 if (allocated) {
266 bzero(buf, enccrd->crd_len + 16);
267 free(buf, M_PADLOCK);
268 }
275 if (allocated) {
276 bzero(buf, enccrd->crd_len + 16);
277 free(buf, M_PADLOCK);
278 }
269 return (0);
279 return (error);
270}
280}